This custom Action can be used to check if a given Timer is currently running.
ActionTimerCheck.cs:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionTimerCheck : ActionCheck
{
public int timerID;
public override ActionCategory Category { get { return ActionCategory.Variable; }}
public override string Title { get { return "Check timer"; }}
public override string Description { get { return "Checks if a Timer is running"; }}
public override bool CheckCondition ()
{
if (KickStarter.variablesManager != null && KickStarter.variablesManager.timers != null)
{
foreach (Timer timer in KickStarter.variablesManager.timers)
{
if (timer.ID == timerID)
{
return timer.IsRunning;
}
}
}
return false;
}
#if UNITY_EDITOR
protected override string GetSocketLabel (int i)
{
if (i == 1)
{
return "If running:";
}
return "If not running:";
}
public override void ShowGUI ()
{
if (GUILayout.Button ("Timers window"))
{
TimersEditor.Init ();
}
int tempNumber = -1;
if (KickStarter.variablesManager != null && KickStarter.variablesManager.timers != null && KickStarter.variablesManager.timers.Count > 0)
{
string[] labelList = new string[KickStarter.variablesManager.timers.Count];
for (int i=0; i<KickStarter.variablesManager.timers.Count; i++)
{
labelList[i] = i.ToString () + ": " + KickStarter.variablesManager.timers[i].Label;
if (KickStarter.variablesManager.timers[i].ID == timerID)
{
tempNumber = i;
}
}
if (tempNumber == -1)
{
// Wasn't found (was deleted?), so revert to zero
if (timerID != 0)
LogWarning ("Previously chosen Timer no longer exists!");
tempNumber = 0;
timerID = 0;
}
tempNumber = EditorGUILayout.Popup ("Timer:", tempNumber, labelList);
timerID = KickStarter.variablesManager.timers [tempNumber].ID;
}
else
{
EditorGUILayout.HelpBox ("No Timers exist!", MessageType.Info);
timerID = 0;
}
}
#endif
}
}