123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- 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<int> DestList = new List<int>();
- public List<float> DelayList = new List<float>();
- public List<float> DurationList = new List<float>();
- public List<IntPair> DestKvList = new List<IntPair>();
- public List<UnityAction> ActionList = new List<UnityAction>();
- public Text Target;
- public CurveFunctionF Func;
- #endregion
- public StreamFont(Text target, List<int> destList, List<float> delayList, List<float> durationList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> 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<IntPair> destKvList, List<float> delayList, List<float> durationList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> 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();
- }
- }
|