public static bool TouchHitGameObject(SimTouch touch, out GameObject result, float rayCastDepth = 1500f) { result = null; //Raycast 3D Ray ray = Camera.main.ScreenPointToRay(touch.screenPosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, rayCastDepth)) { if (hit.collider != null) { result = hit.collider.gameObject; return true; } } //Raycast 2D Vector3 worldPosition = Camera.main.ScreenToWorldPoint(touch.screenPosition); RaycastHit2D hit2D = Physics2D.Raycast(new Vector2(worldPosition.x, worldPosition.y), Vector2.zero, rayCastDepth); if (hit2D.collider != null) { result = hit2D.collider.gameObject; return true; } //no cigar return false; }
public override void OnBeganTouch(SimTouch touch) { Debug.Log ("ON BEGAN TOUCH "+touch.time); GameObject target; if (InputHandler.TouchHitGameObject(touch, out target)) Debug.Log("Hit object: "+target.name); }
public override void OnMovedTouch(SimTouch touch) { if (isScrolling && touch.fingerID == scrollFinger) { if (allowScrolling) Scroll(touch.deltaScreenPosition); else isScrolling = false; } }
public override void OnBeganTouch(SimTouch touch) { if (allowScrolling) { if (!isScrolling && TouchHitNothing(touch)) { isScrolling = true; scrollFinger = touch.fingerID; } } }
public override void OnBeganTouch(SimTouch touch) { if (TouchHitTarget(touch, _gameObject)) { if (ShipPositionMarker.Instance.currentPort != this) LocationInfoPanel.Open(this); // if (ShipPositionMarker.Instance.TravelToPort(this)) // { // SoundManager.PlaySfx(Sfx.Click); // } } }
public static bool TouchHitNothing(SimTouch touch, float rayCastDepth = 1500f) { //Raycast 3D Ray ray = Camera.main.ScreenPointToRay(touch.screenPosition); if (Physics.Raycast(ray)) return false; //Raycast 2D Vector3 worldPosition = Camera.main.ScreenToWorldPoint(touch.screenPosition); RaycastHit2D hit2D = Physics2D.Raycast(new Vector2(worldPosition.x, worldPosition.y), Vector2.zero, rayCastDepth); if (hit2D.collider != null) return false; return true; }
private void HandleMouseEvents() { if (Input.GetMouseButtonDown(0)) { trackMouse = true; SimTouch touch = new SimTouch(); touch.fingerID = 1; touch.phase = TouchPhase.Began; touch.deltaTime = 0f; touch.time = Time.time; touch.screenPosition = Input.mousePosition; touch.deltaScreenPosition = Vector3.zero; lastTouches.Add(touch); } else if (trackMouse) { UpdateMouseTouch(1); } }
private void UpdateMouseTouch(int id) { SimTouch lastTouch = GetLastTouchWithID(id); SimTouch touch = new SimTouch(); touch.fingerID = id; touch.time = Time.time; touch.deltaTime = Time.time - lastTouch.time; touch.totalTime = lastTouch.totalTime + touch.deltaTime; touch.screenPosition = Input.mousePosition; touch.deltaScreenPosition = touch.screenPosition - lastTouch.screenPosition; if (Input.GetMouseButtonUp(0)) touch.phase = TouchPhase.Ended; else if (Input.GetMouseButton(0)) { if (screenRect.Contains(Input.mousePosition)) { if (touch.deltaScreenPosition == Vector3.zero) touch.phase = TouchPhase.Stationary; else touch.phase = TouchPhase.Moved; } else touch.phase = TouchPhase.Canceled; } lastTouches.Add(touch); lastTouches.Remove(lastTouch); if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) trackMouse = false; }
private void HandleTouchEvents() { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { SimTouch simTouch = new SimTouch(); simTouch.fingerID = touch.fingerId; simTouch.phase = touch.phase; simTouch.deltaTime = touch.deltaTime; simTouch.screenPosition = touch.position; simTouch.deltaScreenPosition = touch.deltaPosition; simTouch.time = Time.time; simTouch.totalTime = 0f; if (simTouch.phase != TouchPhase.Began) { SimTouch lastTouch = GetLastTouchWithID(touch.fingerId); simTouch.totalTime = lastTouch.totalTime + simTouch.deltaTime; lastTouches.Remove(lastTouch); } lastTouches.Add(simTouch); } } }
public override void OnEndedOrCanceledTouch(SimTouch touch) { if (isScrolling && touch.fingerID == scrollFinger) isScrolling = false; }
public virtual void OnStationaryTouch(SimTouch touch) { }
public virtual void OnMovedTouch(SimTouch touch) { }
public virtual void OnEndedOrCanceledTouch(SimTouch touch) { }
public virtual void OnBeganTouch(SimTouch touch) { }