예제 #1
0
 /// <summary>
 /// Invoke from OnDestroy() method in your per level game object.
 /// Uses the hash code to identify the listener over the list of many listeners.
 /// </summary>
 public void removeListener(ITouchListener listener)
 {
             #if TOUCH_EVENT_MANAGER_NO_QUADTREE
     dynamicListeners.remove(listener);
             #else
     if (!listener.isScreenStatic())
     {
         dynamicListeners.remove(listener);
     }
     else
     {
         // need to remove from every list the listener appears
         ListenerLists[] lls = staticQuadTree.traverse(listener.getScreenBoundsAA());
         for (int i = 0, c = lls.Length; i < c; ++i)
         {
             // first listenerList element being not valid means next ones are also invalid
             if (lls[i] == null)
             {
                 break;
             }
             lls[i].remove(listener);
         }
     }
             #endif
 }
예제 #2
0
 /// <summary>
 /// Register the specified iListener in the adequate list to be processed on every touch event.
 /// </summary>
 /// <param name='listener'>
 /// The object you are registering. Needed for callback invocations.
 /// </param>
 /// <param name='touchPhases'>
 /// All the touch phases you want your gameobject be registered to.
 /// </param>
 public void register(ITouchListener listener, params TouchPhase[] touchPhases)
 {
             #if TOUCH_EVENT_MANAGER_NO_QUADTREE
     for (int i = 0, c = touchPhases.Length; i < c; ++i)
     {
         dynamicListeners.add(listener, touchPhases[i]);
     }
             #else
     if (!listener.isScreenStatic())
     {
         for (int i = 0, c = touchPhases.Length; i < c; ++i)
         {
             dynamicListeners.add(listener, touchPhases[i]);
         }
     }
     else
     {
         /// adding the listener's screen rect into the quad tree will return a list of
         /// as much as 4 ListenerLists elems, since the listener can fall in more than one quadrant
         Rect            screenBounds = listener.getScreenBoundsAA();
         ListenerLists[] leaves       = staticQuadTree.add(screenBounds);
         for (int i = 0, c = leaves.Length; i < c; ++i)
         {
             // first listenerList element being not valid means next ones are also invalid
             if (leaves[i] == null)
             {
                 break;
             }
             for (int j = 0, d = touchPhases.Length; j < d; ++j)
             {
                 leaves[i].add(listener, touchPhases[j]);
             }
         }
     }
             #endif
 }