//Add a new timer to the tool, returns the key used public string AddTimer(string name, float length) { TimerObj newTimer = new TimerObj(); newTimer.timerLength = length; newTimer.finished = true; // Set to true as there has been no timer set yet //This will correct any duplicate names if (timerDictionary.ContainsKey(name)) { Debug.Log("TimerTool.cs | WARNING: Duplicate timer added, function will return a new key that isn't duplicate"); string newName = name; int i = 0; //Keep iterating i untill it hits a number that hasn't been useed while (timerDictionary.ContainsKey(newName)) { newName = name + i.ToString(); i++; } timerDictionary.Add(newName, newTimer); return(newName); } else { timerDictionary.Add(name, newTimer); return(name); } }
public static TimerObj LazyScheduleTimer(float duration, TimerObj.FinishTimerDelegate _finishTimerDelegate) { TimerObj timer = new TimerObj(duration, _finishTimerDelegate); timer.isSchedule = true; return(timer); }
public void Stop() { lock (TimerObjLock) { TimerObj?.Dispose(); TimerObj = null; } }
public void Stop() { if (DpTimerObj == null) { TimerObj.Stop(); } else { DpTimerObj.Stop(); } }
//End the timer prematurely public void EndTimer(string name) { if (timerDictionary.ContainsKey(name)) { TimerObj temp = timerDictionary[name]; temp.finished = true; temp.currentTime = 0; timerDictionary[name] = temp; } else { Debug.Log("TimerTool.cs | ERROR: Timer " + name + " not found"); } }
//Starts the timer sent in public void StartTimer(string name) { if (timerDictionary.ContainsKey(name)) { TimerObj temp = timerDictionary[name]; temp.finished = false; temp.currentTime = Time.time + temp.timerLength; timerDictionary[name] = temp; } else { Debug.Log("TimerTool.cs | ERROR: Timer " + name + " not found"); } }
//Checks to see if the timer has been finished public bool CheckTimer(string name) { if (timerDictionary.ContainsKey(name)) { //If the timer has finished, either though time or if the variable has allready been finished if (timerDictionary[name].currentTime < Time.time || timerDictionary[name].finished) { TimerObj temp = timerDictionary[name]; temp.finished = true; temp.currentTime = 0; timerDictionary[name] = temp; return(true); } } else { Debug.Log("TimerTool.cs | ERROR: Timer " + name + " not found"); } return(false); }
public void AddTimerObj(TimerObj node) { timerObjs.Add(node); }