public void RegisterEventHook(string eventName, Func <List <string>, IEnumerator> eventFunction) { GameEventHook newHook = new GameEventHook { Name = eventName, Function = eventFunction }; _eventFunctions.Add(newHook); DebugMessage("Registered event '" + eventName + "'."); }
public IEnumerator ExecuteGameEvent(GameEvent gameEvent) { DebugMessage("Controller is executing game event: " + gameEvent.Event + "..."); string eventName = gameEvent.Event; List <string> eventArgs = gameEvent.EventArgs; // Find the first coroutine on the child behaviors with a name that matches the event name. GameEventHook coroutine = _eventFunctions.FirstOrDefault(f => f.Name == eventName); if (coroutine == default(GameEventHook)) { Debug.LogError("Could not find an event named " + eventName + " in the registered event list."); yield break; } DebugMessage(eventName + " is registered! Doing it."); yield return(StartCoroutine(coroutine.Function(eventArgs))); }