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 WinTouch if (inputType == INPUT_TYPE.WTOUCH) { #if UNITY_STANDALONE_WIN #if !USE_TOUCH_SCRIPT touchCount = Input.touchCount; // 1点目を入力として受付 if (touchCount >= 1) { Rect wrect = WindowsUtil.GetApplicationWindowRect(); // not work in Editor. touchPosition = new Vector2( (int)(((Input.touches[0].position.x / Screen.width) * Screen.currentResolution.width) - wrect.x), Screen.height + (int)(((Input.touches[0].position.x / Screen.height) * Screen.currentResolution.height) - wrect.y)); if (Input.touches[0].deltaPosition != Vector2.zero) { if (isPressed) { phase = INPUT_PHASE.Moved; } else { phase = INPUT_PHASE.Began; } } else { phase = INPUT_PHASE.Moved; } #else touchCount = TouchScript.TouchManager.Instance.PressedPointersCount; // 1点目を入力として受付 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; } #endif } 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; } }