UniRx 를 사용한 2D 캐릭터 이동
void Start()
{
this.UpdateAsObservable()
.Select(_ => new Vector2(Input.GetAxis("Horizontal"), 0))
.Subscribe(x => Move(x));
this.UpdateAsObservable()
.Where(_ => curJumpCount > 0 && Input.GetKeyDown(KeyCode.W))
.Subscribe(x => Jump());
this.UpdateAsObservable()
.Where(_ => !isDashed && Input.GetKeyDown(KeyCode.A))
.Buffer(System.TimeSpan.FromMilliseconds(250))
.Where(_ => _.Count >= 2)
.Subscribe(_ => Dash(-1);
this.UpdateAsObservable()
.Where(_ => !isDashed && Input.GetKeyDown(KeyCode.D))
.Buffer(System.TimeSpan.FromMilliseconds(250))
.Where(_ => _.Count >= 2)
.Subscribe(_ => Dash(1);
}
좋았던 점
- 구현이 쉬움
- Update 문을 돌지 않기 때문에 성능상 이점이 있음
- 멤버 변수를 적게 사용하여 함수 간 의존성이 낮음
아쉬운 점
- 대쉬에서 0.25초가 반드시 지나야 수행하는 듯 함
1-1. 위 문제로 입력 감지가 느린 느낌이 있음
- UniRx 활용법이 미숙함