1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/UI/Scripts/Other/IndexController.cs

43 lines
958 B
C#

using Cysharp.Threading.Tasks;
using System.Threading;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class IndexController : BaseBehaviour
{
[SerializeField]
private Button[] btns;
private void Reset()
{
this.btns = this.GetComponentsInChildren<Button>(true);
}
public void Bind(AsyncReactiveProperty<int> index, int min, int max, CancellationToken cancellationToken)
{
this.btns[0]
.OnClickAsObservable()
.Where(_ => index.Value > min)
.Subscribe(_ => {
index.Value--;
})
.AddTo(cancellationToken);
this.btns[1]
.OnClickAsObservable()
.Where(_ => index.Value < max)
.Subscribe(_ => {
index.Value++;
})
.AddTo(cancellationToken);
}
public void SetActive(int index, bool value)
{
this.btns[index].gameObject.SetActive(value);
}
}