| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | |
| | | public class TimeMgr : SingletonMonobehaviour<TimeMgr> |
| | | { |
| | | private Dictionary<Component, TimeItem> timeItems = new Dictionary<Component, TimeItem>(); |
| | | private List<TimeItem> timeItemList = new List<TimeItem>(); |
| | | private int m_LastRecordHour = -1; |
| | | private int m_LastRecordMinute = -1; |
| | | public int m_LastRecordDay = -1; |
| | | public event Action OnDayEvent; |
| | | public event Action OnHourEvent; |
| | | public event Action OnMinuteEvent; |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | try |
| | | { |
| | | if (m_LastRecordDay != TimeUtility.ServerNow.Day) |
| | | { |
| | | if (OnDayEvent != null) |
| | | { |
| | | OnDayEvent(); |
| | | } |
| | | m_LastRecordDay = TimeUtility.ServerNow.Day; |
| | | } |
| | | if (m_LastRecordHour != TimeUtility.ServerNow.Hour) |
| | | { |
| | | if (OnHourEvent != null) |
| | | { |
| | | OnHourEvent(); |
| | | } |
| | | m_LastRecordHour = TimeUtility.ServerNow.Hour; |
| | | } |
| | | if (m_LastRecordMinute != TimeUtility.ServerNow.Minute) |
| | | { |
| | | if (OnMinuteEvent != null) |
| | | { |
| | | OnMinuteEvent(); |
| | | } |
| | | m_LastRecordMinute = TimeUtility.ServerNow.Minute; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | DesignDebug.Log(e.Message); |
| | | } |
| | | for (int i = 0; i < syntonyList.Count; i++) |
| | | { |
| | | if ((TimeUtility.ServerNow - syntonyList[i].endTime).TotalSeconds > 0) |
| | | { |
| | | if (syntonyList[i].callback != null) |
| | | { |
| | | syntonyList[i].callback(); |
| | | } |
| | | var _type = syntonyList[i].type; |
| | | syntonyList.RemoveAt(i); |
| | | if (OnSyntonyEvent != null) |
| | | { |
| | | OnSyntonyEvent(_type); |
| | | } |
| | | i--; |
| | | } |
| | | } |
| | | if (timeItems.Count > 0) |
| | | { |
| | | timeItemList.RemoveRange(0, timeItemList.Count); |
| | | foreach (Component item in timeItems.Keys) |
| | | { |
| | | if (item == null) continue; |
| | | timeItemList.Add(timeItems[item]); |
| | | } |
| | | for (int i = 0; i < timeItemList.Count; i++) |
| | | { |
| | | timeItemList[i].Update(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void Register(Component comp, Action<Component> func, float t, int loopCnt = 1) |
| | | { |
| | | if (comp == null) return; |
| | | if (!timeItems.ContainsKey(comp)) |
| | | { |
| | | TimeItem item = new TimeItem(t, comp, loopCnt, func); |
| | | timeItems.Add(comp, item); |
| | | } |
| | | } |
| | | |
| | | public void SetInterval(Component comp, float t) |
| | | { |
| | | if (timeItems.ContainsKey(comp)) |
| | | { |
| | | TimeItem item = timeItems[comp]; |
| | | item.time = t; |
| | | } |
| | | } |
| | | |
| | | public void UnRegister(Component comp) |
| | | { |
| | | if (comp == null) return; |
| | | if (timeItems.ContainsKey(comp)) |
| | | { |
| | | TimeItem item = timeItems[comp]; |
| | | timeItems.Remove(comp); |
| | | item = null; |
| | | } |
| | | } |
| | | |
| | | public void Register(SyntonyType type, float _totalTime, Action _func = null) |
| | | { |
| | | int index; |
| | | if (ContainsSyntony(type, out index)) |
| | | { |
| | | syntonyList[index].SetTime(_totalTime, _func); |
| | | } |
| | | else |
| | | { |
| | | Syntony syntony = new Syntony(); |
| | | syntony.type = type; |
| | | syntony.SetTime(_totalTime, _func); |
| | | syntonyList.Add(syntony); |
| | | } |
| | | } |
| | | |
| | | public void UnRegister(SyntonyType type) |
| | | { |
| | | int index; |
| | | if (ContainsSyntony(type, out index)) |
| | | { |
| | | syntonyList.RemoveAt(index); |
| | | } |
| | | } |
| | | |
| | | public struct Syntony |
| | | { |
| | | public SyntonyType type; |
| | | public DateTime endTime { get; private set; } |
| | | public Action callback; |
| | | public void SetTime(float _totalTime, Action _func = null) |
| | | { |
| | | endTime = TimeUtility.ServerNow.AddSeconds(_totalTime); |
| | | callback = _func; |
| | | DesignDebug.LogFormat("{0}{1}", type, endTime); |
| | | } |
| | | } |
| | | |
| | | private List<Syntony> syntonyList = new List<Syntony>(); |
| | | |
| | | public event Action<SyntonyType> OnSyntonyEvent; |
| | | |
| | | private bool ContainsSyntony(SyntonyType type, out int index) |
| | | { |
| | | index = 0; |
| | | for (int i = 0; i < syntonyList.Count; i++) |
| | | { |
| | | if (syntonyList[i].type == type) |
| | | { |
| | | index = i; |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public enum SyntonyType |
| | | { |
| | | PrayerRedpoint, |
| | | BossShow, |
| | | BossShowName, |
| | | BossShowDialogue, |
| | | BossShowSound, |
| | | FairyLeaugeStage, |
| | | VipExperirnceOverdue, |
| | | HeavenBattleState, |
| | | Realm, |
| | | RealmSit, |
| | | GuardHurtEffect, |
| | | GetFairyInfo, |
| | | Audio, |
| | | OSRedEnvelope, |
| | | } |
| | | } |
| | | using System;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using UnityEngine;
|
| | |
|
| | | public class TimeMgr : SingletonMonobehaviour<TimeMgr>
|
| | | {
|
| | | private Dictionary<Component, TimeItem> timeItems = new Dictionary<Component, TimeItem>();
|
| | | private List<TimeItem> timeItemList = new List<TimeItem>();
|
| | | private int m_LastRecordHour = -1;
|
| | | private int m_LastRecordMinute = -1;
|
| | | public int m_LastRecordDay = -1;
|
| | | public event Action OnDayEvent;
|
| | | public event Action OnHourEvent;
|
| | | public event Action OnMinuteEvent;
|
| | |
|
| | | private void LateUpdate()
|
| | | {
|
| | | try
|
| | | {
|
| | | if (m_LastRecordDay != TimeUtility.ServerNow.Day)
|
| | | {
|
| | | if (OnDayEvent != null)
|
| | | {
|
| | | OnDayEvent();
|
| | | }
|
| | | m_LastRecordDay = TimeUtility.ServerNow.Day;
|
| | | }
|
| | | if (m_LastRecordHour != TimeUtility.ServerNow.Hour)
|
| | | {
|
| | | if (OnHourEvent != null)
|
| | | {
|
| | | OnHourEvent();
|
| | | }
|
| | | m_LastRecordHour = TimeUtility.ServerNow.Hour;
|
| | | }
|
| | | if (m_LastRecordMinute != TimeUtility.ServerNow.Minute)
|
| | | {
|
| | | if (OnMinuteEvent != null)
|
| | | {
|
| | | OnMinuteEvent();
|
| | | }
|
| | | m_LastRecordMinute = TimeUtility.ServerNow.Minute;
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | DebugEx.Log(e.StackTrace);
|
| | | }
|
| | | for (int i = 0; i < syntonyList.Count; i++)
|
| | | {
|
| | | if ((TimeUtility.ServerNow - syntonyList[i].endTime).TotalSeconds > 0)
|
| | | {
|
| | | if (syntonyList[i].callback != null)
|
| | | {
|
| | | syntonyList[i].callback();
|
| | | }
|
| | | var _type = syntonyList[i].type;
|
| | | syntonyList.RemoveAt(i);
|
| | | if (OnSyntonyEvent != null)
|
| | | {
|
| | | OnSyntonyEvent(_type);
|
| | | }
|
| | | i--;
|
| | | }
|
| | | }
|
| | | if (timeItems.Count > 0)
|
| | | {
|
| | | timeItemList.RemoveRange(0, timeItemList.Count);
|
| | | foreach (Component item in timeItems.Keys)
|
| | | {
|
| | | if (item == null) continue;
|
| | | timeItemList.Add(timeItems[item]);
|
| | | }
|
| | | for (int i = 0; i < timeItemList.Count; i++)
|
| | | {
|
| | | timeItemList[i].Update();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void Register(Component comp, Action<Component> func, float t, int loopCnt = 1)
|
| | | {
|
| | | if (comp == null) return;
|
| | | if (!timeItems.ContainsKey(comp))
|
| | | {
|
| | | TimeItem item = new TimeItem(t, comp, loopCnt, func);
|
| | | timeItems.Add(comp, item);
|
| | | }
|
| | | }
|
| | |
|
| | | public void SetInterval(Component comp, float t)
|
| | | {
|
| | | if (timeItems.ContainsKey(comp))
|
| | | {
|
| | | TimeItem item = timeItems[comp];
|
| | | item.time = t;
|
| | | }
|
| | | }
|
| | |
|
| | | public void UnRegister(Component comp)
|
| | | {
|
| | | if (comp == null) return;
|
| | | if (timeItems.ContainsKey(comp))
|
| | | {
|
| | | TimeItem item = timeItems[comp];
|
| | | timeItems.Remove(comp);
|
| | | item = null;
|
| | | }
|
| | | }
|
| | |
|
| | | public void Register(SyntonyType type, float _totalTime, Action _func = null)
|
| | | {
|
| | | int index;
|
| | | if (ContainsSyntony(type, out index))
|
| | | {
|
| | | syntonyList[index].SetTime(_totalTime, _func);
|
| | | }
|
| | | else
|
| | | {
|
| | | Syntony syntony = new Syntony();
|
| | | syntony.type = type;
|
| | | syntony.SetTime(_totalTime, _func);
|
| | | syntonyList.Add(syntony);
|
| | | }
|
| | | }
|
| | |
|
| | | public void UnRegister(SyntonyType type)
|
| | | {
|
| | | int index;
|
| | | if (ContainsSyntony(type, out index))
|
| | | {
|
| | | syntonyList.RemoveAt(index);
|
| | | }
|
| | | }
|
| | |
|
| | | public struct Syntony
|
| | | {
|
| | | public SyntonyType type;
|
| | | public DateTime endTime { get; private set; }
|
| | | public Action callback;
|
| | | public void SetTime(float _totalTime, Action _func = null)
|
| | | {
|
| | | endTime = TimeUtility.ServerNow.AddSeconds(_totalTime);
|
| | | callback = _func;
|
| | | DebugEx.LogFormat("{0}{1}", type, endTime);
|
| | | }
|
| | | }
|
| | |
|
| | | private List<Syntony> syntonyList = new List<Syntony>();
|
| | |
|
| | | public event Action<SyntonyType> OnSyntonyEvent;
|
| | |
|
| | | private bool ContainsSyntony(SyntonyType type, out int index)
|
| | | {
|
| | | index = 0;
|
| | | for (int i = 0; i < syntonyList.Count; i++)
|
| | | {
|
| | | if (syntonyList[i].type == type)
|
| | | {
|
| | | index = i;
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public enum SyntonyType
|
| | | {
|
| | | PrayerRedpoint,
|
| | | BossShow,
|
| | | BossShowName,
|
| | | BossShowDialogue,
|
| | | BossShowSound,
|
| | | FairyLeaugeStage,
|
| | | VipExperirnceOverdue,
|
| | | HeavenBattleState,
|
| | | Realm,
|
| | | RealmSit,
|
| | | GuardHurtEffect,
|
| | | GetFairyInfo,
|
| | | Audio,
|
| | | OSRedEnvelope,
|
| | | }
|
| | | }
|