文本系统重做完成
This commit is contained in:
@@ -1,72 +1,123 @@
|
||||
using AibisDream.Kit;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
public class EventSystemEx : SingletonBase<EventSystemEx>
|
||||
public class EventSystemEx : Singleton<EventSystemEx>
|
||||
{
|
||||
#region 状态
|
||||
|
||||
public bool isLocked;
|
||||
|
||||
#endregion
|
||||
|
||||
public GameObject pointerOverObj;
|
||||
public GameObject draggingObj;
|
||||
public GameObject holdingObj;
|
||||
|
||||
|
||||
private List<GameObject> pointerOverObjList;
|
||||
private List<GameObject> draggingObjList;
|
||||
private List<GameObject> holdingObjList;
|
||||
|
||||
#region 事件触发中转
|
||||
|
||||
public void OnPointerEnter(IInteraction interaction)
|
||||
{
|
||||
pointerOverObj = interaction.GetGameObject();
|
||||
EnumEventSystem.Global.Send(TriggerEnum.PointerEnter, interaction);
|
||||
if (!pointerOverObjList.Contains(interaction.GetGameObject()))
|
||||
{
|
||||
pointerOverObjList.Add(interaction.GetGameObject());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(IInteraction interaction)
|
||||
{
|
||||
if (pointerOverObj == interaction.GetGameObject())
|
||||
{
|
||||
EnumEventSystem.Global.Send(TriggerEnum.PointerExit, interaction);
|
||||
pointerOverObj = null;
|
||||
}
|
||||
pointerOverObjList.Remove(interaction.GetGameObject());
|
||||
}
|
||||
|
||||
public void OnPointerDown(IInteraction interaction)
|
||||
{
|
||||
EnumEventSystem.Global.Send(TriggerEnum.PointerDown, interaction);
|
||||
holdingObj = interaction.GetGameObject();
|
||||
if (!holdingObjList.Contains(interaction.GetGameObject()))
|
||||
{
|
||||
holdingObjList.Add(interaction.GetGameObject());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerUp(IInteraction interaction)
|
||||
{
|
||||
if (holdingObj == interaction.GetGameObject())
|
||||
holdingObjList.Remove(interaction.GetGameObject());
|
||||
}
|
||||
|
||||
public void OnDrag(IInteraction interaction)
|
||||
{
|
||||
if (!draggingObjList.Contains(interaction.GetGameObject()))
|
||||
{
|
||||
EnumEventSystem.Global.Send(TriggerEnum.PointerUp, interaction);
|
||||
holdingObj = null;
|
||||
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)
|
||||
{
|
||||
Debug.Log($"Dragging: {draggingObjList.Count}");
|
||||
Debug.Log($"Holding: {holdingObjList.Count}");
|
||||
return TriggerEnum.Dragging;
|
||||
}
|
||||
else if (pointerOverObjList.Count > 0)
|
||||
{
|
||||
Debug.Log($"PointerOver: {pointerOverObjList.Count}");
|
||||
return TriggerEnum.PointerOver;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TriggerEnum.None;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 单例必须的代码
|
||||
|
||||
private EventSystemEx()
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
PointerEnter,
|
||||
PointerExit,
|
||||
PointerDown,
|
||||
PointerUp
|
||||
None,
|
||||
Dragging,
|
||||
PointerOver
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user