using UnityEngine; using System.Collections; using System; using System.Collections.Generic; public class TimeRecoveryHelper : MonoSingleton { /// /// /// public Dictionary allTimerDic = new Dictionary(); /// /// /// /// /// public void StartTimer(string functionName, int seconds, Action leftTs) { if (allTimerDic.ContainsKey(functionName)) { GameObject xx = allTimerDic[functionName]; TimeRecovery timer = xx.GetComponent(); timer.StartTimer(seconds, leftTs); } else { GameObject xx = new GameObject(); xx.transform.SetParent(this.gameObject.transform); TimeRecovery timer = xx.GetComponent(); if (timer == null) { AssemblyHelper.Instance.BindScript("TimeRecovery", xx); timer = xx.GetComponent(); } timer.StartTimer(seconds, leftTs); allTimerDic.Add(functionName, xx); } } public void StopTimer(string functionName) { if (allTimerDic.ContainsKey(functionName)) { GameObject xx = allTimerDic[functionName]; TimeRecovery timer = xx.GetComponent(); timer.StopTimer(); Destroy(xx); allTimerDic.Remove(functionName); } } }