Tanoda
unity-ui-extensions/Runtime/Scripts/Controls/Accordion/Tweening/TweenRunner.cs
Go to the documentation of this file.
1
3
4using System.Collections;
5
7{
8 // Tween runner, executes the given tween.
9 // The coroutine will live within the given
10 // behaviour container.
11 internal class TweenRunner<T> where T : struct, ITweenValue
12 {
13 protected MonoBehaviour m_CoroutineContainer;
14 protected IEnumerator m_Tween;
15
16 // utility function for starting the tween
17 private static IEnumerator Start(T tweenInfo)
18 {
19 if (!tweenInfo.ValidTarget())
20 yield break;
21
22 float elapsedTime = 0.0f;
23 while (elapsedTime < tweenInfo.duration)
24 {
25 elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
26 var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
27 tweenInfo.TweenValue (percentage);
28 yield return null;
29 }
30 tweenInfo.TweenValue (1.0f);
31 tweenInfo.Finished();
32 }
33
34 public void Init(MonoBehaviour coroutineContainer)
35 {
36 m_CoroutineContainer = coroutineContainer;
37 }
38
39 public void StartTween(T info)
40 {
41 if (m_CoroutineContainer == null)
42 {
43 Debug.LogWarning ("Coroutine container not configured... did you forget to call Init?");
44 return;
45 }
46
47 if (m_Tween != null)
48 {
49 m_CoroutineContainer.StopCoroutine (m_Tween);
50 m_Tween = null;
51 }
52
53 if (!m_CoroutineContainer.gameObject.activeInHierarchy)
54 {
55 info.TweenValue(1.0f);
56 return;
57 }
58
59 m_Tween = Start (info);
60 m_CoroutineContainer.StartCoroutine (m_Tween);
61 }
62 }
63}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19