Ejemplo n.º 1
0
    private void GetInput()
    {
        //for Touch
        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
        {
            if (Input.touchCount == 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    moveVector = (Vector3)(Input.GetTouch(0).deltaPosition / 10.0f);
                    isClicked  = true;
                }
                else
                {
                    ResetInput();
                }
            }
            else if (Input.touchCount == 0)
            {
                ResetInput();
            }
        }

#if UNITY_STANDALONE_WIN
        else if (Application.platform == RuntimePlatform.WindowsPlayer && win7touch)
        {
            if (W7TouchManager.GetTouchCount() == 1)
            {
                if (W7TouchManager.GetTouch(0).Phase == TouchPhase.Moved)
                {
                    moveVector = (Vector3)(W7TouchManager.GetTouch(0).DeltaPosition / 10.0f);
                    isClicked  = true;
                }
                else
                {
                    ResetInput();
                }
            }
            else if (W7TouchManager.GetTouchCount() == 0)
            {
                ResetInput();
            }
        }
#endif

        //for Mouse
        else
        {
            if (Input.GetMouseButton(0))
            {
                moveVector = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0f);
                isClicked  = true;
            }
            else
            {
                ResetInput();
            }
        }
    }
Ejemplo n.º 2
0
    private void GetInput()
    {
        //for Touch
        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
        {
            if (Input.touchCount > 0)
            {
                currentTouchScrPos = Input.GetTouch(0).position;
            }
            else
            {
                ResetInput();
            }
        }

#if UNITY_STANDALONE_WIN
        else if (Application.platform == RuntimePlatform.WindowsPlayer && win7touch)
        {
            if (W7TouchManager.GetTouchCount() > 0)
            {
                currentTouchScrPos = W7TouchManager.GetTouch(0).Position;
            }
            else
            {
                ResetInput();
            }
        }
#endif

        //for Mouse
        else
        {
            if (Input.GetMouseButton(0))
            {
                currentTouchScrPos = Input.mousePosition;
            }
            else
            {
                ResetInput();
            }
        }
    }
    /// <summary>
    /// 入力チェック
    /// </summary>
    private void CheckInput()
    {
        if (!isValid)
        {
            //for Mouse
            if (Application.platform == RuntimePlatform.WindowsEditor || inputType == INPUT_TYPE.MOUSE)
            {
                if (Input.GetAxis("Mouse X") + Input.GetAxis("Mouse Y") > 0.0f)
                {
                    DisableScreenSaver();
                }
            }

            //for Touch
            else if (inputType == INPUT_TYPE.INPUTTOUCH)
            {
                if (Input.touchCount > 0)
                {
                    DisableScreenSaver();
                }
            }

            //for W7Touch
            else if (inputType == INPUT_TYPE.W7TOUCH)
            {
                if (W7TouchManager.GetTouchCount() > 0)
                {
                    DisableScreenSaver();
                }
            }

            //for Kinect
            else if (inputType == INPUT_TYPE.KINECT)
            {
                //TODO for Kinect
            }
        }
    }
Ejemplo n.º 4
0
    private void GetInput()
    {
        //for Touch
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount >= grabTouchNum)
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (PinchZoomCamera.Instance != null)
                {
                    PinchZoomCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ドラッグ量を計算
                float   touchesPosX          = (Input.GetTouch(0).position.x + Input.GetTouch(1).position.x + Input.GetTouch(2).position.x) / 3.0f;
                float   touchesPosY          = (Input.GetTouch(0).position.y + Input.GetTouch(1).position.y + Input.GetTouch(2).position.y) / 3.0f;
                Vector3 currentWorldTouchPos = renderCamera.ScreenToWorldPoint(new Vector3(touchesPosX, touchesPosY, 1000.0f));

                if (isFirstTouch)
                {
                    oldWorldTouchPos = currentWorldTouchPos;
                    isFirstTouch     = false;
                    return;
                }

                dragDelta        = currentWorldTouchPos - oldWorldTouchPos;
                oldWorldTouchPos = currentWorldTouchPos;
            }
            else
            {
                ResetInput();
            }
        }

#if UNITY_STANDALONE_WIN
        else if (Application.platform == RuntimePlatform.WindowsPlayer && win7touch)
        {
            if (W7TouchManager.GetTouchCount() >= grabTouchNum)
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (PinchZoomCamera.Instance != null)
                {
                    PinchZoomCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ドラッグ量を計算
                float   touchesPosX          = (W7TouchManager.GetTouch(0).Position.x + W7TouchManager.GetTouch(1).Position.x + W7TouchManager.GetTouch(2).Position.x) / 3.0f;
                float   touchesPosY          = (W7TouchManager.GetTouch(0).Position.y + W7TouchManager.GetTouch(1).Position.y + W7TouchManager.GetTouch(2).Position.y) / 3.0f;
                Vector3 currentWorldTouchPos = renderCamera.ScreenToWorldPoint(new Vector3(touchesPosX, touchesPosY, 1000.0f));

                if (isFirstTouch)
                {
                    oldWorldTouchPos = currentWorldTouchPos;
                    isFirstTouch     = false;
                    return;
                }

                dragDelta        = currentWorldTouchPos - oldWorldTouchPos;
                oldWorldTouchPos = currentWorldTouchPos;
            }
            else
            {
                ResetInput();
            }
        }
