using System.Collections.Generic;
using UnityEngine;
public class PopupTest : MonoBehaviour
{
#region Editor Interface
[SerializeField] private TweenScale tweener;
[SerializeField] private int secondsToDisplay;
#endregion
#region Private Fields
private static PopupTest instance;
private static Queue
<string> queue
= new Queue
<string>(); private static bool isActive = false;
#endregion
#region MonoBehaviour Methods
private void Awake ()
{
//Enforce the singleton pattern
if ( instance != null )
{
Debug.LogError("Multiple instances of the " + GetType() + " created. There can be only one.");
}
instance = this;
}
private void OnDisable ()
{
isActive = false;
NGUITools.SetActiveChildren(gameObject, false);
tweener.onFinished.Clear();
tweener.enabled = false;
queue.Clear();
}
private void OnDestroy ()
{
instance = null;
}
#endregion
#region Public Interface
public static void Display ()
{
if ( !instance.gameObject.activeInHierarchy ) return;
queue.Enqueue("Test");
if ( !isActive )
{
instance.Show();
}
}
#endregion
#region Private Methods
private void Show ()
{
queue.Dequeue();
EventDelegate.Add(tweener.onFinished, Hide, true);
tweener.delay = 0;
tweener.Play(true);
Debug.Log("Scale (play1):" + transform.localScale);
tweener.ResetToBeginning();
Debug.Log("Scale (reset):" + transform.localScale);
tweener.Play(true);
Debug.Log("Scale (play2):" + transform.localScale);
isActive = true;
NGUITools.SetActiveChildren(gameObject, true);
}
private void Hide ()
{
EventDelegate.Add(tweener.onFinished, HideComplete, true);
tweener.delay = secondsToDisplay;
tweener.Play(false);
}
private void HideComplete ()
{
isActive = false;
NGUITools.SetActiveChildren(gameObject, false);
if ( queue.Count > 0 )
{
Show();
}
}
#endregion
}