private IEnumerator LongTouch(Touch touch) { yield return(new WaitForSeconds(3f)); longTouch = true; RaycastHit hit = new RaycastHit(); if (Physics.Raycast(Camera.main.ScreenPointToRay(touch.position), out hit, Mathf.Infinity, LayerMask)) { try { hit.transform.gameObject.SendMessage("OnClick", Clickable.Click.LONG_TOUCH); } catch (Exception e) { Debug.LogError(e); } } else { OnBlindClick?.Invoke(this, new EventClickArgs(Clickable.Click.LONG_TOUCH)); } OnGeneralClick?.Invoke(this, new EventClickArgs(Clickable.Click.LONG_TOUCH)); }
private void TryToRaycast(Clickable.Click clickType) { // Do not raycast through UI element if (!EventSystem.current.IsPointerOverGameObject()) { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, LayerMask)) { try { hit.transform.gameObject.SendMessage("OnClick", clickType); } catch (Exception e) { Debug.LogError(e); } } else { OnBlindClick?.Invoke(this, new EventClickArgs(clickType)); } OnGeneralClick?.Invoke(this, new EventClickArgs(clickType)); } }
private void HandleTouch() { RaycastHit hit = new RaycastHit(); foreach (Touch touch in Input.touches) { // Do not raycast through UI element if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { if (touch.phase == TouchPhase.Began) { if (coroutine != null) { StopCoroutine(coroutine); } coroutine = LongTouch(touch); StartCoroutine(coroutine); if (Physics.Raycast(Camera.main.ScreenPointToRay(touch.position), out hit, Mathf.Infinity, LayerMask)) { try { hit.transform.gameObject.SendMessage("OnClick", Clickable.Click.TOUCH); } catch (Exception e) { Debug.LogError(e); } } else { OnBlindClick?.Invoke(this, new EventClickArgs(Clickable.Click.TOUCH)); } OnGeneralClick?.Invoke(this, new EventClickArgs(Clickable.Click.TOUCH)); } // NOTE: TouchPhase.Ended always ignores UI clicking check (IsPointerOverGameObject) if (touch.phase == TouchPhase.Ended) { if (longTouch) { longTouch = false; } else { StopCoroutine(coroutine); longTouch = false; if (Physics.Raycast(Camera.main.ScreenPointToRay(touch.position), out hit, Mathf.Infinity, LayerMask)) { try { hit.transform.gameObject.SendMessage("OnClick", Clickable.Click.TOUCH_ENDED); } catch (Exception e) { Debug.LogError(e); } } else { OnBlindClick?.Invoke(this, new EventClickArgs(Clickable.Click.TOUCH_ENDED)); } OnGeneralClick?.Invoke(this, new EventClickArgs(Clickable.Click.TOUCH_ENDED)); } } } } }
private void TryToRaycast(Clickable.Click clickType) { // Do not raycast through UI element if (!EventSystem.current.IsPointerOverGameObject()) { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, LayerMask)) { // try { if (clickType == Clickable.Click.MOUSE_HOVER) { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (hoveredObject == null) { hit.collider.transform.gameObject.SendMessage("OnHoverStart"); HoverStartTime = System.DateTime.UtcNow; hoveredObject = hit.collider.transform.gameObject; } else { if (!GameObject.ReferenceEquals(hit.collider.transform.gameObject, hoveredObject)) { hoveredObject.SendMessage("OnHoverEnd"); if (endingHover) { StopAllCoroutines(); endingHover = false; } hit.collider.transform.gameObject.SendMessage("OnHoverStart"); HoverStartTime = System.DateTime.UtcNow; hoveredObject = hit.collider.transform.gameObject; } else { if (endingHover) { StopAllCoroutines(); endingHover = false; HoverStartTime = System.DateTime.UtcNow; } } } //} catch (Exception e) { // Debug.LogError(e); //} } else { //hit.collider.transform.gameObject.SendMessage("OnClick", clickType); if (hoveredObject != null) { hoveredObject.transform.gameObject.SendMessage("OnClick", clickType); if (!endingHover) { StartCoroutine(HoverEnd()); } } } // } catch (Exception e) { // Debug.LogError(e); // } } else { if (hoveredObject != null) { hoveredObject.transform.gameObject.SendMessage("OnClick", clickType); if (!endingHover) { StartCoroutine(HoverEnd()); } } else { OnBlindClick?.Invoke(this, new EventClickArgs(clickType)); } } OnGeneralClick?.Invoke(this, new EventClickArgs(clickType)); } }