public void PostEvent(string evtName, GameObject obj = null) { EventDelegate value; try { GPEventID evtID = EventNameToID(evtName); if (evtID == GPEventID.Invalid) { throw new KeyNotFoundException(); } if (m_eventMap.TryGetValue(evtID.ID, out value)) { GPEvent evt = new GPEvent(); evt.EventID = evtID; evt.RelatedObject = obj; value(evt); } else { throw new KeyNotFoundException(); } } catch (KeyNotFoundException) { } }
public bool Equals(GPEventID p) { if (p == null) { return false; } return (ID == p.ID); }
private void EventTrigger(GPEventID id, GameObject relatedObj = null) { GPEvent evt = new GPEvent(); evt.EventID = id; evt.RelatedObject = relatedObj; this.EventTrigger(evt); }
public int IndexOfEventID(GPEventID id) { if (m_isEventIDMapDirty) { CreateEventIDMap(); } return(m_eventIDList.IndexOf(id)); }
public void CheckNames(GPEventID id) { Debug.Log("Map matching: " + (m_eventIDMap.Dictionary [id.Name].ID == id.ID)); foreach (GPEventID eventId in m_eventIDList) { if (eventId.ID == id.ID) { Debug.Log("List matching: " + (eventId.Name == id.Name)); break; } } }
public override bool Equals(System.Object obj) { if (obj == null) { return false; } GPEventID p = obj as GPEventID; if ((System.Object)p == null) { return false; } return (ID == p.ID); }
public void Unregister(string evtName, EventDelegate del) { try { GPEventID evtID = EventNameToID(evtName); if (evtID == GPEventID.Invalid) { throw new KeyNotFoundException(); } Unregister(evtID.ID, del); } catch (KeyNotFoundException) { } }
public void Register(string evtName, EventDelegate del) { try { GPEventID evtID = EventNameToID(evtName); if (evtID.Equals(GPEventID.Invalid)) { throw new KeyNotFoundException(); } Register(evtID.ID, del); } catch (KeyNotFoundException) { Debug.LogError("Can not register for event " + evtName); } }
public void PostRelativeEvent(GameObject postToObj, string evtName, GameObject obj = null) { if (postToObj == null) { throw new NullReferenceException(); } EventDelegate value; try { GPEventID evtID = EventNameToID(evtName); if (evtID == GPEventID.Invalid) { throw new IndexOutOfRangeException(); } EventHandler handlerToTrigger = null; EventHandler[] handlers = postToObj.GetComponents <EventHandler>(); foreach (EventHandler handler in handlers) { if (handler._eventID.Equals(evtID)) { if (handlerToTrigger == null) { handlerToTrigger = handler; } else { Debug.LogError("Several handler listening to " + evtID.Name + " found in object " + postToObj.name + ". Only the first handler will be triggered"); } } } if (handlerToTrigger == null) { Debug.LogWarning("Can not post relative event to " + postToObj.name + ". No event handler listening to " + evtID.Name + " found in object."); return; } if (m_eventMap.TryGetValue(evtID.ID, out value)) { GPEvent evt = new GPEvent(); evt.EventID = evtID; evt.RelatedObject = obj; handlerToTrigger.EventTrigger(evt); } else { throw new KeyNotFoundException(); } } catch (System.Exception e) { Debug.Log("Exception: " + e.Message + " Stack " + e.StackTrace); } }
public void RemoveEventName(GPEventID id) { m_eventIDList.Remove(id); m_isEventIDMapDirty = true; }