先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
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;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|