| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Sunday, September 10, 2017 |
| | | //-------------------------------------------------------- |
| | | using UnityEngine; |
| | | using System.Collections; |
| | | using UnityEngine.UI; |
| | | using UnityEngine.EventSystems; |
| | | using System; |
| | | // //-------------------------------------------------------- |
| | | // // [Author]: 第二世界 |
| | | // // [ Date ]: Sunday, September 10, 2017 |
| | | // //-------------------------------------------------------- |
| | | // using UnityEngine; |
| | | // using System.Collections; |
| | | // using UnityEngine.UI; |
| | | // using UnityEngine.EventSystems; |
| | | // using System; |
| | | |
| | | namespace vnxbqy.UI |
| | | { |
| | | // namespace vnxbqy.UI |
| | | // { |
| | | |
| | | public class UI3DModelInteractProcessor : MonoBehaviour |
| | | { |
| | | public event Action clickEvent; |
| | | public event Action<Vector2> beginDragEvent; |
| | | public event Action<Vector2> endDragEvent; |
| | | public event Action<Vector2> dragingEvent; |
| | | // public class UI3DModelInteractProcessor : MonoBehaviour |
| | | // { |
| | | // public event Action clickEvent; |
| | | // public event Action<Vector2> beginDragEvent; |
| | | // public event Action<Vector2> endDragEvent; |
| | | // public event Action<Vector2> dragingEvent; |
| | | |
| | | RectTransform m_RectTransform; |
| | | public RectTransform rectTransform { |
| | | get { return m_RectTransform; } |
| | | set { |
| | | m_RectTransform = value; |
| | | } |
| | | } |
| | | // RectTransform m_RectTransform; |
| | | // public RectTransform rectTransform { |
| | | // get { return m_RectTransform; } |
| | | // set { |
| | | // m_RectTransform = value; |
| | | // } |
| | | // } |
| | | |
| | | bool isDown = false; |
| | | float downTime = 0f; |
| | | // bool isDown = false; |
| | | // float downTime = 0f; |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | if (Input.GetMouseButtonDown(0)) |
| | | { |
| | | OnPointerDown(); |
| | | } |
| | | // private void LateUpdate() |
| | | // { |
| | | // if (Input.GetMouseButtonDown(0)) |
| | | // { |
| | | // OnPointerDown(); |
| | | // } |
| | | |
| | | if (Input.GetMouseButton(0)) |
| | | { |
| | | OnPointerDrag(); |
| | | } |
| | | // if (Input.GetMouseButton(0)) |
| | | // { |
| | | // OnPointerDrag(); |
| | | // } |
| | | |
| | | if (Input.GetMouseButtonUp(0)) |
| | | { |
| | | OnPointerUp(); |
| | | } |
| | | } |
| | | // if (Input.GetMouseButtonUp(0)) |
| | | // { |
| | | // OnPointerUp(); |
| | | // } |
| | | // } |
| | | |
| | | void OnPointerDown() |
| | | { |
| | | if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, CameraManager.uiCamera)) |
| | | { |
| | | isDown = true; |
| | | downTime = Time.time; |
| | | if (beginDragEvent != null) |
| | | { |
| | | beginDragEvent(Input.mousePosition); |
| | | } |
| | | } |
| | | // void OnPointerDown() |
| | | // { |
| | | // if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, CameraManager.uiCamera)) |
| | | // { |
| | | // isDown = true; |
| | | // downTime = Time.time; |
| | | // if (beginDragEvent != null) |
| | | // { |
| | | // beginDragEvent(Input.mousePosition); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | // } |
| | | |
| | | void OnPointerDrag() |
| | | { |
| | | if (!isDown) |
| | | { |
| | | return; |
| | | } |
| | | // void OnPointerDrag() |
| | | // { |
| | | // if (!isDown) |
| | | // { |
| | | // return; |
| | | // } |
| | | |
| | | if (dragingEvent != null) |
| | | { |
| | | dragingEvent(Input.mousePosition); |
| | | } |
| | | } |
| | | // if (dragingEvent != null) |
| | | // { |
| | | // dragingEvent(Input.mousePosition); |
| | | // } |
| | | // } |
| | | |
| | | void OnPointerUp() |
| | | { |
| | | if (isDown) |
| | | { |
| | | if (Time.time - downTime < 0.3f) |
| | | { |
| | | if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, CameraManager.uiCamera)) |
| | | { |
| | | OnPointerClick(); |
| | | } |
| | | } |
| | | // void OnPointerUp() |
| | | // { |
| | | // if (isDown) |
| | | // { |
| | | // if (Time.time - downTime < 0.3f) |
| | | // { |
| | | // if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, CameraManager.uiCamera)) |
| | | // { |
| | | // OnPointerClick(); |
| | | // } |
| | | // } |
| | | |
| | | if (endDragEvent != null) |
| | | { |
| | | endDragEvent(Input.mousePosition); |
| | | } |
| | | } |
| | | // if (endDragEvent != null) |
| | | // { |
| | | // endDragEvent(Input.mousePosition); |
| | | // } |
| | | // } |
| | | |
| | | isDown = false; |
| | | } |
| | | // isDown = false; |
| | | // } |
| | | |
| | | void OnPointerClick() |
| | | { |
| | | if (clickEvent != null) |
| | | { |
| | | clickEvent(); |
| | | } |
| | | } |
| | | } |
| | | // void OnPointerClick() |
| | | // { |
| | | // if (clickEvent != null) |
| | | // { |
| | | // clickEvent(); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | // } |
| | | |
| | | |
| | | |