private void TouchHandler() { Touch touch; //返回一个在触摸开始阶段时非触摸UI的触摸点 if (m_touchFingerId > -1) { touch = InputUtil.GetTouchWithFingerId(m_touchFingerId, false, TouchPhase.Moved, TouchPhase.Stationary); m_touchFingerId = touch.fingerId; } else { touch = InputUtil.GetFirstTouch(TouchPhase.Began, true); m_touchFingerId = touch.fingerId; } if (touch.fingerId > -1) { if (GetPositionOnActiveArea(touch.position, advancedOptions.activeArea)) { float h = touch.deltaPosition.x * 0.5f; if (!m_isRotateBegin) { m_isRotateBegin = true; onPreRotateEvent?.Invoke(h); } Rotate(h); } } }
private void CheckUiHandleInput() { if (Input.touchSupported) { if (m_inTouchableAreaTouchDown) { //触摸按下过程中... Touch touch = InputUtil.GetTouchWithFingerId(m_fingerIdRecord, false, TouchPhase.Moved, TouchPhase.Stationary); if (touch.fingerId > -1) { OnUiInputTouchMoved(touch.position); } //判断触摸释放 touch = InputUtil.GetTouchWithFingerId(m_fingerIdRecord, false, TouchPhase.Canceled, TouchPhase.Ended); if (touch.fingerId > -1) { OnUiInputTouchEnded(touch.position); } } else { //判断触摸按下 Touch touch = InputUtil.GetFirstTouch(TouchPhase.Began, false); if (touch.fingerId > -1) { bool inTouchableArea = RectTransformUtility.RectangleContainsScreenPoint(m_touchableArea, touch.position); if (inTouchableArea) { m_fingerIdRecord = touch.fingerId; OnUiInputTouchBegan(touch.position); } } } } else { if (m_inTouchableAreaTouchDown) { //鼠标按下过程中... OnUiInputTouchMoved(Input.mousePosition); //判断鼠标释放 if (Input.GetMouseButtonUp(0)) { OnUiInputTouchEnded(Input.mousePosition); } } else { //判断鼠标按下 if (Input.GetMouseButtonDown(0)) { bool inTouchableArea = RectTransformUtility.RectangleContainsScreenPoint(m_touchableArea, Input.mousePosition); if (inTouchableArea) { OnUiInputTouchBegan(Input.mousePosition); } } } } }