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 && winTouch) { if (TouchScript.TouchManager.Instance.NumberOfTouches == 1) { TouchScript.TouchPoint tp = TouchScript.TouchManager.Instance.ActiveTouches[0]; if (tp.Position != tp.PreviousPosition) { moveVector = (Vector3)((tp.PreviousPosition - tp.Position) / 10.0f); isClicked = true; } else { ResetInput(); } } else if (TouchScript.TouchManager.Instance.NumberOfTouches == 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(); } } }
/// <summary> /// Registers a touch. /// </summary> /// <param name="position">Touch position.</param> /// <returns>Internal id of the new touch.</returns> public int BeginTouch(Vector2 position) { TouchPoint touch; lock (sync) { touch = new TouchPoint(nextTouchPointId++, position); touchesBegan.Add(touch); } return(touch.Id); }
private bool shouldReceiveTouch(Gesture gesture, TouchPoint touch) { bool result = true; if (GlobalGestureDelegate != null) { result = GlobalGestureDelegate.ShouldReceiveTouch(gesture, touch); } return(result && gesture.ShouldReceiveTouch(touch)); }
/// <inheritdoc /> public int BeginTouch(Vector2 position, Tags tags, IDictionary <string, System.Object> properties) { TouchPoint touch; lock (touchesBegan) { touch = new TouchPoint(nextTouchId++, position, tags, properties); touchesBegan.Add(touch); } return(touch.Id); }
internal ITouch BeginTouch(Vector2 position, Tags tags) { TouchPoint touch; lock (touchesBegan) { touch = new TouchPoint(nextTouchId++, position, tags); touchesBegan.Add(touch); } return(touch); }
/// <summary> /// Checks if the touch has hit something. /// </summary> /// <param name="touch">The touch.</param> /// <param name="hit">Output RaycastHit.</param> /// <param name="hitCamera">Output camera which was used to hit an object.</param> /// <returns>Object's transform which has been hit or null otherwise.</returns> public Transform GetHitTarget(TouchPoint touch, out RaycastHit hit, out Camera hitCamera) { hit = new RaycastHit(); hitCamera = null; if (HitCameras == null) { return(null); } foreach (var cam in HitCameras) { hitCamera = cam; var ray = cam.ScreenPointToRay(new Vector3(touch.Position.x, touch.Position.y, cam.nearClipPlane)); var hits = Physics.RaycastAll(ray); if (hits.Length == 0) { continue; } var minDist = float.PositiveInfinity; foreach (var rayHit in hits) { var dist = (rayHit.point - cam.transform.position).sqrMagnitude; if (dist < minDist) { minDist = dist; hit = rayHit; } } var hitTests = hit.transform.GetComponents <HitTest>(); if (hitTests.Length == 0) { return(hit.transform); } var result = true; foreach (var test in hitTests) { result = test.IsHit(hit); if (!result) { break; } } if (result) { return(hit.transform); } } return(null); }
private void processTargetBegan(Transform target, TouchPoint touch) { var containingList = gestureListPool.Get(); var endingList = gestureListPool.Get(); // gestures in the target's hierarchy which might affect gesture on the target getHierarchyContaining(target, containingList); // gestures on objects in the hierarchy from "root" to target getHierarchyEndingWith(target, endingList); var count = endingList.Count; for (var i = 0; i < count; i++) { var gesture = endingList[i]; // WARNING! Gestures might change during this loop. // For example when one of them recognizes. if (!gestureIsActive(gesture)) { continue; } var canReceiveTouches = true; var activeCount = containingList.Count; for (var j = 0; j < activeCount; j++) { var activeGesture = containingList[j]; if (gesture == activeGesture) { continue; } if ((activeGesture.State == Gesture.GestureState.Began || activeGesture.State == Gesture.GestureState.Changed) && (canPreventGesture(activeGesture, gesture))) { // there's a started gesture which prevents this one canReceiveTouches = false; break; } } if (canReceiveTouches && shouldReceiveTouch(gesture, touch)) { activeGestures.Add(gesture); } } gestureListPool.Release(containingList); gestureListPool.Release(endingList); }
private bool checkLayers(TouchPoint touch) { foreach (var touchLayer in layers) { if (touchLayer == null) { continue; } if (touchLayer.BeginTouch(touch)) { return(true); } } return(false); }
private void update(TouchPoint touch, Action <Transform, TouchPoint> process, Action <Gesture, TouchPoint> dispatch) { // WARNING! Arcane magic ahead! // gestures which got any touch points // needed because there's no order in dictionary activeGestures.Clear(); if (touch.Target != null) { process(touch.Target, touch); } var count = activeGestures.Count; for (var i = 0; i < count; i++) { var gesture = activeGestures[i]; if (gestureIsActive(gesture)) { dispatch(gesture, touch); } } }
private void processTarget(Transform target, TouchPoint touch) { // gestures on objects in the hierarchy from "root" to target var endingList = gestureListPool.Get(); getHierarchyEndingWith(target, endingList); var count = endingList.Count; for (var i = 0; i < count; i++) { var gesture = endingList[i]; if (!gestureIsActive(gesture)) { continue; } if (gesture.HasTouch(touch)) { activeGestures.Add(gesture); } } gestureListPool.Release(endingList); }
} } if (touch == null) return; } touchesEnded.Add(touch); } } /// <summary> /// Checks if the touch has hit something. /// </summary>
private void doUpdateCancelled(Gesture gesture, TouchPoint touch) { gesture.INTERNAL_TouchCancelled(touch); }
private void doUpdateEnded(Gesture gesture, TouchPoint touch) { gesture.INTERNAL_TouchEnded(touch); }
/// <inheritdoc /> public bool Equals(TouchPoint other) { if (other == null) return false; return Id == other.Id; }
private void removeDebugFigureForTouch(TouchPoint touch) { GLDebug.RemoveFigure(TouchManager.DEBUG_GL_TOUCH + touch.Id); }
private bool checkLayers(TouchPoint touch) { foreach (var touchLayer in layers) { if (touchLayer == null) continue; if (touchLayer.BeginTouch(touch)) return true; } return false; }
/// <summary> /// Registers a touch. /// </summary> /// <param name="position">Touch position.</param> /// <returns>Internal id of the new touch.</returns> public int BeginTouch(Vector2 position) { TouchPoint touch; lock (sync) { touch = new TouchPoint(nextTouchPointId++, position); touchesBegan.Add(touch); } return touch.Id; }
private void addDebugFigureForTouch(TouchPoint touch) { GLDebug.DrawSquareScreenSpace(TouchManager.DEBUG_GL_TOUCH + touch.Id, touch.Position, 0, debugTouchSize, GLDebug.MULTIPLY, float.PositiveInfinity); }
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.NumberOfTouches >= 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.TouchPoint tp0 = TouchScript.TouchManager.Instance.ActiveTouches[0]; TouchScript.TouchPoint tp1 = TouchScript.TouchManager.Instance.ActiveTouches[1]; TouchScript.TouchPoint tp2 = TouchScript.TouchManager.Instance.ActiveTouches[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(); } } }
internal ITouch BeginTouch(Vector2 position, Tags tags) { TouchPoint touch; lock (touchesBegan) { touch = new TouchPoint(nextTouchId++, position, tags); touchesBegan.Add(touch); } return touch; }
internal void IgnoreTouch(TouchPoint touch) { }
/// <returns>Object's transform which has been hit or null otherwise.</returns> public Transform GetHitTarget(TouchPoint touch) { RaycastHit hit; Camera hitCamera; return GetHitTarget(touch, out hit, out hitCamera); } /// <summary> /// Checks if the touch has hit something. /// </summary> /// <param name="touch">The touch.</param> /// <param name="hit">Output RaycastHit.</param> /// <param name="hitCamera">Output camera which was used to hit an object.</param> /// <returns>Object's transform which has been hit or null otherwise.</returns> public Transform GetHitTarget(TouchPoint touch, out RaycastHit hit, out Camera hitCamera) { hit = new RaycastHit(); hitCamera = null; if (HitCameras == null) return null; foreach (var cam in HitCameras) { hitCamera = cam; var ray = cam.ScreenPointToRay(new Vector3(touch.Position.x, touch.Position.y, cam.nearClipPlane)); var hits = Physics.RaycastAll(ray); if (hits.Length == 0) continue; var minDist = float.PositiveInfinity; foreach (var rayHit in hits) { var dist = (rayHit.point - cam.transform.position).sqrMagnitude; if (dist < minDist) { minDist = dist; hit = rayHit; } } var hitTests = hit.transform.GetComponents<HitTest>(); if (hitTests.Length == 0) return hit.transform; var result = true; foreach (var test in hitTests) {
private void update(TouchPoint touch, Action<Transform, TouchPoint> process, Action<Gesture, TouchPoint> dispatch) { // WARNING! Arcane magic ahead! // gestures which got any touch points // needed because there's no order in dictionary activeGestures.Clear(); if (touch.Target != null) process(touch.Target, touch); var count = activeGestures.Count; for (var i = 0; i < count; i++) { var gesture = activeGestures[i]; if (gestureIsActive(gesture)) dispatch(gesture, touch); } }
private void processTargetBegan(Transform target, TouchPoint touch) { var containingList = gestureListPool.Get(); var endingList = gestureListPool.Get(); // gestures in the target's hierarchy which might affect gesture on the target getHierarchyContaining(target, containingList); // gestures on objects in the hierarchy from "root" to target getHierarchyEndingWith(target, endingList); var count = endingList.Count; for (var i = 0; i < count; i++) { var gesture = endingList[i]; // WARNING! Gestures might change during this loop. // For example when one of them recognizes. if (!gestureIsActive(gesture)) continue; var canReceiveTouches = true; var activeCount = containingList.Count; for (var j = 0; j < activeCount; j++) { var activeGesture = containingList[j]; if (gesture == activeGesture) continue; if ((activeGesture.State == Gesture.GestureState.Began || activeGesture.State == Gesture.GestureState.Changed) && (canPreventGesture(activeGesture, gesture))) { // there's a started gesture which prevents this one canReceiveTouches = false; break; } } if (canReceiveTouches && shouldReceiveTouch(gesture, touch)) activeGestures.Add(gesture); } gestureListPool.Release(containingList); gestureListPool.Release(endingList); }
/// <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; } }
private void doUpdateBegan(Gesture gesture, TouchPoint touch) { gesture.INTERNAL_TouchBegan(touch); }
/// <inheritdoc /> public int BeginTouch(Vector2 position, Tags tags, IDictionary<string, System.Object> properties) { TouchPoint touch; lock (touchesBegan) { touch = new TouchPoint(nextTouchId++, position, tags, properties); touchesBegan.Add(touch); } return touch.Id; }
private void processTarget(Transform target, TouchPoint touch) { // gestures on objects in the hierarchy from "root" to target var endingList = gestureListPool.Get(); getHierarchyEndingWith(target, endingList); var count = endingList.Count; for (var i = 0; i < count; i++) { var gesture = endingList[i]; if (!gestureIsActive(gesture)) continue; if (gesture.HasTouch(touch)) activeGestures.Add(gesture); } gestureListPool.Release(endingList); }
private void GetInput2() { // for Touch if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) { if (Input.touchCount == 2) { if (lastFingerVec == Vector3.zero) { lastFingerVec = (Input.GetTouch(0).position - Input.GetTouch(1).position).normalized; lastFingerPos = (Input.GetTouch(0).position + Input.GetTouch(1).position) / 2.0f; } else { moveVector = Vector3.zero; // 回転 Vector3 now_vec = (Input.GetTouch(0).position - Input.GetTouch(1).position).normalized; moveVector.x += Mathf.Rad2Deg * (Mathf.Atan2(lastFingerVec.y, lastFingerVec.x) - Mathf.Atan2(now_vec.y, now_vec.x)); float rot_x_max = 10.0f; if (moveVector.x < rot_x_max) { moveVector.x = -rot_x_max; } if (rot_x_max < moveVector.x) { moveVector.x = rot_x_max; } lastFingerVec = now_vec; // 傾き Vector3 now_pos = (Input.GetTouch(0).position + Input.GetTouch(1).position) / 2.0f; moveVector.y += (-100.0f * ((now_pos - lastFingerPos).y / Screen.height)); lastFingerPos = now_pos; } } else { ResetInput(); } } #if UNITY_STANDALONE_WIN else if (Application.platform == RuntimePlatform.WindowsPlayer && winTouch) { if (TouchScript.TouchManager.Instance.NumberOfTouches == 2) { TouchScript.TouchPoint pt0 = TouchScript.TouchManager.Instance.ActiveTouches[0]; TouchScript.TouchPoint pt1 = TouchScript.TouchManager.Instance.ActiveTouches[1]; if (lastFingerVec == Vector3.zero) { lastFingerVec = (pt0.Position - pt1.Position).normalized; lastFingerPos = (pt0.Position + pt1.Position) / 2.0f; } else { moveVector = Vector3.zero; // 回転 Vector3 now_vec = (pt0.Position - pt1.Position).normalized; moveVector.x += Mathf.Rad2Deg * (Mathf.Atan2(lastFingerVec.y, lastFingerVec.x) - Mathf.Atan2(now_vec.y, now_vec.x)); float rot_x_max = 10.0f; if (moveVector.x < rot_x_max) { moveVector.x = -rot_x_max; } if (rot_x_max < moveVector.x) { moveVector.x = rot_x_max; } lastFingerVec = now_vec; // 傾き Vector3 now_pos = (pt0.Position + pt1.Position) / 2.0f; moveVector.y += (-100.0f * ((now_pos - lastFingerPos).y / Screen.height)); lastFingerPos = now_pos; } } else { ResetInput(); } } #endif // for Mouse else { moveVector = Vector3.zero; if (Input.GetMouseButton(1)) { // 回転 moveVector.x = (oldMousePosition.x - Input.mousePosition.x) * ratioForMouse; // 傾き moveVector.y = (oldMousePosition.y - Input.mousePosition.y) * ratioForMouse; } else { ResetInput(); } oldMousePosition = Input.mousePosition; } }
private bool shouldReceiveTouch(Gesture gesture, TouchPoint touch) { bool result = true; if (GlobalGestureDelegate != null) result = GlobalGestureDelegate.ShouldReceiveTouch(gesture, touch); return result && gesture.ShouldReceiveTouch(touch); }
/// <summary> /// Returns cached instance of EventArgs. /// This cached EventArgs is reused throughout the library not to alocate new ones on every call. /// </summary> /// <param name="touch"> Touch for the event. </param> /// <returns>Cached EventArgs object.</returns> public static TouchEventArgs GetCachedEventArgs(TouchPoint touch) { if (instance == null) instance = new TouchEventArgs(); instance.Touch = touch; return instance; }