using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonoController : MonoBehaviour
{
private Action callBack = null;
void Update()
{
this.callBack?.Invoke();
}
public void AddListener(Action callBack)
{
this.callBack += callBack;
}
public void RemoveListener(Action callBack)
{
this.callBack -= callBack;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MonoMgr : BaseManager<MonoMgr>
{
private MonoController controller;
public MonoMgr()
{
GameObject mono=new GameObject("Mono");
mono.AddComponent<MonoController>();
controller= mono.GetComponent<MonoController>();
}
public void AddListener(Action callBack)
{
controller.AddListener(callBack);
}
public void RemoveListener(Action callBack)
{
controller.RemoveListener(callBack);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonoTest
{
public void AddListen()
{
MonoMgr.GetInstance.AddListener(DebugInfo);
}
public void Remove()
{
MonoMgr.GetInstance.RemoveListener(DebugInfo);
}
private void DebugInfo()
{
Debug.Log("Test");
}
}