Exemple #1
0
 /// <summary>
 /// 初始化计时器驱动
 /// </summary>
 /// <returns>驱动的实例</returns>
 public static TimerDriver Initialize()
 {
     if (!Application.isPlaying)
         return null;
     if (!hasInit)
     {
         hasInit = true;
         _instance = new GameObject("TimerEntity").AddComponent<TimerDriver>();
         DontDestroyOnLoad(_instance.gameObject);
         _instance.gameObject.hideFlags = HideFlags.HideAndDontSave;
     }
     return _instance;
 }
Exemple #2
0
 /// <summary>
 /// 构造定时器
 /// </summary>
 /// <param name="time">定时时长</param>
 /// <param name="flag">定时器标识符</param>
 /// <param name="loop">是否循环</param>
 /// <param name="ignorTimescale">是否忽略TimeScale</param>
 private Timer(float time, string flag, bool loop = false, bool ignorTimescale = true)
 {
     if (null == driver)
     {
         driver = TimerDriver.Get;                 //初始化Time驱动
     }
     _time           = time;
     _loop           = loop;
     _ignorTimescale = ignorTimescale;
     cachedTime      = CurrentTime;
     if (timers.Exists((v) => { return(v._flag == flag); }))
     {
         if (showLog)
         {
             Debug.LogWarningFormat("【TimerTrigger(容错)】:存在相同的标识符【{0}】!", flag);
         }
     }
     _flag = string.IsNullOrEmpty(flag) ? GetHashCode().ToString() : flag;//设置辨识标志符
 }
Exemple #3
0
 /// <summary>
 /// 初始化 Timer 驱动 ,一般都是懒汉加载,但如要在 非主线程使用,请务必手动初始化
 /// </summary>
 public static void IntializeDriver()
 {
     driver = driver ?? TimerDriver.Initialize();
 }
Exemple #4
0
 private void Awake()
 {
     _instance = this;
     hasInit = true;
 }
Exemple #5
0
 private void Awake()
 {
     _instance = this;
 }