Exemplo n.º 1
0
    public override void HandleEvent(EventData resp)
    {
        if (InGameManager.GetInstance().gameState != enGameState.playing)
        {
            return;
        }
        switch (resp.eid)
        {
        case EventID.EVENT_TOUCH_DOWN:
            EventTouch eve = (EventTouch)resp;
            //TouchToPlane(eve.pos);
            //Fire(GameCommon.ScreenPositionToWorld(eve.pos));
            Vector3 pos = GameCommon.ScreenPositionToWorld(InGameManager.GetInstance().gamecamera, eve.pos);

            if (pos.x > 0)
            {
                KillObj();
            }
            else
            {
                if (GetMyState() == GameObjState.red)
                {
                    return;
                }
                SetState(GetMyState() == GameObjState.black ? GameObjState.white:GameObjState.black);
            }

            break;
        }
    }
Exemplo n.º 2
0
    public override void HandleEvent(EventData resp)
    {
        if (InGameManager.GetInstance().gameState != enGameState.playing)
        {
            return;
        }
        if (bullet == null)
        {
            return;
        }
        switch (resp.eid)
        {
        case EventID.EVENT_TOUCH_DOWN:
            EventTouch eve = (EventTouch)resp;
            //TouchToPlane(eve.pos);
            //Fire(GameCommon.ScreenPositionToWorld(eve.pos));
            Vector3 pos = GameCommon.ScreenPositionToWorld(InGameManager.GetInstance().gamecamera, eve.pos);

            if (pos.y > InGameManager.GetInstance().inGameUIManager.gamePadManager.comboLabelPos.y - 1)
            {
                return;
            }

            bullet.Fire();
            AudioManager.Instance.Play("sound/btn");
            bullet = null;
            break;
        }
    }
Exemplo n.º 3
0
 public static EventTouch share()
 {
     if (_instance == null)
     {
         GameObject go = new GameObject("EventTouchSingleTon");
         _instance = go.AddComponent <EventTouch>();
     }
     return(_instance);
 }
Exemplo n.º 4
0
 public override void HandleEvent(EventData resp)
 {
     switch (resp.eid)
     {
     case EventID.EVENT_TOUCH_DOWN:
         EventTouch eve = (EventTouch)resp;
         Fire(GameCommon.ScreenPositionToWorld(eve.pos));
         break;
     }
 }
Exemplo n.º 5
0
    public override void HandleEvent(EventData resp)
    {
        switch (resp.eid)
        {
        case EventID.EVENT_TOUCH_MOVE:
            EventTouch moveeve = (EventTouch)resp;

            //Vector3 pos = GameCommon.ScreenPositionToWorld(InGameManager.GetInstance().gamecamera, moveeve.pos);

            TouchMove(moveeve.pos);
            break;
        }
    }
Exemplo n.º 6
0
    public override void HandleEvent(EventData resp)
    {
        switch (resp.eid)
        {
        case EventID.EVENT_TOUCH_SWEEP:

            EventTouch e = (EventTouch)resp;
            girl1.StartRun(Vector3.zero);
            break;

        case EventID.EVENT_TOUCH_UP:
            EventTouch eup = (EventTouch)resp;
            girl1.StopAction();
            break;
        }
    }
Exemplo n.º 7
0
        // Use this for initialization
        void Awake()
        {
            if (OnTouchCountChanged == null)
            {
                OnTouchCountChanged = new EventInt();
            }

            if (OnTouchDown == null)
            {
                OnTouchDown = new EventTouch();
            }

            if (OnTouchUp == null)
            {
                OnTouchUp = new EventTouch();
            }

            if (OnDrag == null)
            {
                OnDrag = new EventTouch();
            }

            if (OnTapPositionUp == null)
            {
                OnTapPositionUp = new EventScreenPosition();
            }

            if (OnMove == null)
            {
                OnMove = new EventTouch();
            }

            if (OnMultiMove == null)
            {
                OnMultiMove = new EventMultiTouch();
            }

            if (OnMultiMoveUp == null)
            {
                OnMultiMoveUp = new EventMultiTouch();
            }
        }
Exemplo n.º 8
0
    public override void HandleEvent(EventData resp)
    {
        switch (resp.eid)
        {
        case EventID.EVENT_TOUCH_DOWN:
            //EventTouch eve = (EventTouch)resp;
            //TouchToPlane(eve.pos);
            //Fire(GameCommon.ScreenPositionToWorld(eve.pos));
            //transform.position = GameCommon.ScreenPositionToWorld(InGameManager.GetInstance().gamecamera,eve.pos);
            break;

        case EventID.EVENT_TOUCH_MOVE:
            EventTouch moveeve = (EventTouch)resp;
            Vector3    pos     = GameCommon.ScreenPositionToWorld(InGameManager.GetInstance().gamecamera, moveeve.pos);
            Vector3    dis     = (pos - transform.position) * 0.01f;
            //moveForce += dis ;
            moveForce = new Vector3(moveForce.x + dis.x, moveForce.y, 0);
            break;
        }
    }
        private static void TouchDownHandler(object sender, TouchEventArgs e)
#endif
        {
            TouchEventArgs eva = new TouchEventArgs();

            eva.id   = e.id;
            eva.time = e.time;

            recordEventArgs.Add(eva);

            EventTouch found          = null;
            Vector2    screenPosition = ScreenToClient(e.x, e.y);

            foreach (EventTouch t in eventTouches)
            {
#if USE_MOUSE_IN_PLACE_OF_TOUCH
                if (t.fingerId == mouseId)
#else
                if (t.fingerId == e.id)
#endif
                {
                    found = t;
                    //Console.WriteLine("TouchDown: t.postion= " + t.position.ToString() + ", phase=" + t.phase.ToString() + ", EventTouch=" + t.ToString());
                    break;
                }
            }

            // If we have found an old touch, lets compare the current time to the time stored in the touch
            // Then we can decide if its a tap or not.
            if (found != null)
            {
                //Console.WriteLine("Touch down on existing contact? {0}", found.fingerId);
                if (found.phase != TouchPhase.Ended)
                {
                    // This is duplicate from the touch hook?
                    Console.WriteLine("Touch contact exists: " + found.fingerId.ToString() + " -Touch.deltaTime is: " + found.deltaTime.ToString());
                    // This used to return from here. But we should have taken care of the duplicate events now
                    // so this isn't used except to log when we find a touch that should have been removed
                }

                Vector2 deltaPosition = screenPosition - found.position;
                found.deltaPosition = deltaPosition;
            }
            else
            {
                found = new EventTouch(screenPosition);
#if USE_MOUSE_IN_PLACE_OF_TOUCH
                found.fingerId = mouseId;// e.id;
#else
                found.fingerId = e.id;
#endif
                //found.deltaPosition = new Vector2();
                found.startTime = Time.WallClockTotalSeconds;
                //PV New place for the code
                found.isNew = true;
                // Set the phase to began
                found.phase = TouchPhase.Began;
                eventTouches.Add(found);
            }

            found.UpdateTimeOfChange(Time.WallClockTotalSeconds);
            found.position = screenPosition;
        }
        public static void Update()
        {
            //first remove old eventTouches, and Touches
            bool removedOld = true;

            while (removedOld)
            {
                removedOld = false;
                foreach (EventTouch eventTouch in eventTouches)
                {
                    if (eventTouch.isOld)
                    {
                        foreach (Touch touchThisFrame in touchesThisFrame)
                        {
                            if (touchThisFrame.fingerId == eventTouch.fingerId)
                            {
                                touchesThisFrame.Remove(touchThisFrame);
                                break;
                            }
                        }
                        eventTouches.Remove(eventTouch);
                        removedOld = true;
                        break;
                    }
                }
            }

            //add new eventTouches
            for (int i = 0; i < eventTouches.Count; ++i)
            {
                Touch      currentTouchThisFrame = null;
                EventTouch eventTouch            = eventTouches[i];
                // If this is a new touch, then lets add it
                if (eventTouch.isNew)
                {
                    foreach (Touch touchThisFrame in touchesThisFrame)
                    {
                        if (touchThisFrame.fingerId == eventTouch.fingerId)
                        {
                            currentTouchThisFrame = touchThisFrame;
                            break;
                        }
                    }

                    if (currentTouchThisFrame == null)
                    {
                        currentTouchThisFrame          = new Touch();
                        currentTouchThisFrame.fingerId = eventTouch.fingerId;
                        touchesThisFrame.Add(currentTouchThisFrame);
                    }
                    eventTouch.isNew = false;
                }
                else
                {
                    foreach (Touch touchThisFrame in touchesThisFrame)
                    {
                        if (touchThisFrame.fingerId == eventTouch.fingerId)
                        {
                            currentTouchThisFrame = touchThisFrame;
                            break;
                        }
                    }
                    //??
                    if (currentTouchThisFrame == null)
                    {
                        Console.WriteLine("CurrentTouch not found!!");
                        continue;
                    }
                }

                switch (eventTouch.phase)
                {
                case TouchPhase.Began:
                {
                    // Set the {t} object to stationary, this will be updated to moved if needed or copied into the
                    // {touch} object next frame. This way we only see the Began phase for one frame.
                    eventTouch.phase = TouchPhase.Stationary;
                    eventTouch.isOld = false;

                    currentTouchThisFrame.phase = TouchPhase.Began;
                    break;
                }

                case TouchPhase.Moved:
                {
                    // The touch move handler sets 'touches' list objects to the moved phase.
                    // Here in the update, we will transfer that phase info over to the 'touchesThisFrame'
                    // list, and the 'touches' list object gets set to Stationary again. In the absence
                    // of future move events, the 'touchesThisFrame' object will become stationary on
                    // the *following* frame.
                    eventTouch.phase            = TouchPhase.Stationary;
                    currentTouchThisFrame.phase = TouchPhase.Moved;

                    break;
                }

                case TouchPhase.Stationary:
                {
                    currentTouchThisFrame.phase = TouchPhase.Stationary;
                    break;
                }

                case TouchPhase.Ended:
                {
                    currentTouchThisFrame.phase = TouchPhase.Ended;
                    eventTouch.isOld            = true;

                    break;
                }

                default:
                    break;
                } //switch

                // Update the {t} objects time so it can be copied into the {touch} object
                eventTouch.UpdateDeltaTime(Time.WallClockTotalSeconds);

                // Set position with offset for Tutorial mode.
                currentTouchThisFrame.position = eventTouch.position - BokuGame.ScreenPosition;

                // HACK (****)  The touch position seems to be off.  Offset it here to be more accurate.
                // Need to really figure out why.
                currentTouchThisFrame.position += new Vector2(18, 18);

                currentTouchThisFrame.deltaPosition = eventTouch.deltaPosition;
                currentTouchThisFrame.fingerId      = eventTouch.fingerId;
                //touch.tapCount = eventTouch.tapCount;

                currentTouchThisFrame.deltaTime = eventTouch.deltaTime;

                // Here we handle any touch-up messages whose processing is to be delayed by a frame.
                // We set the 'touches' phase to ended, which will then be propogated to
                // 'touchesThisFrame' on the following frame.
                if (eventTouch.delayedEnd)
                {
                    eventTouch.delayedEnd = false;
                    eventTouch.phase      = TouchPhase.Ended;
                    Console.WriteLine("Delayed touch up has been processed. Touch.touchPhase will be Ended next frame! id: " + eventTouch.fingerId.ToString() + ", phase: " +
                                      eventTouch.phase.ToString());
                }
            } //int i = 0; i < eventTouches.Count; ++i)

            touchCountThisFrame = touchesThisFrame.Count;
        }
        private static void TouchUpHandler(object sender, TouchEventArgs e)
