public void AddNewListener(GameEvent newEvent) { GameEventListener listener = this.gameObject.AddComponent(typeof(GameEventListener)) as GameEventListener; listener.ReplaceEvent(newEvent); AllEvents.Add(newEvent.name, listener); }
// method creates a new GameEventListener component, creates a new event for it, sets its name public void AddNewEventAndListener(string eventName) { GameEventListener listener = this.gameObject.AddComponent(typeof(GameEventListener)) as GameEventListener; GameEvent newEvent = ScriptableObject.CreateInstance(typeof(GameEvent)) as GameEvent; newEvent.name = eventName; listener.ReplaceEvent(newEvent); AllEvents.Add(eventName, listener); }