少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
108
109
110
111
112
113
114
115
116
117
118
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, July 31, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class AttackButton : Button
    {
        const float PRESS_TRIGGERTIME = 0.2f;
        UIEvent m_AttackEvent = new UIEvent();
        public UIEvent attackEvent { get { return m_AttackEvent; } }
 
        bool m_IsDown = false;
        public bool isDown {
            get {
                if (Application.isMobilePlatform)
                {
                    return Input.touchCount > 0 && m_IsDown;
                }
                else
                {
                    return Input.GetMouseButton(0) && m_IsDown;
                }
            }
        }
 
        bool clickResponse = false;
        float pressTime = 0f;
        bool m_IsPress = false;
 
        public void AddListener(UnityAction _action)
        {
            if (attackEvent != null)
            {
                attackEvent.AddListener(_action);
            }
        }
 
        public void RemoveListener()
        {
            if (attackEvent != null)
            {
                attackEvent.RemoveAllListeners();
            }
        }
 
        public override void OnPointerDown(PointerEventData eventData)
        {
            base.OnPointerDown(eventData);
            m_IsDown = true;
            m_IsPress = false;
            clickResponse = true;
            pressTime = Time.time + PRESS_TRIGGERTIME;
        }
 
        public override void OnPointerUp(PointerEventData eventData)
        {
            base.OnPointerUp(eventData);
            m_IsDown = false;
            m_IsPress = false;
            clickResponse = false;
        }
 
        protected override void OnDisable()
        {
            m_IsDown = false;
            m_IsPress = false;
            clickResponse = false;
        }
 
        private void LateUpdate()
        {
            if (!isDown)
            {
                return;
            }
 
            if (Time.time > pressTime)
            {
                m_IsPress = true;
            }
 
            if (!m_IsPress && clickResponse)
            {
                if (attackEvent != null)
                {
                    attackEvent.Invoke();
                }
 
                EffectMgr.Instance.PlayUIEffect(1021, 1500, this.transform, false);
                clickResponse = false;
            }
 
            if (m_IsPress)
            {
                if (attackEvent != null)
                {
                    attackEvent.Invoke();
                }
            }
 
        }
 
    }
 
}