using Sirenix.OdinInspector; using System.Threading; using UnityEngine; using UnityEngine.UI; using DG.Tweening; using System.Collections.Generic; using Cysharp.Threading.Tasks; using TMPro; using Object = UnityEngine.Object; namespace PMaker.Await { public abstract partial class AwaitBehaviour : BaseBehaviour { public bool isFinish = false; public abstract UniTask WaitAsync(CancellationToken cancellationToken = default); protected async UniTask WaitTrue(CancellationToken cancellationToken = default) { await UniTask.WaitUntil(() => this.isFinish == true, cancellationToken: cancellationToken); } protected async UniTask WaitFalse(CancellationToken cancellationToken = default) { await UniTask.WaitUntil(() => this.isFinish == false, cancellationToken: cancellationToken); } protected void SetTrue() { isFinish = true; } protected void SetFalse() { isFinish = false; } } #if UNITY_EDITOR public partial class AwaitBehaviour { [Button] [HideInEditorMode] private async UniTask WaitAsyncTest() { await this.WaitAsync(this.GetCancellationTokenOnDestroy()); } } #endif public abstract partial class AwaitBehaviour { protected virtual void CheObjActive(T obj, bool isOpen = false) where T : Object { if (obj != null) { var o = obj as Component; o.gameObject.SetActive(isOpen); return; } Debug.LogWarning($"ChangeObj is null"); } /// /// 改变Obj的状态 che为change /// /// /// protected virtual void CheObjActive(GameObject item, bool isOpen = false) { if (item != null) { item.SetActive(isOpen); return; } Debug.LogWarning($"ChangeGameObj is null"); } /// /// 改变Obj数组的状态 che为change /// /// /// protected virtual void CheGameObjActive(GameObject[] item, bool isOpen = false) { for (int i = 0; i < item.Length; i++) { if (item[i] != null) { item[i].SetActive(isOpen); } } } /// /// 改变Obj数组中的单个状态 che为change /// /// /// protected virtual void CheObjListOneActive(GameObject[] item, int index, bool isOpen = false) { for (int i = 0; i < item.Length; i++) { if (index.Equals(i)) { item[i].SetActive(isOpen); return; } } } /// /// 除了传入的值激活其他都失活 /// /// /// /// protected void CheObjListAllActive(List item, int index = -1, bool isOpen = false) where T : Object { if (item.Count < 0) { return; } for (int i = 0; i < item.Count; i++) { var obj = item[i] as Component; if (obj == null) continue; if (index.Equals(i)) { obj.gameObject.SetActive(isOpen); } else { obj.gameObject.SetActive(!isOpen); } } } /// /// 除了传入的值激活其他都失活 /// /// /// /// protected void CheObjListAllActive(List item, int index = -1, int count = 0, bool isOpen = false) where T : Object { if (item.Count < 0) { return; } for (int i = 0; i < item.Count; i++) { var obj = item[i] as Component; if (obj == null) continue; if (i < count) { if (index.Equals(i)) { obj.gameObject.SetActive(isOpen); } } else { obj.gameObject.SetActive(!isOpen); } } } /// /// 除了传入的值激活其他都失活 /// /// /// /// protected void CheObjListAllActive(List item, int index = -1, bool isOpen = false) { if (item.Count < 0) { return; } for (int i = 0; i < item.Count; i++) { if (item[i] is null) continue; if (index.Equals(i)) { item[i].SetActive(isOpen); } else { item[i].SetActive(!isOpen); } } } public void DoTexts(Text text, string context = "", int time = 0, int speed = 0) { text.DOText(context, time).SetEase(Ease.Linear); } public void DoTMPTexts(TextMeshProUGUI text, string context = "", float time = 0, int speed = 0) { DOTween.To(() => string.Empty, value => text.text = value, context, time).SetEase(Ease.Linear); } /// /// 除了传入的值激活其他都失活 /// /// /// /// /// protected void CheObjListAllActive(List item, int index = -1, int count = 0, bool isOpen = false) { if (item.Count < 0) { return; } for (int i = 0; i < item.Count; i++) { if (i < count) { if (item[i] is null) continue; if (index.Equals(i)) { item[i].SetActive(isOpen); } else { item[i].SetActive(!isOpen); } } } } } }