1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/UI/Scripts/UIEffect/ButtonText.cs

43 lines
1.0 KiB
C#

using Cysharp.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.UI;
public class ButtonText : MonoBehaviour
{
[SerializeField]
private Button _btn;
[SerializeField]
private TextMeshProUGUI _text;
public Color pressedColor;
private void Reset()
{
this._btn = this.GetComponent<Button>();
this._text = this.GetComponentInChildren<TextMeshProUGUI>(true);
}
private void Start()
{
var token = this.GetCancellationTokenOnDestroy();
this._btn
.OnPointerDownAsObservable()
.Subscribe(async _ => {
var old = this._text.color;
this._text.color = pressedColor;
await UniTask.WaitUntil(() => Input.GetMouseButtonUp(0) == true || Input.GetMouseButtonUp(1) == true, cancellationToken: token).SuppressCancellationThrow();
this._text.color = old;
})
.AddTo(this);
}
}