#endif

        //for Mouse
        else
        {
            if (Input.GetMouseButton(0) &&
                (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) &&
                (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (PinchZoomCamera.Instance != null)
                {
                    PinchZoomCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ドラッグ量を計算
                Vector3 currentWorldTouchPos = renderCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1000.0f));

                if (isFirstTouch)
                {
                    oldWorldTouchPos = currentWorldTouchPos;
                    isFirstTouch     = false;
                    return;
                }

                dragDelta        = currentWorldTouchPos - oldWorldTouchPos;
                oldWorldTouchPos = currentWorldTouchPos;
            }
            else
            {
                ResetInput();
            }
        }
    }
Ejemplo n.º 5
0
    private void GetInput()
    {
        //for Touch
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount == 1)
            {
                //ドラッグ量を計算
                Vector3 currentScrTouchPos = Input.GetTouch(0).position;

                if (isFirstTouch)
                {
                    oldScrTouchPos = currentScrTouchPos;
                    isFirstTouch   = false;
                    return;
                }

                dragDelta = currentScrTouchPos - oldScrTouchPos;

                if (controllType == FLYTHROUGH_CONTROLL_TYPE.DRAG)
                {
                    oldScrTouchPos = currentScrTouchPos;
                }
            }
            else
            {
                ResetInput();
            }
        }

#if UNITY_STANDALONE_WIN
        else if (Application.platform == RuntimePlatform.WindowsPlayer && win7touch)
        {
            if (W7TouchManager.GetTouchCount() == 1)
            {
                //ドラッグ量を計算
                Vector3 currentScrTouchPos = W7TouchManager.GetTouch(0).Position;

                if (isFirstTouch)
                {
                    oldScrTouchPos = currentScrTouchPos;
                    isFirstTouch   = false;
                    return;
                }

                dragDelta = currentScrTouchPos - oldScrTouchPos;

                if (controllType == FLYTHROUGH_CONTROLL_TYPE.DRAG)
                {
                    oldScrTouchPos = currentScrTouchPos;
                }
            }
            else
            {
                ResetInput();
            }
        }
#endif

        //for Mouse
        else
        {
            if (Input.GetMouseButton(0))
            {
                //ドラッグ量を計算
                Vector3 currentScrTouchPos = Input.mousePosition;

                if (isFirstTouch)
                {
                    oldScrTouchPos = currentScrTouchPos;
                    isFirstTouch   = false;
                    return;
                }

                dragDelta = currentScrTouchPos - oldScrTouchPos;

                if (controllType == FLYTHROUGH_CONTROLL_TYPE.DRAG)
                {
                    oldScrTouchPos = currentScrTouchPos;
                }
            }
            else
            {
                ResetInput();
            }
        }
    }
Ejemplo n.º 6
0
    private void GetInput()
    {
        //for Touch
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount == 2)
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //連携コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ピンチセンターを設定
                pinchCenter = (Input.GetTouch(0).position + Input.GetTouch(1).position) / 2.0f;

                //ピンチ距離を計算
                currentDistance = Vector3.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);

                if (isFirstTouch)
                {
                    //ピンチセンターへのズーム開始
                    if (zoomToPinchCenter)
                    {
                        StartZoomToPinchCenter();
                    }

                    oldDistance  = currentDistance;
                    isFirstTouch = false;
                    return;
                }

                calcZoom    = currentDistance - oldDistance;
                oldDistance = currentDistance;
            }
            else
            {
                ResetInput();
            }
        }

#if UNITY_STANDALONE_WIN
        else if (Application.platform == RuntimePlatform.WindowsPlayer && win7touch)
        {
            if (W7TouchManager.GetTouchCount() == 2)
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //連携コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ピンチセンターを設定
                pinchCenter = (W7TouchManager.GetTouch(0).Position + W7TouchManager.GetTouch(1).Position) / 2.0f;

                //ピンチ距離を計算
                currentDistance = Vector3.Distance(W7TouchManager.GetTouch(0).Position, W7TouchManager.GetTouch(1).Position);

                if (isFirstTouch)
                {
                    //ピンチセンターへのズーム開始
                    if (zoomToPinchCenter)
                    {
                        StartZoomToPinchCenter();
                    }

                    oldDistance  = currentDistance;
                    isFirstTouch = false;
                    return;
                }

                calcZoom    = currentDistance - oldDistance;
                oldDistance = currentDistance;
            }
            else
            {
                ResetInput();
            }
        }
