private void InputByDevice()
        {
            isTouch    = true;
            touchCount = 0;

            if (inputType == INPUT_TYPE.TOUCH)
            {
#if UNITY_STANDALONE_WIN
                // for Windows Player
#if !USE_TOUCH_SCRIPT
                Debug.LogWarning("Input.Touch is not work in windows. please use TouchScript. and then enable the define macro on the first line of this script.");
#else
                // as TouchScript
                touchCount = TouchScript.TouchManager.Instance.PressedPointersCount;

                if (touchCount >= 1)
                {
                    TouchScript.Pointers.Pointer tp = TouchScript.TouchManager.Instance.PressedPointers[0];
                    Rect wrect = WindowsUtil.GetApplicationWindowRect(); // not work in Editor.
                    touchPosition = new Vector2(
                        (int)(((tp.Position.x / Screen.width) * Screen.currentResolution.width) - wrect.x),
                        Screen.height + (int)(((tp.Position.y / Screen.height) * Screen.currentResolution.height) - wrect.y));

                    if (tp.Position == tp.PreviousPosition)
                    {
                        if (isPressed)
                        {
                            phase = INPUT_PHASE.Moved;
                        }
                        else
                        {
                            phase = INPUT_PHASE.Began;
                        }
                    }
                    else
                    {
                        phase = INPUT_PHASE.Moved;
                    }
                }
                else
#endif
                {
                    // Pressされた後にここにきたらReleaseとする
                    if (isPressed)
                    {
                        phase = INPUT_PHASE.ENDED;
                    }
                    else
                    {
                        phase         = INPUT_PHASE.NONE;
                        touchPosition = Vector3.zero;
                        isTouch       = false;
                    }
                }
#elif UNITY_IOS || UNITY_ANDROID
                // for Mobile
                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;
                }
#endif
            }

            // 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;
            }
        }
    /// <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;
        }
    }
    /// <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;
    }
Beispiel #4
0
    /// <summary>
    /// 入力デバイスにより分岐する
    /// </summary>
    private void InputDevice()
    {
        isTouch    = true;
        touchCount = 0;

        //for WinTouch
        if (inputType == INPUT_TYPE.WTOUCH)
        {
#if UNITY_STANDALONE_WIN
            touchCount = TouchScript.TouchManager.Instance.NumberOfTouches;

            //1点目を入力として受付
            if (touchCount >= 1)
            {
                TouchScript.TouchPoint tp = TouchScript.TouchManager.Instance.ActiveTouches[0];
                Rect wrect = Utils.WindowsUtil.GetApplicationWindowRect();                 //not work in Editor.
                touchPosition = new Vector2(
                    (int)(((tp.Position.x / Screen.width) * Screen.currentResolution.width) - wrect.x),
                    Screen.height + (int)(((tp.Position.y / Screen.height) * Screen.currentResolution.height) - wrect.y));

                if (tp.Position == tp.PreviousPosition)
                {
                    if (isPressed)
                    {
                        phase = INPUT_PHASE.Moved;
                    }
                    else
                    {
                        phase = INPUT_PHASE.Began;
                    }
                }
                else
                {
                    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;
        }
    }