using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using System; using System.Collections; using System.Collections.Generic; public struct IntPair { public int Key; public int Value; public IntPair(int key, int value) { Key = key; Value = value; } } public class StreamFont : Tween { #region 变量 public override bool InOrigin { get { if (Consecutive) { if (Target.fontSize.Equal(DestList[0])) { _InOrigin = true; } else { _InOrigin = false; } } else { if (Target.fontSize.Equal(DestKvList[0].Key)) { _InOrigin = true; } else { _InOrigin = false; } } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { if (Consecutive) { Target.fontSize = DestList[0]; } else { Target.fontSize = DestKvList[0].Key; } FinishBackward(); } } } public override bool InDestination { get { if (Consecutive) { if (Target.fontSize.Equal(DestList.Last(0))) { _InDestination = true; } else { _InDestination = false; } } else { if (Target.fontSize.Equal(DestKvList.Last(0).Value)) { _InDestination = true; } else { _InDestination = false; } } return _InDestination; } set { _InDestination = value; if (_InDestination) { if (Consecutive) { Target.fontSize = DestList.Last(0); } else { Target.fontSize = DestKvList.Last(0).Value; } FinishForward(); } } } public int Phase; public int TotPhase; public int TempDest; public int TempDelta; public int TempOrigin; public bool Consecutive; public float TempDelay; public float TempDuration; public List DestList = new List(); public List DelayList = new List(); public List DurationList = new List(); public List DestKvList = new List(); public List ActionList = new List(); public Text Target; public CurveFunctionF Func; #endregion public StreamFont(Text target, List destList, List delayList, List durationList, bool originActive, bool destActive, Curve curve, bool cg = false, List actionList = null) : base(cg, curve, target) { Func = ManaAnim.CurveFuncDicF[curve]; Target = target; TotPhase = destList.Count - 1; Consecutive = true; DestList = destList; DelayList = delayList; ActionList = actionList; DurationList = durationList; if (ActionList.Valid()) { if ((DestList.Count - 1) - ActionList.Count != -1) { throw new Exception(); } } if (DestList.Count - DelayList.Count != 2) { throw new Exception(); } if (DestList.Count - DurationList.Count != 1) { throw new Exception(); } InForward = false; InBackward = false; DestActive = destActive; OriginActive = originActive; } public StreamFont(Text target, List destKvList, List delayList, List durationList, bool originActive, bool destActive, Curve curve, bool cg = false, List actionList = null) : base(cg, curve, target) { Func = ManaAnim.CurveFuncDicF[curve]; Target = target; TotPhase = destKvList.Count - 1; Consecutive = false; DelayList = delayList; ActionList = actionList; DestKvList = destKvList; DurationList = durationList; if (ActionList.Valid()) { if (DestKvList.Count - ActionList.Count != -1) { throw new Exception(); } } if (DestKvList.Count - DelayList.Count != 1) { throw new Exception(); } if (DestKvList.Count - DurationList.Count != 0) { throw new Exception(); } InForward = false; InBackward = false; DestActive = destActive; OriginActive = originActive; } public override void StartForward() { base.StartForward(); if (Consecutive) { Phase = 1; TempDest = DestList[1]; TempDelay = DelayList[0]; TempOrigin = DestList[0]; TempDuration = DurationList[0]; } else { Phase = 0; TempDest = DestKvList[0].Value; TempDelay = DelayList[0]; TempOrigin = DestKvList[0].Key; TempDuration = DurationList[0]; } TempDelta = TempDest - TempOrigin; if (ActionList.Valid()) { ActionList[0].SafeInvoke(); } //if (InBackward) //{ // Timer = ManaAnim.GetTimerFloat(Target.fontSize, Duration, TempOrigin, TempDelta, Curve); //} } public override void StartBackward() { base.StartBackward(); throw new Exception(); } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Phase == TotPhase) { if (Timer > TempDuration) { FinishForward(); Timer = 0; InForward = false; InDestination = true; if (OnForwardFinish != null) { OnForwardFinish.Invoke(); } if (ActionList.Valid()) { ActionList.Last(0).SafeInvoke(); } return true; } else { Target.fontSize = (int)Func(Timer, TempDuration, TempOrigin, TempDelta); return false; } } else { if (Timer > TempDuration + TempDelay) { Timer = 0; Phase++; if (Consecutive) { TempDest = DestList[Phase]; TempOrigin = DestList[Phase - 1]; TempDuration = DurationList[Phase - 1]; TempDelta = TempDest - TempOrigin; if (Phase != DestList.Count - 1) { TempDelay = DelayList[Phase - 1]; } if (ActionList.Valid()) { ActionList[Phase - 1].SafeInvoke(); } } else { TempDest = DestKvList[Phase].Value; TempOrigin = DestKvList[Phase].Key; TempDuration = DurationList[Phase]; TempDelta = TempDest - TempOrigin; if (Phase != DestKvList.Count - 1) { TempDelay = DelayList[Phase]; } if (ActionList.Valid()) { ActionList[Phase].SafeInvoke(); } } return false; } else { Target.fontSize = (int)Func(Timer, TempDuration, TempOrigin, TempDelta); return false; } } } public override bool DoBackward() { throw new Exception(); } }