diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs
new file mode 100644
index 0000000..543e3d3
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs
@@ -0,0 +1,117 @@
+using UnityEngine;
+using System;
+
+namespace Coffee.UIExtensions
+{
+ ///
+ /// Effect Runner.
+ ///
+ [Serializable]
+ public class EffectRunner
+ {
+ //################################
+ // Public Members.
+ //################################
+ ///
+ /// Gets or sets a value indicating whether is running.
+ ///
+ public bool running;// { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether can loop.
+ ///
+ public bool loop;// { get; set; }
+
+ ///
+ /// Gets or sets the duration.
+ ///
+ public float duration;// { get; set; }
+
+ ///
+ /// Gets or sets the delay before looping.
+ ///
+ public float loopDelay;// { get; set; }
+
+ ///
+ /// Gets or sets the update mode.
+ ///
+ public AnimatorUpdateMode updateMode;// { get; set; }
+
+// ///
+// /// Register runner.
+// ///
+// public void Register(bool running,float duration, AnimatorUpdateMode updateMode, bool loop, float loopDelay, Action callback)
+// {
+// Canvas.willRenderCanvases += OnWillRenderCanvases;
+//
+// _time = 0;
+// this._callback = callback;
+// this.loop = loop;
+// this.running = running;
+// this.duration = duration;
+// this.loopDelay = loopDelay;
+// this.updateMode = updateMode;
+// }
+
+ public void OnEnable(Action callback)
+ {
+ Canvas.willRenderCanvases += OnWillRenderCanvases;
+
+ _time = 0;
+ this._callback = callback;
+ }
+
+// ///
+// /// Unregister runner.
+// ///
+// public void Unregister()
+// {
+// _callback = null;
+// Canvas.willRenderCanvases -= OnWillRenderCanvases;
+// }
+
+ ///
+ /// Unregister runner.
+ ///
+ public void OnDisable()
+ {
+ _callback = null;
+ Canvas.willRenderCanvases -= OnWillRenderCanvases;
+ }
+
+ ///
+ /// Play runner.
+ ///
+ public void Play()
+ {
+ _time = 0;
+ running = true;
+ }
+
+ //################################
+ // Private Members.
+ //################################
+ float _time = 0;
+ Action _callback;
+
+ void OnWillRenderCanvases()
+ {
+ if (!running || !Application.isPlaying)
+ {
+ return;
+ }
+
+ _time += updateMode == AnimatorUpdateMode.UnscaledTime
+ ? Time.unscaledDeltaTime
+ : Time.deltaTime;
+ var current = _time / duration;
+
+ if (duration <= _time)
+ {
+ running = loop;
+ _time = loop ? -loopDelay : 0;
+ }
+ _callback(current);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs.meta
new file mode 100644
index 0000000..661e073
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/EffectRunner.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1656fb67110cd44298010d95c324e87a
+timeCreated: 1528296875
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
index e5d0d85..0631f06 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
@@ -27,9 +27,16 @@ namespace Coffee.UIExtensions
[SerializeField] Texture m_NoiseTexture;
[SerializeField] protected EffectArea m_EffectArea;
[SerializeField] bool m_KeepAspectRatio;
+
+ [Header("Effect Runner")]
+ [SerializeField] EffectRunner m_Runner;
+
[Header("Play Effect")]
+ [Obsolete][HideInInspector]
[SerializeField] bool m_Play = false;
+ [Obsolete][HideInInspector]
[SerializeField][Range(0.1f, 10)] float m_Duration = 1;
+ [Obsolete][HideInInspector]
[SerializeField] AnimatorUpdateMode m_UpdateMode = AnimatorUpdateMode.Normal;
@@ -161,19 +168,29 @@ namespace Coffee.UIExtensions
public ColorMode colorMode { get { return m_ColorMode; } }
///
- /// Play dissolve on enable.
+ /// Play effect on enable.
///
- public bool play { get { return m_Play; } set { m_Play = value; } }
+ public bool play { get { return m_Runner.running; } set { m_Runner.running = value; } }
///
- /// Dissolve duration.
+ /// Play effect loop.
///
- public float duration { get { return m_Duration; } set { m_Duration = Mathf.Max(value, 0.1f); } }
+ public bool loop { get { return m_Runner.loop; } set { m_Runner.loop = value; } }
///
- /// Dissolve update mode.
+ /// The duration for playing effect.
///
- public AnimatorUpdateMode updateMode { get { return m_UpdateMode; } set { m_UpdateMode = value; } }
+ public float duration { get { return m_Runner.duration; } set { m_Runner.duration = Mathf.Max(value, 0.1f); } }
+
+ ///
+ /// Delay on loop effect.
+ ///
+ public float loopDelay { get { return m_Runner.loopDelay; } set { m_Runner.loopDelay = Mathf.Max(value, 0); } }
+
+ ///
+ /// Update mode for playing effect.
+ ///
+ public AnimatorUpdateMode updateMode { get { return m_Runner.updateMode; } set { m_Runner.updateMode = value; } }
///
/// Modifies the material.
@@ -256,8 +273,7 @@ namespace Coffee.UIExtensions
///
public void Play()
{
- _time = 0;
- m_Play = true;
+ m_Runner.Play();
}
@@ -269,8 +285,8 @@ namespace Coffee.UIExtensions
///
protected override void OnEnable()
{
- _time = 0;
base.OnEnable();
+ m_Runner.OnEnable(f => location = f);
}
protected override void OnDisable()
@@ -278,6 +294,7 @@ namespace Coffee.UIExtensions
MaterialCache.Unregister(_materialCache);
_materialCache = null;
base.OnDisable();
+ m_Runner.OnDisable();
}
#if UNITY_EDITOR
@@ -295,25 +312,5 @@ namespace Coffee.UIExtensions
// Private Members.
//################################
MaterialCache _materialCache = null;
- float _time = 0;
-
- void Update()
- {
- if (!m_Play || !Application.isPlaying)
- {
- return;
- }
-
- _time += m_UpdateMode == AnimatorUpdateMode.UnscaledTime
- ? Time.unscaledDeltaTime
- : Time.deltaTime;
- location = _time / m_Duration;
-
- if (m_Duration <= _time)
- {
- m_Play = false;
- _time = 0;
- }
- }
}
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
index 6ecccdf..ac3f224 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
@@ -37,11 +37,18 @@ namespace Coffee.UIExtensions
[SerializeField][Range(0, 1)] float m_Brightness = 1f;
[SerializeField][Range(0, 1)] float m_Highlight = 1;
[SerializeField] protected EffectArea m_EffectArea;
- [Header("Play Effect")]
+ [Header("Effect Runner")]
+ [SerializeField] EffectRunner m_Runner;
+
+ [Obsolete][HideInInspector]
[SerializeField] bool m_Play = false;
+ [Obsolete][HideInInspector]
[SerializeField] bool m_Loop = false;
+ [Obsolete][HideInInspector]
[SerializeField][Range(0.1f, 10)] float m_Duration = 1;
+ [Obsolete][HideInInspector]
[SerializeField][Range(0, 10)] float m_LoopDelay = 1;
+ [Obsolete][HideInInspector]
[SerializeField] AnimatorUpdateMode m_UpdateMode = AnimatorUpdateMode.Normal;
@@ -191,46 +198,48 @@ namespace Coffee.UIExtensions
///
/// Play shinning on enable.
///
- public bool play { get { return m_Play; } set { m_Play = value; } }
+ public bool play { get { return m_Runner.running; } set { m_Runner.running = value; } }
///
/// Play shinning loop.
///
- public bool loop { get { return m_Loop; } set { m_Loop = value; } }
+ public bool loop { get { return m_Runner.loop; } set { m_Runner.loop = value; } }
///
/// Shinning duration.
///
- public float duration { get { return m_Duration; } set { m_Duration = Mathf.Max(value, 0.1f); } }
+ public float duration { get { return m_Runner.duration; } set { m_Runner.duration = Mathf.Max(value, 0.1f); } }
///
/// Delay on loop.
///
- public float loopDelay { get { return m_LoopDelay; } set { m_LoopDelay = Mathf.Max(value, 0); } }
+ public float loopDelay { get { return m_Runner.loopDelay; } set { m_Runner.loopDelay = Mathf.Max(value, 0); } }
///
/// Shinning update mode.
///
- public AnimatorUpdateMode updateMode { get { return m_UpdateMode; } set { m_UpdateMode = value; } }
+ public AnimatorUpdateMode updateMode { get { return m_Runner.updateMode; } set { m_Runner.updateMode = value; } }
///
/// This function is called when the object becomes enabled and active.
///
protected override void OnEnable()
{
- _time = 0;
-// graphic.material = effectMaterial;
base.OnEnable();
+// m_Runner.Register(m_Play, m_Duration, m_UpdateMode, m_Loop, m_LoopDelay, f => location = f);
+ m_Runner.OnEnable(f => location = f);
}
+ ///
+ /// This function is called when the behaviour becomes disabled () or inactive.
+ ///
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+ m_Runner.OnDisable();
+ }
-// ///
-// /// This function is called when the behaviour becomes disabled () or inactive.
-// ///
-// protected override void OnDisable()
// {
-// graphic.material = null;
-// base.OnDisable();
// }
#if UNITY_EDITOR
@@ -239,28 +248,6 @@ namespace Coffee.UIExtensions
return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName));
}
-// public void OnBeforeSerialize()
-// {
-// }
-//
-// public void OnAfterDeserialize()
-// {
-// var obj = this;
-// EditorApplication.delayCall += () =>
-// {
-// if (Application.isPlaying || !obj)
-// return;
-//
-// var mat = GetMaterial(shaderName);
-// if (m_EffectMaterial == mat && graphic.material == mat)
-// return;
-//
-// graphic.material = m_EffectMaterial = mat;
-// EditorUtility.SetDirty(this);
-// EditorUtility.SetDirty(graphic);
-// EditorApplication.delayCall += AssetDatabase.SaveAssets;
-// };
-// }
//
// public static Material GetMaterial(string shaderName)
// {
@@ -328,42 +315,12 @@ namespace Coffee.UIExtensions
///
public void Play()
{
- _time = 0;
- m_Play = true;
+ m_Runner.Play();
}
//################################
// Private Members.
//################################
- float _time = 0;
-
- void Update()
- {
- if (!m_Play || !Application.isPlaying)
- {
- return;
- }
-
- _time += m_UpdateMode == AnimatorUpdateMode.UnscaledTime
- ? Time.unscaledDeltaTime
- : Time.deltaTime;
- location = _time / m_Duration;
-
- if (m_Duration <= _time)
- {
- m_Play = m_Loop;
- _time = m_Loop ? -m_LoopDelay : 0;
- }
- }
-
-// ///
-// /// Mark the UIEffect as dirty.
-// ///
-// void _SetDirty()
-// {
-// if (graphic)
-// graphic.SetVerticesDirty();
-// }
}
}