/// <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);
            }
        }
Beispiel #2
0
        public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.AddEventListener(eventType, handler, phases);

            _touchCount++;
            SystemManager.Instance.TouchSignal.Connect(TouchSlot);
        }
Beispiel #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);
            }
        }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
        }
        /// <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);
            }
        }
        public override void RemoveEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.RemoveEventListener(eventType, handler, phases);

            _touchCount--;
            if (_touchCount <= 0)
            {
                SystemManager.Instance.TouchSignal.Disconnect(TouchSlot);
            }
        }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
        public override void AddEventListener(string eventType, EventHandler handler, EventPhase phases)
        {
            base.AddEventListener(eventType, handler, phases);

            _touchCount++;
            SystemManager.Instance.TouchSignal.Connect(TouchSlot);
        }
 public override void RemoveEventListener(string eventType, EventHandler handler)
 {
     // listening for Target and Bubbling phases by default
     base.RemoveEventListener(eventType, handler, EventPhase.Target | EventPhase.Bubbling);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }