コード例 #1
0
ファイル: PlayerEventListener.cs プロジェクト: kknet/Heliko
    void Update()
    {
        if (bc.isInPause())
        {
            return;
        }
                #if UNITY_ANDROID || UNITY_IOS
        if (Input.touchCount > 0)
        {
            switch (Input.GetTouch(0).phase)
            {
            case TouchPhase.Began:
                Vector2 posDoigt = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);

                //si c'est sur le bouton Pause
                if (rectanglePause.Contains(Input.GetTouch(0).position))
                {
                    return;
                }

                touchScreen = true;
                if (posDoigt.x > 0)
                {
                    sendEvent(1);
                }
                else
                {
                    sendEvent(2);
                }
                break;

            case TouchPhase.Ended:
                if (mouvement.magnitude >= 12 && touchScreen)
                {
                    sendEvent(4);
                }
                else if (timeTouchTotal >= timeBeforeLongTouch)
                {
                    sendEvent(3);
                }
                else
                {
                    sendEvent(5);
                }
                timeTouchTotal = 0F;
                touchScreen    = false;
                mouvement      = Vector2.zero;
                break;

            case TouchPhase.Stationary:
                timeTouchTotal += Time.deltaTime;
                if (timeTouchTotal >= timeBeforeLongTouch && touchScreen)
                {
                    touchScreen = false;
                }
                break;

            case TouchPhase.Moved:
                mouvement += Input.GetTouch(0).deltaPosition;
                if (mouvement.magnitude <= 4)
                {
                    timeTouchTotal += Time.deltaTime;
                    if (timeTouchTotal >= timeBeforeLongTouch && touchScreen)
                    {
                        touchScreen = false;
                    }
                }
                break;
            }
        }
                #endif


        if (Input.GetKeyDown(KeyCode.O))
        {
            sendEvent(1);
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            sendEvent(2);
        }
        if (Input.GetKeyUp(KeyCode.O) || Input.GetKeyUp(KeyCode.P))
        {
            sendEvent(3);
        }
    }