备份CatanBuilding瘦身独立工程
This commit is contained in:
84
Assets/Scripts/UIExtend/UIButtonDouble.cs
Normal file
84
Assets/Scripts/UIExtend/UIButtonDouble.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using static UnityEngine.EventSystems.ExecuteEvents;
|
||||
|
||||
public class UIButtonDouble : Button
|
||||
{
|
||||
public int ExecuteCount = 1;
|
||||
public int curExecuteCount = 0;
|
||||
private ButtonClickedEvent m_OnDown = new ButtonClickedEvent();
|
||||
private ButtonClickedEvent m_OnUp = new ButtonClickedEvent();
|
||||
PointerEventData _pointerEventData;
|
||||
public PointerEventData PointerEventData => _pointerEventData;
|
||||
public ButtonClickedEvent onDown
|
||||
{
|
||||
get { return m_OnDown; }
|
||||
set { m_OnDown = value; }
|
||||
}
|
||||
|
||||
public ButtonClickedEvent onUp
|
||||
{
|
||||
get { return m_OnUp; }
|
||||
set { m_OnUp = value; }
|
||||
}
|
||||
public override void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
RaycastThrough(eventData, pointerClickHandler);
|
||||
base.OnPointerClick(eventData);
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
RaycastThrough(eventData, pointerDownHandler);
|
||||
m_OnDown.Invoke();
|
||||
base.OnPointerDown(eventData);
|
||||
}
|
||||
public override void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
RaycastThrough(eventData, pointerUpHandler);
|
||||
m_OnUp.Invoke();
|
||||
base.OnPointerUp(eventData);
|
||||
}
|
||||
public void RaycastThrough<T>(BaseEventData baseEventData, EventFunction<T> eventFunction) where T : IEventSystemHandler
|
||||
{
|
||||
_pointerEventData = (PointerEventData)baseEventData;
|
||||
|
||||
List<RaycastResult> raycastResults = new List<RaycastResult>();
|
||||
//当前处理的gameobject
|
||||
GameObject currentObj = gameObject ?? _pointerEventData.pointerDrag;
|
||||
//获取当前射线检测到的所有结果
|
||||
EventSystem.current.RaycastAll(_pointerEventData, raycastResults);
|
||||
curExecuteCount = 0;
|
||||
bool isExecute = false;
|
||||
for (int i = 0; i < raycastResults.Count; i++)
|
||||
{
|
||||
//}
|
||||
//foreach (var item in raycastResults)
|
||||
//{
|
||||
var item = raycastResults[i];
|
||||
GameObject nextObj = item.gameObject;
|
||||
if (nextObj != null && nextObj == currentObj)
|
||||
{
|
||||
isExecute = true;
|
||||
}
|
||||
if (isExecute && nextObj != null && nextObj != currentObj)
|
||||
{
|
||||
GameObject excuteObj = GetEventHandler<T>(nextObj);
|
||||
if (excuteObj != null && excuteObj != currentObj)
|
||||
{
|
||||
//执行下一层事件,如果你还需要继续执行下面层UI事件可以不return,我这里只检测下一层的,所以我循环一次就直接return
|
||||
Execute(excuteObj, _pointerEventData, eventFunction);
|
||||
}
|
||||
curExecuteCount++;
|
||||
if (curExecuteCount >= ExecuteCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user