Skip to content

Commit

Permalink
close #19 : Play effect from script
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed May 24, 2018
1 parent f9b9a70 commit 3a5d3ec
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Assets/ShinyEffectForUGUI/ShinyEffectForUGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
using System.Collections;

#if UNITY_EDITOR
using System.IO;
Expand Down Expand Up @@ -188,6 +189,32 @@ public override void ModifyMesh(VertexHelper vh)
}
}

/// <summary>
/// Play effect.
/// </summary>
public void Play()
{
Play(1);
}

/// <summary>
/// Play effect.
/// </summary>
public void Play(float duration)
{
StopAllCoroutines();
StartCoroutine(CoPlay(duration, AnimatorUpdateMode.Normal));
}

/// <summary>
/// Play effect.
/// </summary>
public void Play(float duration, AnimatorUpdateMode updateMode)
{
StopAllCoroutines();
StartCoroutine(CoPlay(duration, updateMode));
}

//################################
// Private Members.
//################################
Expand All @@ -200,6 +227,19 @@ void _SetDirty()
graphic.SetVerticesDirty();
}

IEnumerator CoPlay(float duration, AnimatorUpdateMode updateMode = AnimatorUpdateMode.Normal)
{
float time = 0;
while (time < duration)
{
location = time / duration;
time += updateMode == AnimatorUpdateMode.UnscaledTime
? Time.unscaledDeltaTime
: Time.deltaTime;
yield return null;
}
}

/// <summary>
/// Pack 4 low-precision [0-1] floats values to a float.
/// Each value [0-1] has 64 steps(6 bits).
Expand Down

0 comments on commit 3a5d3ec

Please sign in to comment.