using System; using System.Collections.Generic; using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical; using UnityEngine; using Object = UnityEngine.Object; namespace Core.UI.UTool.UITween { [ExecuteInEditMode] public class UITweenController : MonoBehaviour { public List allTargets = new List(); public TweenAssetInfo TweenAssetInfo; public bool TargetFoldout = true; // public List allTweenInfo = new List(); public float maxDuration; public bool isUpdate; [HideInInspector] public float currTime; private void OnEnable() { if (Application.isPlaying) { StartPlay(); } } public void StartPlay() { if (TweenAssetInfo == null) { return; } maxDuration = 0; for (int i = 0; i < TweenAssetInfo.allTweenInfo.Count; i++) { TweenEntity tweenEntity = TweenAssetInfo.allTweenInfo[i]; if (tweenEntity.duration + tweenEntity.delay > maxDuration) { maxDuration = tweenEntity.duration + tweenEntity.delay; } tweenEntity.Prepare(); tweenEntity.Rest(allTargets[i]); } isUpdate = true; currTime = 0; } public void SetMaxTime() { maxDuration = 0; for (int i = 0; i < TweenAssetInfo.allTweenInfo.Count; i++) { TweenEntity tweenEntity = TweenAssetInfo.allTweenInfo[i]; if (tweenEntity.duration + tweenEntity.delay > maxDuration) { maxDuration = tweenEntity.duration + tweenEntity.delay; } } } public void JumpToTime(float t) { for (int i = 0; i < TweenAssetInfo.allTweenInfo.Count; i++) { TweenAssetInfo.allTweenInfo[i].Prepare(); // allTweenInfo[i].Rest(); } PlayTween(t, true); } private void PlayTween(float t, bool isFallBack) { for (int i = 0; i < TweenAssetInfo.allTweenInfo.Count; i++) { TweenAssetInfo.allTweenInfo[i].Play(allTargets[i], t, isFallBack); } } private void Update() { if (!isUpdate) { return; } currTime += Time.deltaTime; PlayTween(currTime, false); if (currTime >= maxDuration) { isUpdate = false; } } } }