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");
}
}
private MonoTest test;
void Start()
{
MusicMgr.GetInstance.Init();
PoolMgr.GetInstance.Init();
test=new MonoTest();
test.AddListen();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.K))
{
test.Remove();
}
}
版权声明:本文为weixin_33950757原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。