using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class TweenNumber : Tween { #region 变量 public override bool InOrigin { get { if (int.Parse(Target.text) - Origin == 0) { _InOrigin = true; } else { _InOrigin = false; } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { Target.text = Origin.ToString(); FinishBackward(); } } } public override bool InDestination { get { if (int.Parse(Target.text) - Destination == 0) { _InDestination = true; } else { _InDestination = false; } return _InDestination; } set { _InDestination = value; if (_InDestination) { Target.text = Destination.ToString(); FinishForward(); } } } protected int Delta; protected int Origin; protected int Destination; protected Text Target; protected CurveFunctionF Func; #endregion public TweenNumber(Text target, int origin, int destination, float duration, bool originActive, bool destActive, Curve curve, bool cg=false) : base(cg,target) { Func = ManaAnim.CurveFuncDicF[curve]; Target = target; InForward = false; InBackward = false; Delta = destination - origin; Origin = origin; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; } public override void StartForward() { base.StartForward(); if (InBackward) { Timer = Duration - Timer; } else { Target.text = Origin.ToString(); } } public override void StartBackward() { base.StartBackward(); if (InForward) { Timer = Duration - Timer; } else { Target.text = Destination.ToString(); } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { FinishForward(); Timer = 0; InForward = false; InDestination = true; if (OnForwardFinish != null) { OnForwardFinish.Invoke(); } ManaAnim.TweenForList.Remove(this); return true; } else { Target.text = ((int) Func(Timer, Duration, Origin, Delta)).ToString(); return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { FinishBackward(); Timer = 0; InBackward = false; InOrigin = true; if (OnBackwardFinish != null) { OnBackwardFinish.Invoke(); } ManaAnim.TweenBacList.Remove(this); return true; } else { Target.text = ((int) Func(Timer, Duration, Destination, -Delta)).ToString(); return false; } } }