예제 #1
0
    IEnumerator CheckForChange()
    {
        resolution  = new Vector2(Screen.width, Screen.height);
        orientation = Input.deviceOrientation;

        while (isAlive)
        {
            // Check for a Resolution Change
            if (resolution.x != Screen.width || resolution.y != Screen.height)
            {
                resolution = new Vector2(Screen.width, Screen.height);
                if (OnResolutionChanged != null)
                {
                    OnResolutionChanged(resolution);
                }
            }

            // Check for an Orientation Change
            switch (Input.deviceOrientation)
            {
            case DeviceOrientation.Unknown:             // Ignore
            case DeviceOrientation.FaceUp:              // Ignore
            case DeviceOrientation.FaceDown:            // Ignore
                break;

            case DeviceOrientation.Portrait:
                OnOrientationPortrait?.Invoke();
                break;

            case DeviceOrientation.LandscapeLeft:
                OnOrientationLandscape?.Invoke();
                break;

            case DeviceOrientation.LandscapeRight:
                OnOrientationLandscape?.Invoke();
                break;

            default:
                break;
            }

            yield return(new WaitForSeconds(CheckDelay));
        }
    }
예제 #2
0
    private void Update()
    {
        //Check Device Orientation Maybe use DougMcFarlane Device Change class from https://forum.unity.com/threads/device-screen-rotation-event.118638/
        if (Input.deviceOrientation == DeviceOrientation.Portrait)
        {
            //Run all methods subscribed to event
            OnOrientationPortrait?.Invoke();
        }
        else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft || Input.deviceOrientation == DeviceOrientation.LandscapeRight)
        {
            OnOrientationLandscape?.Invoke();
        }

        //check if there is a touch found
        if (Input.touchCount > 0)
        {
            initialPlayerTouch = Input.GetTouch(0);
            //Test to see if this will cause any issues.
            //OnTouchDrag?.Invoke(initialPlayerTouch);
            touchTimer += Time.deltaTime;

            //check if we are touching a UI element and if we are dont do any input commands !!!MOVE INTO TOUCHPHASE.ENDED IF
            if (IsTouchOverUIElement(initialPlayerTouch) == false)
            {
                if (initialPlayerTouch.phase == TouchPhase.Began)
                {
                    initialTouchPosition = initialPlayerTouch.position;
                }
                else if (initialPlayerTouch.phase == TouchPhase.Moved)
                {
                    OnTouchDrag?.Invoke(initialPlayerTouch);
                }
                else if (initialPlayerTouch.phase == TouchPhase.Ended)
                {
                    finalTouchPosition = initialPlayerTouch.position;
                    touchTimer         = touchTimer;

                    direction = DetectSwipeDirection(initialTouchPosition, finalTouchPosition);
                    if (direction == SwipeDirection.Left)
                    {
                        OnSwipeLeft?.Invoke();
                    }
                    else if (direction == SwipeDirection.Right)
                    {
                        OnSwipeRight?.Invoke();
                    }
                    else if (direction == SwipeDirection.Up)
                    {
                        OnSwipeUp?.Invoke();
                    }
                    else if (direction == SwipeDirection.Down)
                    {
                        OnSwipeDown?.Invoke();
                    }
                    else if (direction == SwipeDirection.None)
                    {
                        if (touchTimer < tapTime)
                        {
                            StartCoroutine("DoubleTap");
                        }
                        else
                        {
                            OnSingleTouchHeld?.Invoke(initialPlayerTouch);
                        }
                    }
                    touchTimer = 0f;
                }
            }
        }
    }