public virtual void SetEventListener(string eventName, FunctionInstance fun) { var eventType = EventHandlerMap.GetEventType(eventName); if (eventType == null) { throw new System.Exception($"Unknown event name specified, '{eventName}'"); } // Remove var handler = GameObject.GetComponent(eventType) as IEventHandler; handler?.ClearListeners(); // No event to add if (fun == null) { return; } if (handler == null) { handler = GameObject.AddComponent(eventType) as IEventHandler; } System.Action <BaseEventData> callAction = (e) => fun.Invoke(JsValue.FromObject(Context.Engine, e)); handler.OnEvent += callAction; }
public override void SetEventListener(string eventName, FunctionInstance callback) { switch (eventName) { case "onClick": Button.onClick.RemoveAllListeners(); if (callback != null) { Button.onClick.AddListener(new UnityAction(() => callback.Invoke())); } return; default: base.SetEventListener(eventName, callback); return; } }