public void RegistersEvent(EventDefine eventName , EventHandler handler , object sender = null ) { if ( eventDict.ContainsKey(eventName) ) { Dictionary<EventHandler,EventClass> ecDict; eventDict.TryGetValue(eventName, out ecDict); if ( ecDict == null ) { Debug.LogError("No event class list found in " + eventName.ToString() +"'s dictionary"); }else { if ( ecDict.ContainsKey(handler) ) { Debug.LogError("Mutiply define of handler" + eventName.ToString()); }else { ecDict.Add(handler, new EventClass(eventName,handler,sender)); } } } else { var ecDict = new Dictionary<EventHandler,EventClass>(); ecDict.Add(handler, new EventClass(eventName,handler,sender)); eventDict.Add(eventName, ecDict); } }
void EnterStayAway(EventDefine eventName, object sender , EventArgs args ) { GameObject obj = sender as GameObject; parItem.SetActive(false); parPers.SetActive(false); if ( obj.GetComponent<Person>() != null ) parPers.SetActive(true); if ( obj.GetComponent<Item>() != null ) parItem.SetActive(true); }
public bool ContainClockEvent(EventDefine eventName) { for( int i = 0; i < m_ClockEvents.Count; i++ ) { if( m_ClockEvents[i].m_Name == eventName ) return true; } return false; }
void OnTokenInit(EventDefine eventName, object sender, EventArgs args) { foreach( GuideInfo gInfo in guideInfoList ) { string movieName = ((MessageEventArgs)args).GetMessage("name"); if ( gInfo.movieName.Equals( movieName )) { StartGuide( gInfo ); } } }
void LevelAfter(EventDefine eventName, object sender , EventArgs args ) { if ( LogicManager.Instance.tempLevel.level.Equals(level)) { parItem.SetActive(false); parPers.SetActive(false); StartCoroutine(fadeTo(1f)); }else { StartCoroutine( fadeTo( 0 )); } }
//no parameters public static void Broadcast(EventDefine eventType) { Delegate d; if (m_EventTable.TryGetValue(eventType, out d)) { CallBack callBack = d as CallBack; if (callBack != null) { callBack(); } else { throw new Exception(string.Format("Erro in broadcasting: event {0} has a different delegate type.", eventType)); } } }
//five parameters public static void Broadcast <T, X, Y, Z, W>(EventDefine EventDefine, T arg1, X arg2, Y arg3, Z arg4, W arg5) { Delegate d; if (m_EventTable.TryGetValue(EventDefine, out d)) { CallBack <T, X, Y, Z, W> callBack = d as CallBack <T, X, Y, Z, W>; if (callBack != null) { callBack(arg1, arg2, arg3, arg4, arg5); } else { throw new Exception(string.Format("广播事件错误:事件{0}对应委托具有不同的类型", EventDefine)); } } }
//single parameters public static void Broadcast <T>(EventDefine EventDefine, T arg) { Delegate d; if (m_EventTable.TryGetValue(EventDefine, out d)) { CallBack <T> callBack = d as CallBack <T>; if (callBack != null) { callBack(arg); } else { throw new Exception(string.Format("广播事件错误:事件{0}对应委托具有不同的类型", EventDefine)); } } }
/// <summary> /// 广播监听,两个参数 /// </summary> /// <param name="eventType"></param> public static void Broadcast <T, X, Y>(EventDefine eventType, T arg1, X arg2, Y arg3) { Delegate d; if (m_EventTable.TryGetValue(eventType, out d)) { CallBack <T, X, Y> callBack = d as CallBack <T, X, Y>; if (callBack != null) { callBack(arg1, arg2, arg3); } else { throw new Exception(string.Format("广播事件错误,事件{0}对应委托具有不同的类型", eventType)); } } }
/// <summary> /// 广播监听,没有参数 /// </summary> /// <param name="eventType"></param> public static void Broadcast(EventDefine eventType) { Delegate d; if (m_EventTable.TryGetValue(eventType, out d)) { CallBack callBack = d as CallBack; if (callBack != null) { callBack(); } else { throw new Exception(string.Format("广播事件错误,事件{0}对应委托具有不同的类型", eventType)); } } }
public long GetTimer(EventDefine eventName) { for (int i = 0; i < m_ClockEvents.Count; i++) { if (m_ClockEvents[i].m_Name == eventName) { DateTime clockEnd = new DateTime(m_ClockEvents[i].m_LastUpdateTime + m_ClockEvents[i].m_TimeSpan * Global.SECOND_TO_TICKS); DateTime currentDate = DateTime.Now; long elapsedTicks = clockEnd.Ticks - currentDate.Ticks; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); return(Convert.ToInt64(elapsedSpan.TotalSeconds)); } } return(0); }
/** * Register an event handler to listen to events of type /eventName/, * from the given sender only. */ public void RegisterEvent(EventDefine eventName, EventHandler handler, object sender, int priority = 1) { m_AddEvents.Add(new EventClass(eventName, sender, handler, priority)); if (!priorityList.Contains(priority)) { priorityList.Add(priority); priorityList.Sort(); priorityList.Reverse(); } /* * Dictionary<object, List<EventHandler>> handlers = m_EventDictionary[eventName]; * if (!handlers.ContainsKey(sender)) * handlers[sender] = new List<EventHandler>(); * handlers[sender].Add(handler); */ }
private static void OnListenerRemoving(EventDefine eventType, Delegate callBack) { if (m_EventTable.ContainsKey(eventType)) { Delegate d = m_EventTable[eventType]; if (d == null) { throw new Exception(string.Format("RemoveListener Error:there is no commision for Event(1)", eventType)); } else if (d.GetType() != callBack.GetType()) { throw new Exception(string.Format("RemoveListener Error:try to remove different commision from Event(0), current commision is 1, want to remove commision 2.", eventType, d.GetType(), callBack.GetType())); } } else { throw new Exception(string.Format("RemoveListener Error:there is no such event", eventType)); } }
private static void OnListenerRemoving(EventDefine eventType, Delegate callBack) { if (m_EventTable.ContainsKey(eventType)) { Delegate d = m_EventTable[eventType]; if (d == null) { throw new Exception(string.Format("移除监听错误:事件{0}没有对应的委托", eventType)); } else if (d.GetType() != callBack.GetType()) { throw new Exception(string.Format("移除监听错误:尝试为事件{0}移除不同类型的委托,当前委托类型为{1},要移除的委托类型为{2}", eventType, d.GetType(), callBack.GetType())); } } else { throw new Exception(string.Format("移除监听错误:没有事件码{0}", eventType)); } }
private static void OnListenerRemoving(EventDefine eventType, Delegate callBack) { if (m_EventTable.ContainsKey(eventType)) { Delegate d = m_EventTable[eventType]; if (d == null) { throw new Exception(string.Format("Erro in removing listener: delegate in current event not found.", eventType)); } else if (d.GetType() != callBack.GetType()) { throw new Exception(string.Format("Erro in removing listener:Removing a different delegate for event {0}. Delegate type for the even is {1}. Delegate type to be removed is {2}.", eventType, d.GetType(), callBack.GetType())); } } else { throw new Exception(string.Format("Erro in removing listener:Event {0} not exist", eventType)); } }
private void OnBattleCardClicked(EventDefine type, System.Object[] args) { if (args.Length < 0 || args[0] != m_BattleCard.BattleCardObj) { return; } if (m_BattleCard.GetCardState() != CardStateType.E_CARD_STATE_WAITING) { return; } if (!m_BattleCard.IsDead) { return; } BoxManager.showMessageByID((int)MessageIdEnum.Msg135, Obj_MyselfPlayer.GetMe().money.ToString(), ((Obj_MyselfPlayer.GetMe().reviveCount + 1) * 1000).ToString()); UIEventListener.Get(BoxManager.buttonYes).onClick += ReviveComfirmHandler; }
public Boolean UnRegisterEventHandler(EventDefine type, EventHandler handler) { if (handler == null) { return(false); } if (!m_EventHandlerList.ContainsKey(type)) { return(false); } ArrayList handlerList = m_EventHandlerList[type]; if (!handlerList.Contains(handler)) { return(false); } handlerList.Remove(handler); return(true); }
public void UnregistersEvent(EventDefine eventName , EventHandler handler) { if ( eventDict.ContainsKey(eventName)) { Dictionary<EventHandler,EventClass> ecDict; eventDict.TryGetValue(eventName, out ecDict); if ( ecDict == null ) { Debug.LogError("no event class list found in " + eventName.ToString() +"'s list"); }else { if ( !ecDict.ContainsKey(handler) ) { // Debug.LogError("No define of handler" + eventName.ToString()); }else { ecDict.Remove(handler); } } } }
private void OnForwardBtn(EventDefine type, System.Object[] args) { if (GetBattleStateType() != BattleProcedureType.E_BATTLE_PROCEDURE_WAITING) { return; } if (Time.realtimeSinceStartup - m_ForwardBtnPressCounter < 3f / Time.timeScale) { return; } m_ForwardBtnPressCounter = Time.realtimeSinceStartup; //王明磊 : 统计模块代码 -> Statistics //如果是Guide阶段,需要统计此按钮的点击信息 if (GameManager.Instance.isGuideMode()) { switch (m_RoundCounter) { case 1: PlayerPrefsX.StatisticsIncrease("Btn" + ((int)StatisticsEnum.Btn20).ToString()); break; case 2: PlayerPrefsX.StatisticsIncrease("Btn" + ((int)StatisticsEnum.Btn21).ToString()); break; } } BattleCardManager.Instance.UpdateCardState(); if (Obj_MyselfPlayer.GetMe().battleType == BattleType.PVE) { NetworkSender.Instance().AskBattleData(OnAskContinueBattleRet, m_RoundCounter + 1, Obj_MyselfPlayer.GetMe().curSubcopy.subCopyID); } else if (Obj_MyselfPlayer.GetMe().battleType == BattleType.CHONG_LOU) { NetworkSender.Instance().AskChonglouBattleData(OnAskContinuePataBattleRet); } }
public void UnregistersEvent(EventDefine eventName, EventHandler handler) { if (eventDict.ContainsKey(eventName)) { Dictionary <EventHandler, EventClass> ecDict; eventDict.TryGetValue(eventName, out ecDict); if (ecDict == null) { Debug.LogError("no event class list found in " + eventName.ToString() + "'s list"); } else { if (!ecDict.ContainsKey(handler)) { Debug.LogError("No define of handler" + eventName.ToString()); } else { ecDict.Remove(handler); } } } }
void Update() { foreach (EventInvocation eventInv in postEventList) { EventDefine tempEventName = eventInv.m_Name; foreach (EventHandler handler in eventDict[tempEventName].Keys) { EventClass eventClass = eventDict[tempEventName][handler]; Message msg = eventInv.m_message; if (eventInv.m_sender == null) { msg.SetSender(eventClass.m_sender); } else { msg.SetSender(eventInv.m_sender); } msg.SetEventName(eventClass.m_Name); handler(msg); } } postEventList.Clear(); }
/// <summary> /// 移除监听,三个参数 /// </summary> /// <param name="eventType"></param> /// <param name="callBack"></param> public static void RemoveListener <T, X, Y, Z>(EventDefine eventType, CallBack <T, X, Y, Z> callBack) { if (m_EventTable.ContainsKey(eventType)) { Delegate d = m_EventTable[eventType]; if (d == null) { throw new Exception(string.Format("移除监听错误:事件{0}没有对应的委托", eventType)); } else if (d.GetType() != callBack.GetType()) { throw new Exception(string.Format("移除监听错误:尝试为事件{0}移除不同类型的委托,当前委托类型为{1},要移除的委托类型为{2}", eventType, d.GetType(), callBack.GetType())); } } else { throw new Exception(string.Format("移除监听错误,没有事件码{0}", eventType)); } m_EventTable[eventType] = (CallBack <T, X, Y, Z>)m_EventTable[eventType] - callBack; if (m_EventTable[eventType] == null) { m_EventTable.Remove(eventType); } }
void OnAllEnd(EventDefine eventName, object sender, EventArgs args) { isOcupied = false; }
public EventInvocation(EventDefine name, Message msg = null, object sender = null) { m_Name = name; m_message = msg; m_sender = sender; }
public void PostEvent(EventDefine eventName , Message msg = null , object sender=null) { if (msg == null ) msg = new Message(); postEventList.Add(new EventInvocation(eventName,msg, sender)); }
void ExitStayAway(EventDefine eventName, object sender, EventArgs args) { // parItem.SetActive(false); // parPers.SetActive(false); }
public void SetEventName(EventDefine name) { m_eventName = name; }
public void Fire(EventDefine type, System.Object arg0) { Fire(type, new System.Object[] { arg0 }); }
public void Fire(EventDefine type, System.Object[] args) { m_EventList.Add(new Event(type, args)); }
//five parameters public static void AddListener <T, X, Y, Z, W>(EventDefine eventType, CallBack <T, X, Y, Z, W> callBack) { OnListenerAdding(eventType, callBack); m_EventTable[eventType] = (CallBack <T, X, Y, Z, W>)m_EventTable[eventType] + callBack; }
public void PostEventSynchronously(EventDefine eventName, object sender) { PostEventSynchronously(eventName, sender, EventArgs.Empty); }
public void Fire(EventDefine type, object param1 = null, object param2 = null, object param3 = null, object param4 = null) { m_EventQueue.Enqueue(new Event(type, param1, param2, param3, param4)); }
/** * Register an event handler to listen to events of type /eventName/, * from the given sender only. */ public void RegisterClockEvent(EventDefine eventName, ClockEventHandler handler, long startTimeTicks, long timeSpanSeconds) { //when you regist a clock event it may has been elapse some timeSpan DateTime clockBegin = new DateTime(startTimeTicks); DateTime currentDate = DateTime.Now; long elapsedTicks = currentDate.Ticks - clockBegin.Ticks; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); long totalSeconds = Convert.ToInt64(elapsedSpan.TotalSeconds); // there is /count/ timeSpan between start time and now long count = totalSeconds / timeSpanSeconds; for( long i = 0; i < count ; i++ ) { handler(eventName); } // reset start time ticks to a reason value startTimeTicks += count * timeSpanSeconds * Global.SECOND_TO_TICKS; if( !ContainClockEvent(eventName)) { m_ClockEvents.Add(new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds)); } else { int index = GetClockEventIndex(eventName); m_ClockEvents[index] = new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds); } }
/** * Unregisters this event handler from all events of this type, regardless * of what it is listening for (all senders or specific senders). */ public void UnregisterEventAllSenders(EventDefine eventName, EventHandler handler) { foreach (object sender in m_EventDictionary[eventName].Keys) UnregisterEvent(eventName, handler, sender); }
/** * Calling this function stops this event handler from listening * to events from all senders--if it is registered to listen to specific * senders, it will still listen to those. See UnregisterEventAllSenders(). */ public void UnregisterEvent(EventDefine eventName, EventHandler handler, int priority = 1) { UnregisterEvent(eventName, handler, AllSenders, priority); }
/** * Call this to stop an event handler from listening to events * from a specific sender. */ public void UnregisterEvent(EventDefine eventName, EventHandler handler, object sender, int priority = 1) { if (sender is EventArgs) Debug.LogWarning("You posted an event with the sender being an EventArgs " + "object. It's probably wrong."); m_RemoveEvents.Add(new EventClass(eventName, sender, handler, priority)); }
public void UnregisterClockEvent(EventDefine eventName) { int index = -1; for( int i = 0; i < m_ClockEvents.Count; i++ ) { if( m_ClockEvents[i].m_Name == eventName ) { index = i; } } if( index > 0 ) m_ClockEvents.RemoveAt(index); }
/** * Post the given event right now, without waiting for Update(). * Be very careful about deadlocks. * * Note that this forces Update(). */ public void PostEventSynchronously(EventDefine eventName, object sender, EventArgs arg) { PostEvent(eventName, sender, arg); Update(); }
public void Fire(EventDefine type) { Fire(type, new System.Object[] { }); }
public int GetClockEventIndex(EventDefine eventName) { for( int i = 0; i < m_ClockEvents.Count; i++ ) { if( m_ClockEvents[i].m_Name == eventName ) return i; } return -1; }
public void Fire(EventDefine type, System.Object arg0, System.Object arg1, System.Object arg2) { Fire(type, new System.Object[] { arg0, arg1, arg2 }); }
public void NextLevelAfter(EventDefine eventName, object sender , EventArgs args ) { mainCharacter = null; StartCoroutine( setMainCharacterAfterSecond(LogicManager.Instance.levelChangeTime)); }
public Event(EventDefine type, System.Object[] args) { this.type = type; this.args = args; }
public void PostEvent(EventDefine eventName, object sender, EventArgs arg) { if (sender is EventArgs) Debug.LogWarning("You posted an event with the sender being an EventArgs " + "object. It's probably wrong."); m_WaitingEvents.Add(new EventInvocation(eventName, sender, arg)); }
// Post event to all sender public void PostEvent(EventDefine eventName) { PostEvent(eventName, AllSenders, EventArgs.Empty); }
public void PostEvent(EventDefine eventName, object sender) { PostEvent(eventName, sender, EventArgs.Empty); }
public EventClass(EventDefine name, EventHandler handler, object sender = null) { m_Name = name; m_Handler = handler; m_sender = sender; }
void ExitStayAway(EventDefine eventName, object sender , EventArgs args ) { // parItem.SetActive(false); // parPers.SetActive(false); }
public long GetTimer(EventDefine eventName) { for( int i = 0; i < m_ClockEvents.Count; i++ ) { if( m_ClockEvents[i].m_Name == eventName ) { DateTime clockEnd = new DateTime(m_ClockEvents[i].m_LastUpdateTime + m_ClockEvents[i].m_TimeSpan * Global.SECOND_TO_TICKS); DateTime currentDate = DateTime.Now; long elapsedTicks = clockEnd.Ticks - currentDate.Ticks; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); return Convert.ToInt64(elapsedSpan.TotalSeconds); } } return 0; }
// Post event to all sender with args public void PostEvent(EventDefine eventName, EventArgs arg) { PostEvent(eventName, AllSenders, arg); }
private void OnGameStart(EventDefine type, object param1 = null, object param2 = null, object param3 = null, object param4 = null) { Debug.Log(param1); }
//委托示例 private static void DelegateTest() { var eventA = new EventDefine(); eventA.MyEvent += new EventRespond().RespondAction; eventA.EventHappen(); Console.ReadKey(); }
public ClockEventClass(EventDefine name, ClockEventHandler handler, long startTime, long timeSpan) { m_Name = name; m_LastUpdateTime = startTime; m_TimeSpan = timeSpan; m_handler = handler; }
/** * Register an event handler to listen to events of type /eventName/, * from the given sender only. */ public void RegisterEvent(EventDefine eventName, EventHandler handler, object sender, int priority = 1) { m_AddEvents.Add(new EventClass(eventName, sender, handler, priority)); if( !priorityList.Contains(priority) ) { priorityList.Add(priority); priorityList.Sort(); priorityList.Reverse(); } /* Dictionary<object, List<EventHandler>> handlers = m_EventDictionary[eventName]; if (!handlers.ContainsKey(sender)) handlers[sender] = new List<EventHandler>(); handlers[sender].Add(handler); */ }
//five parameters public static void RemoveListener <T, X, Y, Z, W>(EventDefine eventType, CallBack <T, X, Y, Z, W> callBack) { OnListenerRemoving(eventType, callBack); m_EventTable[eventType] = (CallBack <T, X, Y, Z, W>)m_EventTable[eventType] - callBack; OnListenerRemoved(eventType); }
public ClockEventClass(ClockEventClass copy) { m_Name = copy.m_Name; m_LastUpdateTime = copy.m_LastUpdateTime; m_TimeSpan = copy.m_TimeSpan; m_handler = copy.m_handler; }
//no parameters public static void AddListener(EventDefine eventType, CallBack callBack) { OnListenerAdding(eventType, callBack); m_EventTable[eventType] = (CallBack)m_EventTable[eventType] + callBack; }
public EventClass(EventDefine name, object sender, EventHandler handler, int priority = 1) { m_Name = name; m_Sender = sender; m_handler = new PriorityEventHandler(handler, priority); }
protected void ExitStayAway(EventDefine eventName, object sender, EventArgs args) { stayAway = null; }
public EventInvocation(EventDefine name, object sender, EventArgs args) { m_Name = name; m_Sender = sender; m_Args = args; }