120 lines
3.2 KiB
C#
120 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using AibisDream.Kit;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Framework
|
|
{
|
|
public class EventSystemEx : Singleton<EventSystemEx>
|
|
{
|
|
#region 状态
|
|
|
|
public bool isLocked;
|
|
|
|
#endregion
|
|
|
|
private List<GameObject> pointerOverObjList;
|
|
private List<GameObject> draggingObjList;
|
|
private List<GameObject> holdingObjList;
|
|
|
|
#region 事件触发中转
|
|
|
|
public void OnPointerEnter(IInteraction interaction)
|
|
{
|
|
if (!pointerOverObjList.Contains(interaction.GetGameObject()))
|
|
{
|
|
pointerOverObjList.Add(interaction.GetGameObject());
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(IInteraction interaction)
|
|
{
|
|
pointerOverObjList.Remove(interaction.GetGameObject());
|
|
}
|
|
|
|
public void OnPointerDown(IInteraction interaction)
|
|
{
|
|
if (!holdingObjList.Contains(interaction.GetGameObject()))
|
|
{
|
|
holdingObjList.Add(interaction.GetGameObject());
|
|
}
|
|
}
|
|
|
|
public void OnPointerUp(IInteraction interaction)
|
|
{
|
|
holdingObjList.Remove(interaction.GetGameObject());
|
|
}
|
|
|
|
public void OnDrag(IInteraction interaction)
|
|
{
|
|
if (!draggingObjList.Contains(interaction.GetGameObject()))
|
|
{
|
|
draggingObjList.Add(interaction.GetGameObject());
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(IInteraction interaction)
|
|
{
|
|
draggingObjList.Remove(interaction.GetGameObject());
|
|
}
|
|
|
|
public void OnBeginDrag(IInteraction interaction)
|
|
{
|
|
if (!draggingObjList.Contains(interaction.GetGameObject()))
|
|
{
|
|
draggingObjList.Add(interaction.GetGameObject());
|
|
}
|
|
}
|
|
|
|
public TriggerEnum GetPointerState()
|
|
{
|
|
if (holdingObjList.Count > 0 || draggingObjList.Count > 0)
|
|
{
|
|
return TriggerEnum.Dragging;
|
|
}
|
|
else if (pointerOverObjList.Count > 0)
|
|
{
|
|
return TriggerEnum.PointerOver;
|
|
}
|
|
else
|
|
{
|
|
return TriggerEnum.None;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 单例必须的代码
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
pointerOverObjList = new List<GameObject>();
|
|
draggingObjList = new List<GameObject>();
|
|
holdingObjList = new List<GameObject>();
|
|
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, ClearAll);
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, ClearAll);
|
|
}
|
|
|
|
private void ClearAll()
|
|
{
|
|
pointerOverObjList.Clear();
|
|
draggingObjList.Clear();
|
|
holdingObjList.Clear();
|
|
}
|
|
|
|
public override void OnSingletonDestroy()
|
|
{
|
|
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameStart, ClearAll);
|
|
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameQuit, ClearAll);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public enum TriggerEnum
|
|
{
|
|
None,
|
|
Dragging,
|
|
PointerOver
|
|
}
|
|
} |