public static TouchGUI GetTouch(int aID) { TouchGUI touchGUI = new TouchGUI(); if (Input.touchCount > aID) { Touch touch = Input.GetTouch(aID); touchGUI.position = touch.position; touchGUI.phase = touch.phase; touchGUI.fingerId = touch.fingerId; touchGUI.deltaPosition = touch.deltaPosition; } #if (PC_MAC || UNITY_EDITOR) else { touchGUI.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); touchGUI.fingerId = 0; touchGUI.phase = TouchPhase.Ended; touchGUI.deltaPosition = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); if (Input.GetMouseButtonDown(aID)) //|| Input.anyKeyDown) { touchGUI.phase = TouchPhase.Began; } else if (Input.GetMouseButton(aID)) //|| Input.anyKey) { touchGUI.phase = TouchPhase.Moved; } } #endif return(touchGUI); }
public override bool TouchInsideButtonBounds(TouchGUI aTouch) { Ray ray = m_camera.ScreenPointToRay(new Vector3(aTouch.position.x, aTouch.position.y)); RaycastHit hit; Physics.Raycast(ray, out hit); return(hit.collider != null && hit.collider == targetCollider); }
void Update() { bool insideBounds = false; if (InputGUI.touches.Count > 0) { TouchGUI touch = InputGUI.touches[0]; if (TouchInsideButtonBounds(touch)) { insideBounds = true; switch (touch.phase) { case TouchPhase.Began: OnBeginPress(); break; case TouchPhase.Moved: break; case TouchPhase.Ended: if (m_pressing) { OnReleaseInBounds(); } break; } } } if (!insideBounds) { if (m_pressing) { OnOutOfBounds(); } } }
public abstract bool TouchInsideButtonBounds(TouchGUI aTouch);