#endif

        //for Mouse
        else
        {
            if (Input.GetMouseButton(0) && (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)))
            {
                //カメラ操作のロック
                if (FlyThroughCamera.Instance != null)
                {
                    FlyThroughCamera.Instance.LockInput(this.gameObject);
                }
                if (OrbitCamera.Instance != null)
                {
                    OrbitCamera.Instance.LockInput(this.gameObject);
                }

                //連携コンポーネントをOFF
                foreach (MonoBehaviour component in disableComponents)
                {
                    if (component != null)
                    {
                        component.enabled = false;
                    }
                }

                //ピンチセンターを設定
                if (isFirstTouch)
                {
                    pinchCenter = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                }

                //ピンチ距離を計算
                Vector2 orgPoint    = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                Vector2 diff        = orgPoint - pinchCenter;
                Vector2 mirrorPoint = new Vector2(
                    (diff.x * Mathf.Cos(180 * Mathf.Deg2Rad)) - (diff.y * Mathf.Sin(180 * Mathf.Deg2Rad)),
                    (diff.x * Mathf.Sin(180 * Mathf.Deg2Rad)) + (diff.y * Mathf.Cos(180 * Mathf.Deg2Rad))
                    );
                currentDistance = Vector3.Distance(orgPoint, mirrorPoint);

                if (isFirstTouch)
                {
                    //ピンチセンターへのズーム開始
                    if (zoomToPinchCenter)
                    {
                        StartZoomToPinchCenter();
                    }

                    oldDistance  = currentDistance;
                    isFirstTouch = false;
                    return;
                }

                calcZoom    = currentDistance - oldDistance;
                oldDistance = currentDistance;
            }
            else
            {
                ResetInput();
            }
        }
    }
    /// <summary>
    /// 入力デバイスにより分岐する
    /// </summary>
    private void InputDevice()
    {
        isTouch    = true;
        touchCount = 0;

        //for Win7Touch
        if (inputType == INPUT_TYPE.W7TOUCH)
        {
#if UNITY_STANDALONE_WIN
            //WindowsのときのみWin7Touchが必要
            touchCount = W7TouchManager.GetTouchCount();

            //1点目を入力として受付
            if (touchCount >= 1)
            {
                W7Touch w7t1  = W7TouchManager.GetTouch(0);
                Rect    wrect = Utils.WindowsUtil.GetApplicationWindowRect();              //not work in Editor.
                touchPosition = new Vector2(
                    (int)(((w7t1.Position.x / Screen.width) * Screen.currentResolution.width) - wrect.x),
                    Screen.height + (int)(((w7t1.Position.y / Screen.height) * Screen.currentResolution.height) - wrect.y));
                TouchPhase tphase = w7t1.Phase;

                if (tphase == TouchPhase.Began)
                {
                    //isPressed == Trueの状態でBeganがくることはありえないのだが来てしまうときがある
                    //その場合はMovedということにする
                    if (isPressed)
                    {
                        phase = INPUT_PHASE.Moved;
                    }
                    else
                    {
                        phase = INPUT_PHASE.Began;
                    }
                }
                else if (tphase == TouchPhase.Ended || tphase == TouchPhase.Canceled)
                {
                    //Win7Touchではここにはこないようです
                    phase = INPUT_PHASE.Ended;
                }
                else if (tphase == TouchPhase.Moved || tphase == TouchPhase.Stationary)
                {
                    phase = INPUT_PHASE.Moved;
                }
            }
            else
            {
                //Pressされた後にここにきたらReleaseとする
                if (isPressed)
                {
                    phase = INPUT_PHASE.Ended;
                }
                else
                {
                    phase         = INPUT_PHASE.NONE;
                    touchPosition = Vector3.zero;
                    isTouch       = false;
                }
            }
#endif
        }

        //for Mobile
        else if (inputType == INPUT_TYPE.INPUTTOUCH)
        {
            touchCount = Input.touchCount;

            if (touchCount >= 1)
            {
                touchPosition = Input.GetTouch(0).position;
                TouchPhase tphase = Input.GetTouch(0).phase;

                if (tphase == TouchPhase.Began)
                {
                    phase = INPUT_PHASE.Began;
                }
                else if (tphase == TouchPhase.Ended || tphase == TouchPhase.Canceled)
                {
                    phase = INPUT_PHASE.Ended;
                }
                else if (tphase == TouchPhase.Moved || tphase == TouchPhase.Stationary)
                {
                    phase = INPUT_PHASE.Moved;
                }
            }
            else
            {
                phase         = INPUT_PHASE.NONE;
                touchPosition = Vector3.zero;
                isTouch       = false;
            }
        }

        //for Mouse
        else if (inputType == INPUT_TYPE.MOUSE)
        {
            touchPosition = Input.mousePosition;

            if (Input.GetMouseButton(0))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    phase = INPUT_PHASE.Began;
                }
                else
                {
                    phase = INPUT_PHASE.Moved;
                }

                touchCount = 1;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                phase = INPUT_PHASE.Ended;
            }
            else
            {
                phase = INPUT_PHASE.NONE;
            }
        }

        if (touchCount < 0)
        {
            touchCount = 0;
        }
    }