using UnityEngine;
using System.Collections;
/// <summary>
/// Reset tween children on enable.
/// </summary>
public class ResetChildrenTweensOnEnable : MonoBehaviour {
[SerializeField]
bool m_ResetChildren = true;
[SerializeField]
public bool m_AutoPlayOnEnable = true;
//tweens
private UITweener[] m_tweens;
/// <summary>
/// Gets all the tweeners.
/// </summary>
void Start () {
if (m_tweens == null)
{
if(m_ResetChildren)
m_tweens = GetComponentsInChildren<UITweener>();
else
m_tweens = GetComponents<UITweener>();
}
}
/// <summary>
/// Reset all the tweens. Made this function public so other script could call this function manually to reset all the tweeners.
/// </summary>
public void OnEnable () {
if (m_tweens == null)
{
Start();
}
for (int i = 0; i < m_tweens.Length; i++)
{
if(m_AutoPlayOnEnable)
{
m_tweens [i].ResetToBeginning();
m_tweens [i].enabled = true;
m_tweens [i].PlayForward();
}
}
}
/// <summary>
/// Resets the tween.
/// </summary>
public void ResetTween()
{
if (m_tweens == null)
{
Start();
}
for (int i = 0; i < m_tweens.Length; i++)
{
m_tweens [i].ResetToBeginning();
m_tweens [i].enabled = true;
m_tweens [i].PlayForward();
}
}
}