public static TWEAK_IgnoreTimeScale GetInstance() { if (instance == null) { GameObject go = new GameObject(); go.name = "TWEAK_IgnoreTimeScale"; DontDestroyOnLoad(go); instance = go.AddComponent <TWEAK_IgnoreTimeScale>(); } return(instance); }
/// <summary> /// Get the value from the animation curve using the timer /// </summary> /// <returns>The by animation curve.</returns> protected IEnumerator TweenByAnimationCurve(bool _bResume = false) { if (_bResume) { m_fStartTime = Time.realtimeSinceStartup; m_fCurTime = m_fStartTime + m_fDuration * m_fCurAvancement; } else { m_fStartTime = Time.realtimeSinceStartup; m_fCurTime = m_fStartTime; } while (m_fCurTime < m_fStartTime + m_fDuration) { m_fCurAvancement = Mathf.Abs(m_fLoopFactor - (m_fCurTime - m_fStartTime) / m_fDuration); ValueUpdated(m_aniCurve.Evaluate(m_fCurAvancement)); if (m_bTimeScaleIndependant) { m_fCurTime += TWEAK_IgnoreTimeScale.GetInstance().realTimeDelta; } else { m_fCurTime += Time.deltaTime; } yield return(null); } m_fCurAvancement = m_aniCurve.Evaluate(Mathf.Abs(m_fLoopFactor - 1f)); ValueUpdated(m_fCurAvancement); switch (m_loopType) { case LoopType.Once: OnTweenFinished(); break; case LoopType.Loop: StartCoroutine(TweenByAnimationCurve()); break; case LoopType.PingPong: m_fLoopFactor = m_fLoopFactor == 0 ? 1 : 0; StartCoroutine(TweenByAnimationCurve()); break; } }
/// <summary> /// Start the tween after a delay /// </summary> /// <returns>The tween co routine.</returns> /// <param name="_fDelay">_f delay.</param> protected IEnumerator StartTweenCoRoutine(float _fDelay, bool _bResume = false) { m_fStartTime = Time.realtimeSinceStartup; m_fCurTime = Time.realtimeSinceStartup; while (m_fCurTime < m_fStartTime + _fDelay) { if (m_bTimeScaleIndependant) { m_fCurTime += TWEAK_IgnoreTimeScale.GetInstance().realTimeDelta; } else { m_fCurTime += Time.deltaTime; } yield return(null); } ImmediateStartTween(_bResume); }
protected virtual void Awake() { instance = this; }