Beispiel #1
0
        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;
        }
Beispiel #2
0
        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;
            }
        }