public bool DetachListener(int eventKey, DGameEventHandle eventHandle) { if (!mListenerTable.ContainsKey(eventKey)) { return(false); } List <CEventData> listenerList = mListenerTable[eventKey]; CEventData find = null; foreach (CEventData evtData in listenerList) { if (evtData.mHandle == eventHandle) { find = evtData; break; } } if (find != null) { listenerList.Remove(find); } return(true); }
/// <summary> /// 为避免回调时被调方是一个已经被删除的GameObj上的组件,造成异常,组件需要使用此函数注册 /// </summary> /// <param name="eventkey"></param> /// <param name="eventHandle"></param> /// <param name="gameObj"></param> /// <returns></returns> public bool AddListener(int eventkey, DGameEventHandle eventHandle, GameObject gameObj) { if (eventHandle == null) { return(false); } if (!mListenerTable.ContainsKey(eventkey)) { mListenerTable.Add(eventkey, new List <CEventData>()); } List <CEventData> listenerList = mListenerTable[eventkey]; listenerList.Add(new CEventData(eventHandle, gameObj)); return(true); }
//public bool AddNetListener(RockProtocol.MsgID msgID, DGameEventHandle eventHandle) //{ // return AddListener(GetNetMsgIdEventKey(msgID), eventHandle); //} //static public int GetNetMsgIdEventKey(RockProtocol.MsgID msgID) //{ // return (int)msgID; //} public bool RemoveListener(ESysEvent eventkey, DGameEventHandle eventHandle) { if (!mListenerTable.ContainsKey(eventkey)) { return(false); } List <CEventData> listenerList = mListenerTable[eventkey]; for (int i = 0; i < listenerList.Count; ++i) { if (eventHandle == listenerList[i].mHandle) { listenerList.Remove(listenerList[i]); return(true); } } return(false); }
public bool DetachListener(int eventKey, DGameEventHandle eventHandle) { if (!mListenerTable.ContainsKey(eventKey)) { return(false); } List <CEventData> listenerList = mListenerTable[eventKey]; CEventData find = null; for (int i = 0; i < listenerList.Count; ++i) { if (listenerList[i].mHandle == eventHandle) { find = listenerList[i]; break; } } if (find != null) { listenerList.Remove(find); } return(true); }
public SEventData(int eventKey, DGameEventHandle eventHandle) { this.eventKey = eventKey; this.eventHandle = eventHandle; }
public CEventData(DGameEventHandle handle, GameObject gameObj) { mObjRelate = true; mHandle = handle; mGameObj = gameObj; }
public CEventData(DGameEventHandle handle) { mObjRelate = false; mHandle = handle; mGameObj = null; }