123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- 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();
- Target.SetActive(OriginActive);
- }
- }
- }
- 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();
- Target.SetActive(DestActive);
- }
- }
- }
- 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)
- {
- Func = ManaAnim.CurveFuncDicF[curve];
- Target = target;
- InForward = false;
- InBackward = false;
- Delta = destination - origin;
- Origin = origin;
- if (origin == destination)
- {
- Duration = 0;
- }
- else
- {
- Duration = duration;
- }
- DestActive = destActive;
- Destination = destination;
- OriginActive = originActive;
- }
- public override void StartForward()
- {
- base.StartForward();
- Target.SetActive(true);
- if (InBackward)
- {
- Timer = Duration - Timer;
- }
- else
- {
- Target.text = Origin.ToString();
- }
- }
- public override void StartBackward()
- {
- base.StartBackward();
- Target.SetActive(true);
- if (InForward)
- {
- Timer = Duration - Timer;
- }
- else
- {
- Target.text = Destination.ToString();
- }
- }
- public override bool DoForward()
- {
- Timer += Time.fixedDeltaTime;
- if (Timer > Duration)
- {
- 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)
- {
- 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;
- }
- }
- }
|