네, 알겠습니다. UniRx를 사용하지 않고, NuGet for Unity를 통해 설치한 ReactiveProperty.NET과 System.Reactive를 활용하여 attackSpeed에 맞춰 콤보 공격을 하는 코드를 다시 만들어 드리겠습니다.
핵심 변경 사항:
Observable.EveryUpdate() 대신, 일반적인 MonoBehaviour의 Update() 메서드 내에서 입력을 감지하고, ReactiveProperty와 System.Reactive의 Observable.Timer 등을 활용하여 콤보 로직을 구성합니다.
- UI 업데이트나
Observable 스트림의 결과를 메인 스레드에서 처리하기 위해 이전 답변에서 사용했던 UnityMainThreadScheduler가 필요합니다.
1. 필요 NuGet 패키지 설치
이전에 안내드린 것처럼 NuGet for Unity를 통해 다음 패키지들이 설치되어 있는지 확인해주세요:
ReactiveProperty
System.Reactive
System.Reactive.Linq
System.Reactive.Core
2. UnityMainThreadScheduler.cs 준비
이전 답변에서 제공된 UnityMainThreadScheduler.cs 스크립트가 프로젝트에 포함되어 있고, 씬의 특정 GameObject (예: ReactiveXScheduler)에 추가되어 있어야 합니다. 이 스크립트는 Observable.Timer와 같은 비동기 작업의 결과를 Unity 메인 스레드에서 안전하게 처리하도록 돕습니다.
// UnityMainThreadScheduler.cs (이전 답변 내용과 동일)
using UnityEngine;
using System;
using System.Collections.Concurrent;
using System.Reactive.Concurrency;
using System.Threading;
public class UnityMainThreadScheduler : MonoBehaviour
{
public static IScheduler MainThreadScheduler { get; private set; }
private static ConcurrentQueue<Action> _actionQueue = new ConcurrentQueue<Action>();
private static bool _isInitialized = false;
private void Awake()
{
if (_isInitialized)
{
Destroy(gameObject);
return;
}
_isInitialized = true;
DontDestroyOnLoad(gameObject);
MainThreadScheduler = new CustomUnityScheduler();
}
private void Update()
{
while (_actionQueue.TryDequeue(out Action action))
{
try
{
action?.Invoke();
}
catch (Exception ex)
{
Debug.LogError($"UnityMainThreadScheduler: Error executing action: {ex}");
}
}
}
private class CustomUnityScheduler : IScheduler
{
public DateTimeOffset Now => DateTimeOffset.Now;
public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
{
_actionQueue.Enqueue(() => action(this, state));
return System.Reactive.Disposables.Disposable.Empty;
}
public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
{
_actionQueue.Enqueue(() => action(this, state));
return System.Reactive.Disposables.Disposable.Empty;
}
public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
{
_actionQueue.Enqueue(() => action(this, state));
return System.Reactive.Disposables.Disposable.Empty;
}
}
}