Пример #1
0
        /// <summary>
        /// Processes a single event listener phases
        /// </summary>
        /// <param name="adapter">Component descriptor referencing event handlers</param>
        /// <param name="component">Component dispatching events</param>
        /// <param name="mapping">Event mapping</param>
        /// <param name="enabled">Enabled state</param>
        public static void ProcessPhases(ComponentAdapter adapter, Components.Component component, EventMapping mapping, bool enabled)
        {
            if (null == component && null == adapter.Component)  // not instantiated (edit mode) and no component supplied
            {
                return;
            }

            Component script = adapter.GetComponent(mapping.ScriptName);

            if (null == script)
            {
                Debug.LogWarning("Component " + mapping.ScriptName + " not found on " + adapter.gameObject);
                return;
            }

            Type         type       = script.GetType();
            MethodInfo   methodInfo = type.GetMethod(mapping.MethodName, AllInstanceMethodsBindingFlags, null, TypeOfEvent, Modifiers); //type.GetMethod(mapping.MethodName, TypeOfEvent);
            EventHandler handler    = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), script, methodInfo);

            var cmp = component ?? adapter.Component;

            /**
             * 1. Remove all phases
             * */
            cmp.RemoveEventListener(mapping.EventType, handler, EventPhase.Capture | EventPhase.Target | EventPhase.Bubbling);

            /**
             * 2. If enabled, subscribe again
             * */
            if (enabled)
            {
                cmp.AddEventListener(mapping.EventType, handler, mapping.Phase);
            }
        }
Пример #2
0
        public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.AddEventListener(eventType, handler, phases);

            _touchCount++;
            SystemManager.Instance.TouchSignal.Connect(TouchSlot);
        }
Пример #3
0
        public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.RemoveEventListener(eventType, handler, phases);

            _touchCount--;
            if (_touchCount <= 0)
            {
                SystemManager.Instance.TouchSignal.Disconnect(TouchSlot);
            }
        }
Пример #4
0
 /// <summary>
 /// Overriding the MAIN RemoveEventListener method!
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
 {
     if (eventType == "propertyChange")
     {
         if (!HasEventListener(eventType))
         {
             TileLayout.RemoveEventListener(eventType, RedispatchHandler);
         }
     }
     base.RemoveEventListener(eventType, handler, phases);
 }
Пример #5
0
 /// <summary>
 /// Overriding the MAIN AddEventListener method!
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 /// <param name="priority"></param>
 public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases, int priority)
 {
     if (eventType == "propertyChange")
     {
         if (!HasEventListener(eventType))
         {
             TileLayout.AddEventListener(eventType, RedispatchHandler, phases, priority);
         }
     }
     base.AddEventListener(eventType, handler);
 }
Пример #6
0
        public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            if (MouseEvent.ROLL_OVER == eventType)
            {
                MouseEventDispatcher.Instance.UnregisterRollOverComponent(this);
            }
            else if (MouseEvent.ROLL_OUT == eventType)
            {
                MouseEventDispatcher.Instance.UnregisterRollOverComponent(this);
            }

            base.RemoveEventListener(eventType, handler, phases);
        }
Пример #7
0
        /// <summary>
        /// Processes a single event listener
        /// </summary>
        /// <param name="adapter">Component descriptor referencing event handlers</param>
        /// <param name="component">Component dispatching events</param>
        /// <param name="mapping">Event mapping</param>
        /// <param name="enabled">Enabled state</param>
        public static void ProcessListener(ComponentAdapter adapter, Components.Component component, EventMapping mapping, bool enabled)
        {
            if (null == component && (null == adapter || null == adapter.Component)) // not instantiated (edit mode) and no component supplied
            {
                return;                                                              // "null == adapter" check added 20130218 because having problems with prefabs
            }
            //Debug.Log("mapping.ScriptName: " + mapping.ScriptName);
            //Debug.Log("mapping: " + mapping);
            Component script = adapter.GetComponent(mapping.ScriptName);

            if (null == script)
            {
                Debug.LogWarning("Script " + mapping.ScriptName + " not found on " + adapter.gameObject, adapter.gameObject);
                return;
            }

            Type type = script.GetType();
            //Debug.Log("script: " + type);
            //Debug.Log("mapping.MethodName: " + mapping.MethodName);
            MethodInfo methodInfo = type.GetMethod(mapping.MethodName, AllInstanceMethodsBindingFlags, null, TypeOfEvent, Modifiers); //type.GetMethod(mapping.MethodName, TypeOfEvent);

            if (null == methodInfo)
            {
                Debug.LogWarning(string.Format("Method [{0}] not found in script [{1}]", mapping.MethodName, mapping.ScriptName), adapter);
                return;
            }

            //Debug.Log("method: " + methodInfo);
            EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), script, methodInfo);
            //Debug.Log("handler: " + handler);

            var cmp = component ?? adapter.Component;

            if (enabled)
            {
                //Debug.Log("Wiring [" + mapping.EventType + "] event to [" + handler + "] handler on " + componentDescriptor);
                cmp.AddEventListener(mapping.EventType, handler, mapping.Phase);
            }
            else
            {
                cmp.RemoveEventListener(mapping.EventType, handler, mapping.Phase);
            }
        }
