-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouchableImage.cs
85 lines (65 loc) · 2.09 KB
/
TouchableImage.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class TouchableImage : MonoBehaviour,IPointerClickHandler
{
public string imageName = "unname image";
public bool bPassEvent = false;
// Start is called before the first frame update
void Start()
{
}
#region IPointerClickHandler implementation
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log(imageName + " click!");
//是否向下传递事件
if (bPassEvent)
{
//PassEvent(eventData, ExecuteEvents.submitHandler);
PassEvent(eventData, ExecuteEvents.pointerClickHandler);
}
}
#endregion
public void PassEvent<T>(PointerEventData data,ExecuteEvents.EventFunction<T> function)
where T:IEventSystemHandler
{
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(data, results);
GameObject current = data.pointerCurrentRaycast.gameObject;
GameObject selfObj = gameObject;
int selfOrder = -1;
for (int i = 0; i < results.Count; i++)
{
//if (current != results[i].gameObject)
//{
// ExecuteEvents.Execute(results[i].gameObject, data, function);
//}
//改进一下,只向下传递,不再向上执行,避免死循环
if (selfOrder == -1)
{
//还没获取到自己的order
if (gameObject == results[i].gameObject)
{
selfOrder = i;
}
}
else
{
//已经获取到了
if (gameObject != results[i].gameObject)
{
ExecuteEvents.Execute(results[i].gameObject, data, function);
//只传一层
break;
}
}
}
}
// Update is called once per frame
//void Update()
//{
//}
}