4using System.Collections;
11 internal class TweenRunner<T> where T : struct, ITweenValue
13 protected MonoBehaviour m_CoroutineContainer;
14 protected IEnumerator m_Tween;
17 private static IEnumerator Start(T tweenInfo)
19 if (!tweenInfo.ValidTarget())
22 float elapsedTime = 0.0f;
23 while (elapsedTime < tweenInfo.duration)
25 elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
26 var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
27 tweenInfo.TweenValue (percentage);
30 tweenInfo.TweenValue (1.0f);
34 public void Init(MonoBehaviour coroutineContainer)
36 m_CoroutineContainer = coroutineContainer;
39 public void StartTween(T info)
41 if (m_CoroutineContainer ==
null)
43 Debug.LogWarning (
"Coroutine container not configured... did you forget to call Init?");
49 m_CoroutineContainer.StopCoroutine (m_Tween);
53 if (!m_CoroutineContainer.gameObject.activeInHierarchy)
55 info.TweenValue(1.0f);
59 m_Tween = Start (info);
60 m_CoroutineContainer.StartCoroutine (m_Tween);