#endif
        {
            TouchEventArgs teaFind = recordEventArgs.Find(
                delegate(TouchEventArgs tea)
            {
                return(tea.id == e.id);
            }
                );

            if (teaFind != null)
            {
                recordEventArgs.Remove(teaFind);
            }

            EventTouch found          = null;
            Vector2    screenPosition = ScreenToClient(e.x, e.y);

            foreach (EventTouch t in eventTouches)
            {
#if USE_MOUSE_IN_PLACE_OF_TOUCH
                if (t.fingerId == mouseId)
#else
                if (t.fingerId == e.id)
#endif
                {
                    found = t;
                    //Console.WriteLine("TouchUp: t.postion= " + t.position.ToString() + ", phase=" + t.phase.ToString() + ", EventTouch=" + t.ToString() );

                    break;
                }
            }

            // If we don't have a touch then something went wrong... we should have up events on
            // existing touches, not new ones.
            if (found == null)
            {
                Console.WriteLine("Processing an UP event for a non-existant touch contact");

                return;
            }

            //FIXME: this was making it impossible to implement double tap - removing it seems to work, but more testing needed
            // to attempt to ascertain the actual problem it was supposedly trying to fix in the first place
            //if (found.timeOfLastChange == Time.WallClockTotalSeconds && found.phase != TouchPhase.Ended)
            //{
            //    Console.WriteLine("Touch Up on same event?  Setting delayed end... {0}", found.fingerId);

            //    // This is part of the bug where we get a touch down and up as part of the same message queue...
            //    // so to fix it we delay the touch end by one frame
            //    found.delayedEnd = true;
            //}

            found.UpdateTimeOfChange(Time.WallClockTotalSeconds);
            Vector2 deltaPosition = screenPosition - found.position;
            found.deltaPosition = deltaPosition;
            found.position      = screenPosition;

            // Set the phase to ended
            if (found.delayedEnd == false)
            {
                // No delay was required for this touch up, as it was received with a different time stamp than
                // a touch-down.
                found.phase = TouchPhase.Ended;

                //Console.WriteLine("Undelayed touch up! id: " + found.fingerId.ToString() + ", phase: " + found.phase.ToString());
            }
            else
            {
                //Console.WriteLine("Delayed touch up! id: " + found.fingerId.ToString() + ", phase: " + found.phase.ToString());
            }
        }
        private static void TouchMoveHandler(object sender, TouchEventArgs e)
