예제 #1
0
    private bool sendEvent(Touch tch, ListenerLists ll)
    {
        if (ll == null)
        {
            return(false);
        }

        // NOTE: traverse the arrays and ask if something hitten in the correct order:
        //    Began, Stationary/Move, Ended, Canceled

        ITouchListener[] arrays = null;

        // which lists to traverse? according to touch phase
        switch (tch.phase)
        {
        case TouchPhase.Began:
            arrays = ll.beganListeners;
            break;

        case TouchPhase.Stationary:
        case TouchPhase.Moved:
            arrays = ll.stationaryListeners;
            break;

        default:
            // Ended and Canceled
            arrays = ll.endedListeners;
            break;
            // add here if else for other touch phases
        }

        // one loop for scene only, another loop for global
        bool atLeastOneHit = false;

        for (int i = 0, c = arrays.Length; i < c; ++i)
        {
            ITouchListener listener = arrays[i];
            if (listener == null)
            {
                continue;
            }

            bool hitInner = false;

            // Use detection as in chipmunk platformer, since here I don't use physx colliders
            // (Or use cpShapeQuerySegment (see online documentation from release, cpShape class))
            // Now testing AABB using the screen rect of the GUI element
            hitInner = listener.getScreenBoundsAA().Contains(tch.position);

            if (!hitInner)
            {
                continue;
            }

            // invoke callback
            switch (tch.phase)
            {
            case TouchPhase.Began:
                listener.OnBeganTouch(tch);
                break;

            case TouchPhase.Stationary:
            case TouchPhase.Moved:
                listener.OnStationaryTouch(tch);
                break;

            // Ended and Canceled
            default:
                listener.OnEndedTouch(tch);
                break;
                // add here if else for other methods depending on touch phases
            }

            if (!ALLOW_TOUCH_HITS_OVERLAPPED_OBJECTS)
            {
                return(true);
            }
            atLeastOneHit = true;
        }

        if (!ALLOW_TOUCH_HITS_OVERLAPPED_OBJECTS && atLeastOneHit)
        {
            return(true);
        }

        return(false);
    }
예제 #2
0
    private static bool sendEvent(Touch t, ListenerLists ll)
    {
        if (ll == null)
        {
            return(false);
        }

        // NOTE: traverse the lists and ask if something hitten in the correct order:
        //    Began, Stationary/Move, Ended, Canceled

        List <ITouchListener> list = null;

        // which lists to traverse? according to touch phase
        switch (t.phase)
        {
        case TouchPhase.Began:
            list = ll.beganListeners;
            break;

        case TouchPhase.Stationary:
        case TouchPhase.Moved:
            list = ll.stationaryListeners;
            break;

        default:
            // Ended and Canceled
            list = ll.endedListeners;
            break;
            // add here if else for other touch phases
        }

        if (list == null)
        {
            return(false);
        }

        // one loop for scene only, another loop for global
        bool atLeastOneHit = false;

        for (int i = 0, c = list.Count; i < c; ++i)
        {
            ITouchListener listener = list[i];

            /*if (listener == null)
             *      continue;*/

            GameObject go       = listener.getGameObject();
            bool       hitInner = false;

            // check for GUI Texture
            if (go.guiTexture != null)
            {
                hitInner = go.guiTexture.HitTest(t.position);
            }
            // check for GUI Text
            else if (go.guiText != null)
            {
                hitInner = go.guiText.HitTest(t.position);
            }
            // check for game object
            else
            {
                // use detection as in chipmunk platformer, since here I don't use physx colliders
                // or use cpShapeQuerySegment (see online documentation from release, cpShape class)
                hitInner = GameObjectTools.testHitFromScreenPos(go.transform, t.position);
            }

            if (!hitInner)
            {
                continue;
            }

            // invoke callback
            switch (t.phase)
            {
            case TouchPhase.Began:
                list[i].OnBeganTouch(t);
                break;

            case TouchPhase.Stationary:
            case TouchPhase.Moved:
                list[i].OnStationaryTouch(t);
                break;

            // Ended and Canceled
            default:
                list[i].OnEndedTouch(t);
                break;
                // add here if else for other methods depending on touch phases
            }

            if (!ALLOW_TOUCH_HITS_OVERLAPPED_OBJECTS)
            {
                return(true);
            }
            atLeastOneHit = true;
        }

        if (!ALLOW_TOUCH_HITS_OVERLAPPED_OBJECTS && atLeastOneHit)
        {
            return(true);
        }

        return(false);
    }