forked from zxl/LaboratoryProtection
99 lines
2.9 KiB
C#
99 lines
2.9 KiB
C#
using Cysharp.Threading.Tasks;
|
|
|
|
using DG.Tweening;
|
|
|
|
using PMaker.Await;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using System;
|
|
using System.Threading;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UINext : AwaitBehaviour
|
|
{
|
|
public float timeSpanSecond = 2;
|
|
public float duration = 1.5f;
|
|
[SerializeField]
|
|
private Button _nextBtn;
|
|
|
|
[SerializeField]
|
|
private string _tipString;
|
|
|
|
private void Reset()
|
|
{
|
|
_nextBtn = this.GetComponentInChildren<Button>(true);
|
|
_tipString = _nextBtn.GetComponentInChildren<TextMeshProUGUI>().text;
|
|
}
|
|
|
|
public override async UniTask WaitAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
_nextBtn.gameObject.SetActive(false);
|
|
this.gameObject.SetActive(true);
|
|
|
|
await UniTask.Delay(TimeSpan.FromSeconds(timeSpanSecond));
|
|
|
|
_nextBtn.gameObject.SetActive(true);
|
|
|
|
var text = this._nextBtn.GetComponentInChildren<TextMeshProUGUI>(true);
|
|
text.text = string.Empty;
|
|
var str = _tipString;
|
|
var result = await DOTween
|
|
.To(() => text.text, value => text.text = value, str, duration)
|
|
.SetEase(Ease.Linear)
|
|
.AwaitForComplete(TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait, cancellationToken: cancellationToken)
|
|
.SuppressCancellationThrow();
|
|
Debug.Log(this.name + "IsCanceled: " + result);
|
|
// 箭头动画 TODO
|
|
if (result != true)
|
|
{
|
|
await _nextBtn.OnClickAsync(cancellationToken).SuppressCancellationThrow();
|
|
}
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[Button]
|
|
public void SetValue()
|
|
{
|
|
var text = _nextBtn.GetComponentInChildren<TextMeshProUGUI>();
|
|
text.alignment = TextAlignmentOptions.Midline;
|
|
text.text = _tipString;
|
|
UnityEditor.EditorUtility.SetDirty(text);
|
|
}
|
|
|
|
[Button]
|
|
public void SetSize()
|
|
{
|
|
var text = this._nextBtn.GetComponentInChildren<TextMeshProUGUI>(true);
|
|
var fitter = default(ContentSizeFitter);
|
|
if (text.TryGetComponent<ContentSizeFitter>(out fitter) != true)
|
|
{
|
|
fitter = text.gameObject.AddComponent<ContentSizeFitter>();
|
|
}
|
|
fitter.enabled = true;
|
|
fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
//fitter.SetLayoutHorizontal();
|
|
//fitter.enabled = false;
|
|
UnityEditor.EditorUtility.SetDirty(fitter);
|
|
UnityEditor.EditorUtility.SetDirty(text);
|
|
UnityEditor.EditorUtility.SetDirty(text.transform);
|
|
}
|
|
|
|
[Button]
|
|
public void SetAlignment()
|
|
{
|
|
var text = this._nextBtn.GetComponentInChildren<TextMeshProUGUI>(true);
|
|
text.alignment = TextAlignmentOptions.MidlineLeft;
|
|
UnityEditor.EditorUtility.SetDirty(text);
|
|
text.GetComponent<ContentSizeFitter>().enabled = false;
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
} |