MonoController.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MonoController : MonoBehaviour
{
private event UnityAction updateEvent;
// Start is called before the first frame update
void Start()
{
DontDestroyOnLoad(this.gameObject);//不会转场消失
}
// Update is called once per frame
void Update()
{
if (updateEvent != null)
updateEvent();//不为空执行
}
//给外部提供的 添加更新帧事件
public void AddUpdateListener(UnityAction fun)
{
updateEvent += fun;
}
//给外部提供的 移除更新帧事件
public void RemoveUpdateListener(UnityAction fun)
{
updateEvent -= fun;
}
}
MonoManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MonoManager : BaseManager<MonoManager>
{
private MonoController controller;
public MonoManager()
{
//保证MonoController的唯一
GameObject obj = new GameObject("MonoController");
controller = obj.AddComponent<MonoController>();
}
//给外部提供的 添加更新帧事件
public void AddUpdateListener(UnityAction fun)
{
controller.AddUpdateListener(fun);
}
//给外部提供的 移除更新帧事件
public void RemoveUpdateListener(UnityAction fun)
{
controller.RemoveUpdateListener(fun);
}
public Coroutine StartCoroutine(IEnumerator routine)
{
return controller.StartCoroutine(routine);
}
}