using System;
using System.Collections.Generic;
public class MessageManager
{
static MessageManager mInstance;
public static MessageManager Instance
{
get
{
return mInstance ??= new MessageManager();
}
}
Dictionary> mMessageDict = new Dictionary>(32);
Dictionary mDispatchCacheDict = new Dictionary(16);
private MessageManager()
{
}
public void Suvscribe(string MessageManager, Action
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : SingletonBase
{
Action act;
protected override void Awake()
{
base.Awake();
DontDestroyOnLoad(this);
act = SuvFunc;
MessageManager.Instance.Suvscribe("abc", act);
MessageManager.Instance.Dispatch("abc");
}
private void SuvFunc(object[] obj)
{
Debug.Log("TestSuv");
}
protected override void OnDestroy()
{
base.OnDestroy();
MessageManager.Instance.Unsubscribe("abc");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingletonBase : MonoBehaviour where T : SingletonBase
{
private static T instance;
public static T Instance
{
get { return instance; }
}
protected virtual void Awake()
{
if (instance != null)
Destroy(gameObject);
else
instance = (T)this;
}
public static bool IsInitalized
{
get { return instance != null; }
}
protected virtual void OnDestroy()
{
if (instance == this)
{
instance = null;
}
}
}