RandomGFGoStop/Assets/Scripts/SingletonManagers/Managers/EventManager.cs

261 lines
7.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum EEventType
{
OnStartNormalGame,
OnChallengeStart,
OnReturnToHome,
OnReturnToHunting,
OnSynchronizeScore,
OnSynchronizeGold,
OnSynchronizeHeart,
OnSynchronizeKey,
OnSynchronizeAIChllengeModeAIData,
OnInitializeGame,
OnDistributeCardCompletedToCenter,
OnSynchronizeGameData,
MoveToStore_Heart,
MoveToStore_Heart_DuringGame,
MoveToStore_Key,
OnReturnFullView,
OnGameEnd,
OnSynchronizeNormalGameData,
OnReturnToGameFromStore,
/// <summary> [ECardType] </summary>
OnDiscard,
/// <summary> [int] textureIndex [string] script </summary>
OnClickFullView,
ShowPanel,
}
public class EventManager : MonoBehaviour
{
private Dictionary<EEventType, System.Action> _dicBasicEvents_none;
private Dictionary<EEventType, System.Action<object>> _dicBasicEvents_one;
private Dictionary<EEventType, System.Action<object, object>> _dicBasicEvents_two;
private Dictionary<EEventType, System.Action<object, object, object>> _dicBasicEvents_three;
private Dictionary<EEventType, System.Action<object, object, object, object>> _dicBasicEvents_four;
private void Awake()
{
_dicBasicEvents_none = new Dictionary<EEventType, System.Action>();
_dicBasicEvents_one = new Dictionary<EEventType, System.Action<object>>();
_dicBasicEvents_two = new Dictionary<EEventType, System.Action<object, object>>();
_dicBasicEvents_three = new Dictionary<EEventType, System.Action<object, object, object>>();
_dicBasicEvents_four = new Dictionary<EEventType, System.Action<object, object, object, object>>();
}
#region ## Regist and Remove ##
// Regist =====================================================================================
public void RegistEvent(EEventType evtType, System.Action action)
{
if (_dicBasicEvents_none.ContainsKey(evtType))
{
_dicBasicEvents_none[evtType] += action;
}
else
{
_dicBasicEvents_none.Add(evtType, action);
}
}
public void RegistEvent(EEventType evtType, System.Action<object> action)
{
if (_dicBasicEvents_one.ContainsKey(evtType))
{
_dicBasicEvents_one[evtType] += action;
}
else
{
_dicBasicEvents_one.Add(evtType, action);
}
}
public void RegistEvent(EEventType evtType, System.Action<object, object> action)
{
if (_dicBasicEvents_two.ContainsKey(evtType))
{
_dicBasicEvents_two[evtType] += action;
}
else
{
_dicBasicEvents_two.Add(evtType, action);
}
}
public void RegistEvent(EEventType evtType, System.Action<object, object, object> action)
{
if (_dicBasicEvents_three.ContainsKey(evtType))
{
_dicBasicEvents_three[evtType] += action;
}
else
{
_dicBasicEvents_three.Add(evtType, action);
}
}
public void RegistEvent(EEventType evtType, System.Action<object, object, object, object> action)
{
if (_dicBasicEvents_four.ContainsKey(evtType))
{
_dicBasicEvents_four[evtType] += action;
}
else
{
_dicBasicEvents_four.Add(evtType, action);
}
}
// Remove =====================================================================================
public void RemoveEvent(EEventType evtType, System.Action action)
{
if (_dicBasicEvents_none.ContainsKey(evtType))
{
_dicBasicEvents_none[evtType] -= action;
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"{nameof(_dicBasicEvents_none)}.{evtType} is Already Empry In Dictionary.");
#endif
}
}
public void RemoveEvent(EEventType evtType, System.Action<object> action)
{
if (_dicBasicEvents_one.ContainsKey(evtType))
{
_dicBasicEvents_one[evtType] -= action;
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"{nameof(_dicBasicEvents_one)}.{evtType} is Already Empry In Dictionary.");
#endif
}
}
public void RemoveEvent(EEventType evtType, System.Action<object, object> action)
{
if (_dicBasicEvents_two.ContainsKey(evtType))
{
_dicBasicEvents_two[evtType] -= action;
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"{nameof(_dicBasicEvents_two)}.{evtType} is Already Empry In Dictionary.");
#endif
}
}
public void RemoveEvent(EEventType evtType, System.Action<object, object, object> action)
{
if (_dicBasicEvents_three.ContainsKey(evtType))
{
_dicBasicEvents_three[evtType] -= action;
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"{nameof(_dicBasicEvents_three)}.{evtType} is Already Empry In Dictionary.");
#endif
}
}
public void RemoveEvent(EEventType evtType, System.Action<object, object, object, object> action)
{
if (_dicBasicEvents_four.ContainsKey(evtType))
{
_dicBasicEvents_four[evtType] -= action;
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"{nameof(_dicBasicEvents_four)}.{evtType} is Already Empry In Dictionary.");
#endif
}
}
#endregion
#region ## Invoke ##
public void InvokeEvent(EEventType type)
{
if (_dicBasicEvents_none.ContainsKey(type))
{
_dicBasicEvents_none[type]?.Invoke();
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"\n{nameof(EventManager)}.{nameof(_dicBasicEvents_none)} has not {type}.\n Please Check.\n");
#endif
}
}
public void InvokeEvent(EEventType type, object param1)
{
if (_dicBasicEvents_one.ContainsKey(type))
{
_dicBasicEvents_one[type]?.Invoke(param1);
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"\n{nameof(EventManager)}.{nameof(_dicBasicEvents_one)} has not {type}.\n Please Check.\n");
#endif
}
}
public void InvokeEvent(EEventType type, object param1, object param2)
{
if (_dicBasicEvents_two.ContainsKey(type))
{
_dicBasicEvents_two[type]?.Invoke(param1, param2);
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"\n{nameof(EventManager)}.{nameof(_dicBasicEvents_two)} has not {type}.\n Please Check.\n");
#endif
}
}
public void InvokeEvent(EEventType type, object param1, object param2, object param3)
{
if (_dicBasicEvents_three.ContainsKey(type))
{
_dicBasicEvents_three[type]?.Invoke(param1, param2, param3);
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"\n{nameof(EventManager)}.{nameof(_dicBasicEvents_three)} has not {type}.\n Please Check.\n");
#endif
}
}
public void InvokeEvent(EEventType type, object param1, object param2, object param3, object param4)
{
if (_dicBasicEvents_four.ContainsKey(type))
{
_dicBasicEvents_four[type]?.Invoke(param1, param2, param3, param4);
}
else
{
#if UNITY_EDITOR
Debug.LogWarning($"\n{nameof(EventManager)}.{nameof(_dicBasicEvents_four)} has not {type}.\n Please Check.\n");
#endif
}
}
#endregion
}