Health/Assets/Scripts/EventManager.cs

88 lines
2.2 KiB
C#
Raw Normal View History

2023-11-07 13:55:35 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public class EventManager : MonoSingleton<EventManager>
{
public delegate void EventHandler(params object[] args);
2023-11-10 08:12:37 +00:00
private Dictionary<YogaEventType, Action> _actionDic = new Dictionary<YogaEventType, Action>();
private Dictionary<YogaEventType, EventHandler> _actionsDic = new Dictionary<YogaEventType, EventHandler>();
public void AddEventListener(YogaEventType eventName, Action handler)
2023-11-07 13:55:35 +00:00
{
if (!_actionDic.ContainsKey(eventName))
{
_actionDic.Add(eventName, handler);
}
else
{
_actionDic[eventName] -= handler;
_actionDic[eventName] += handler;
}
}
2023-11-10 08:12:37 +00:00
public void RemoveEventListener(YogaEventType eventName, Action handler)
2023-11-07 13:55:35 +00:00
{
if (!_actionDic.ContainsKey(eventName))
return;
_actionDic[eventName] -= handler;
}
2023-11-10 08:12:37 +00:00
public void Dispatch(YogaEventType eventName)
2023-11-07 13:55:35 +00:00
{
if (!_actionDic.ContainsKey(eventName))
return;
_actionDic[eventName]?.Invoke();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
2023-11-10 08:12:37 +00:00
public void AddEventListener(YogaEventType eventName, EventHandler handler)
2023-11-07 13:55:35 +00:00
{
if (!_actionsDic.ContainsKey(eventName))
{
_actionsDic.Add(eventName, handler);
}
else
{
_actionsDic[eventName] -= handler;
_actionsDic[eventName] += handler;
}
}
2023-11-10 08:12:37 +00:00
public void RemoveEventListener(YogaEventType eventName, EventHandler handler)
2023-11-07 13:55:35 +00:00
{
if (!_actionsDic.ContainsKey(eventName))
return;
_actionsDic[eventName] -= handler;
}
2023-11-10 08:12:37 +00:00
public void Dispatch(YogaEventType eventName, params object[] param)
2023-11-07 13:55:35 +00:00
{
if (!_actionsDic.ContainsKey(eventName))
return;
_actionsDic[eventName]?.Invoke(param);
}
2023-11-10 08:12:37 +00:00
}
public enum YogaEventType
{
StartMotionCapture,
StopMotionCapture,
EstimateAction,
2023-11-10 08:13:03 +00:00
ScoreUpdate,
GetActionBasePoint,
PoseEstimate,
ActionSuccess,
ActionFailed,
PlayAnimation,
UpdateProgress,
2023-11-14 17:01:48 +00:00
ShowHint,
ShowMessage,
2023-11-22 12:34:04 +00:00
ChangeCaptureCameraDevice,
2023-11-07 13:55:35 +00:00
}