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