private void GetInput() { // for Touch if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount >= grabTouchNum) { // カメラ操作のロック if (flyThroughCamera != null) { flyThroughCamera.LockInput(this.gameObject); } if (pinchZoomCamera != null) { pinchZoomCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.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 && winTouch) { if (TouchScript.TouchManager.Instance.PressedPointersCount >= grabTouchNum) { // カメラ操作のロック if (flyThroughCamera != null) { flyThroughCamera.LockInput(this.gameObject); } if (pinchZoomCamera != null) { pinchZoomCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.LockInput(this.gameObject); } // コンポーネントをOFF foreach (MonoBehaviour component in disableComponents) { if (component != null) { component.enabled = false; } } // ドラッグ量を計算 TouchScript.Pointers.Pointer tp0 = TouchScript.TouchManager.Instance.PressedPointers[0]; TouchScript.Pointers.Pointer tp1 = TouchScript.TouchManager.Instance.PressedPointers[1]; TouchScript.Pointers.Pointer tp2 = TouchScript.TouchManager.Instance.PressedPointers[2]; float touchesPosX = (tp0.Position.x + tp1.Position.x + tp2.Position.x) / 3.0f; float touchesPosY = (tp0.Position.y + tp1.Position.y + tp2.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 != null) { flyThroughCamera.LockInput(this.gameObject); } if (pinchZoomCamera != null) { pinchZoomCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.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(); } } }
private void GetInput() { // for Touch if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount == 2) { // カメラ操作のロック if (flyThroughCamera != null) { flyThroughCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.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 (zoomToPinchCenterFor2D) { StartZoomToPinchCenter(); } oldDistance = currentDistance; isFirstTouch = false; return; } calcZoom = currentDistance - oldDistance; oldDistance = currentDistance; } else { ResetInput(); } } #if UNITY_STANDALONE_WIN else if (Application.platform == RuntimePlatform.WindowsPlayer && winTouch) { #if !USE_TOUCH_SCRIPT if (Input.touchCount == 2) #else if (TouchScript.TouchManager.Instance.PressedPointersCount == 2) #endif { // カメラ操作のロック if (flyThroughCamera != null) { flyThroughCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.LockInput(this.gameObject); } // 連携コンポーネントをOFF foreach (MonoBehaviour component in disableComponents) { if (component != null) { component.enabled = false; } } #if !USE_TOUCH_SCRIPT // ピンチセンターを設定 pinchCenter = ( Input.touches[0].position + Input.touches[1].position) / 2.0f; // ピンチ距離を計算 currentDistance = Vector3.Distance( Input.touches[0].position, Input.touches[1].position); #else // ピンチセンターを設定 pinchCenter = ( TouchScript.TouchManager.Instance.PressedPointers[0].Position + TouchScript.TouchManager.Instance.PressedPointers[1].Position) / 2.0f; // ピンチ距離を計算 currentDistance = Vector3.Distance( TouchScript.TouchManager.Instance.PressedPointers[0].Position, TouchScript.TouchManager.Instance.PressedPointers[1].Position); #endif if (isFirstTouch) { // ピンチセンターへのズーム開始 if (zoomToPinchCenterFor2D) { 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))) || Input.mouseScrollDelta.y != 0.0f) { // カメラ操作のロック if (flyThroughCamera != null) { flyThroughCamera.LockInput(this.gameObject); } if (orbitCamera != null) { orbitCamera.LockInput(this.gameObject); } // 連携コンポーネントをOFF foreach (MonoBehaviour component in disableComponents) { if (component != null) { component.enabled = false; } } if (Input.mouseScrollDelta.y == 0.0f) { // ドラッグでの操作 // ピンチセンターを設定 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 (zoomToPinchCenterFor2D) { StartZoomToPinchCenter(); } oldDistance = currentDistance; isFirstTouch = false; return; } calcZoom = currentDistance - oldDistance; oldDistance = currentDistance; } else { // ホイールでの操作 calcZoom = Input.mouseScrollDelta.y * ratioForWheel; } } else { ResetInput(); } } }