77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Code.Infrastructure.UI;
|
|
using Cysharp.Threading.Tasks;
|
|
using LitMotion;
|
|
using LitMotion.Extensions;
|
|
using R3;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Actions.UI
|
|
{
|
|
public class WaitActionCountSelectorPanel : UIPanel
|
|
{
|
|
[SerializeField] private float duration;
|
|
|
|
[SerializeField] private Slider countSlider;
|
|
[SerializeField] private TMP_Text countText;
|
|
|
|
public Slider CountSlider => countSlider;
|
|
|
|
private MotionHandle _motionHandle;
|
|
|
|
private IDisposable _sliderCounter;
|
|
|
|
public void SetRange(int min, int max)
|
|
{
|
|
countSlider.minValue = min;
|
|
countSlider.maxValue = max;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
countSlider.wholeNumbers = true;
|
|
|
|
_sliderCounter = countSlider.OnValueChangedAsObservable()
|
|
.Subscribe(value =>
|
|
{
|
|
countText.SetText(value.ToString());
|
|
});
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_sliderCounter.Dispose();
|
|
}
|
|
|
|
public override async UniTask Open(CancellationToken cts = default)
|
|
{
|
|
gameObject.SetActive(true);
|
|
|
|
float startY = -((RectTransform)transform).rect.height;
|
|
|
|
_motionHandle = LMotion.Create(startY, 0f, duration)
|
|
.WithEase(Ease.OutCubic)
|
|
.WithScheduler(MotionScheduler.UpdateIgnoreTimeScale)
|
|
.BindToAnchoredPositionY((RectTransform)transform);
|
|
|
|
await _motionHandle.ToUniTask(cts);
|
|
}
|
|
|
|
public override async UniTask Close(CancellationToken cts = default)
|
|
{
|
|
float targetY = ((RectTransform)transform).rect.height;
|
|
|
|
_motionHandle = LMotion.Create(0f, targetY, duration)
|
|
.WithEase(Ease.InBack)
|
|
.WithScheduler(MotionScheduler.UpdateIgnoreTimeScale)
|
|
.BindToAnchoredPositionY((RectTransform)transform);
|
|
|
|
await _motionHandle.ToUniTask(cts);
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
} |