Пример #8
0
        public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.RemoveEventListener(eventType, handler, phases);

            _touchCount--;
            if (_touchCount <= 0)
            {
                SystemManager.Instance.TouchSignal.Disconnect(TouchSlot);
            }
        }
Пример #9
0
 /// <summary>
 /// Removes an event listener
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 public void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
 {
     Stage.RemoveEventListener(eventType, handler, phases);
 }
Пример #10
0
 /// <summary>
 /// Removes an event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler (function)</param>
 public void RemoveEventListener(string eventType, EventHandler handler)
 {
     Stage.RemoveEventListener(eventType, handler);
 }
Пример #11
0
 /// <summary>
 /// Adds the event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler</param>
 /// <param name="phases">Event bubbling phases that we listen to</param>
 /// <param name="priority">Event priority</param>
 public void AddEventListener(string eventType, EventHandler handler, EventPhase phases, int priority)
 {
     Stage.AddEventListener(eventType, handler, phases, priority);
 }
Пример #12
0
 /// <summary>
 /// Adds event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler (function)</param>
 public void AddEventListener(string eventType, EventHandler handler)
 {
     Stage.AddEventListener(eventType, handler);
 }
Пример #13
0
 /// <summary>
 /// Removes an event listener
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 public void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
 {
     Stage.RemoveEventListener(eventType, handler, phases);
 }
Пример #14
0
 /// <summary>
 /// Removes an event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler (function)</param>
 public void RemoveEventListener(string eventType, EventHandler handler)
 {
     Stage.RemoveEventListener(eventType, handler);
 }
Пример #15
0
 /// <summary>
 /// Adds the event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler</param>
 /// <param name="phases">Event bubbling phases that we listen to</param>
 /// <param name="priority">Event priority</param>
 public void AddEventListener(string eventType, EventHandler handler, EventPhase phases, int priority)
 {
     Stage.AddEventListener(eventType, handler, phases, priority);
 }
Пример #16
0
 /// <summary>
 /// Overriding the MAIN RemoveEventListener method!
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
 {
     if (eventType == "propertyChange")
     {
         if (!HasEventListener(eventType))
             TileLayout.RemoveEventListener(eventType, RedispatchHandler);
     }
     base.RemoveEventListener(eventType, handler, phases);
 }
Пример #17
0
 public override void RemoveEventListener(string eventType, EventHandler handler)
 {
     // listening for Target and Bubbling phases by default
     base.RemoveEventListener(eventType, handler, EventPhase.Target | EventPhase.Bubbling);
 }
Пример #18
0
        public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.AddEventListener(eventType, handler, phases);

            _touchCount++;
            SystemManager.Instance.TouchSignal.Connect(TouchSlot);
        }
Пример #19
0
 public override void RemoveEventListener(string eventType, EventHandler handler)
 {
     // listening for Target and Bubbling phases by default
     base.RemoveEventListener(eventType, handler, EventPhase.Target | EventPhase.Bubbling);
 }
Пример #20
0
 public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
 {
     if (MouseEvent.ROLL_OVER == eventType)
     {
         MouseEventDispatcher.Instance.UnregisterRollOverComponent(this);
     }
     else if (MouseEvent.ROLL_OUT == eventType)
     {
         MouseEventDispatcher.Instance.UnregisterRollOverComponent(this);
     }
     
     base.RemoveEventListener(eventType, handler, phases);
 }
Пример #21
0
 /// <summary>
 /// Adds event listener
 /// </summary>
 /// <param name="eventType">Event type</param>
 /// <param name="handler">Event handler (function)</param>
 public void AddEventListener(string eventType, EventHandler handler)
 {
     Stage.AddEventListener(eventType, handler);
 }
Пример #22
0
 /// <summary>
 /// Overriding the MAIN AddEventListener method!
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="handler"></param>
 /// <param name="phases"></param>
 /// <param name="priority"></param>
 public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases, int priority)
 {
     if (eventType == "propertyChange")
     {
         if (!HasEventListener(eventType))
             TileLayout.AddEventListener(eventType, RedispatchHandler, phases, priority);
     }
     base.AddEventListener(eventType, handler);
 }