少年修仙传客户端代码仓库
hch
4 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Sunday, September 10, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
 
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;
 
        RectTransform m_RectTransform;
        public RectTransform rectTransform {
            get { return m_RectTransform; }
            set {
                m_RectTransform = value;
            }
        }
 
        bool isDown = false;
        float downTime = 0f;
 
        private void LateUpdate()
        {
            if (Input.GetMouseButtonDown(0))
            {
                OnPointerDown();
            }
 
            if (Input.GetMouseButton(0))
            {
                OnPointerDrag();
            }
 
            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 OnPointerDrag()
        {
            if (!isDown)
            {
                return;
            }
 
            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();
                    }
                }
 
                if (endDragEvent != null)
                {
                    endDragEvent(Input.mousePosition);
                }
            }
 
            isDown = false;
        }
 
        void OnPointerClick()
        {
            if (clickEvent != null)
            {
                clickEvent();
            }
        }
    }
 
}