#endif
        {
            EventTouch found          = null;
            Vector2    screenPosition = ScreenToClient(e.x, e.y);

            foreach (EventTouch t in eventTouches)
            {
#if USE_MOUSE_IN_PLACE_OF_TOUCH
                if (t.fingerId == mouseId)
#else
                if (t.fingerId == e.id)
#endif
                {
                    found = t;
                    break;
                }
            }

#if USE_MOUSE_IN_PLACE_OF_TOUCH
            if (found == null)
            {
                // The mouse can still move when the touch has not started, therefore the touches list is empty.
                return;
            }
#endif
            // If we don't have a touch then something went wrong... we should only be moving
            // existing touches, not new ones.
            if (found == null)
            {
                Console.WriteLine("Processing an MOVE event for a non-existant touch contact");
                return;
            }

#if USE_MOUSE_IN_PLACE_OF_TOUCH
            if (found.phase == TouchPhase.Ended)
            {
                // The mouse can move even if it isn't 'touching' the screen... this breaks the simulated touch!!! so, lets happily ignore this and just go on our way
                return;
            }
#endif

            if (found.timeOfLastChange == Time.WallClockTotalSeconds)
            {
                //Console.WriteLine("Ignoring MOVE event due to zero delta time. {0}", found.fingerId);
                // This is an extraneous message from the OS. It seems that windows doesn't really know what its doing here... we get a touch down event imediately followed by a move.
                // so we never see the down.
                return;
            }

            found.UpdateTimeOfChange(Time.WallClockTotalSeconds);

            //copy the screen position first so that it can get filtered
            Vector2 oldPosition = found.position;
            found.position = screenPosition;

            Vector2 deltaPosition = found.position - oldPosition;
            found.deltaPosition = deltaPosition;


            found.deltaPosition = deltaPosition;
            //found.tapCount = 0;
            // Set the phase to moved
            found.phase = TouchPhase.Moved;
        }