作用:让没有继承Mono的类可以开启协程,可以Update更新,统一管理Update
- public class MonoController : MonoBehaviour {
- private event UnityAction updateEvent;
-
- void Start() {
- DontDestroyOnLoad(this.gameObject);
- }
-
- void Update() {
- if (updateEvent != null)
- updateEvent();
- }
-
- // 给外部提供的添加帧更新事件的函数
- public void AddUpdateListener(UnityAction fun) {
- updateEvent += fun;
- }
-
- // 给外部提供的删除帧更新事件的函数
- public void RemoveUpdateListener(UnityAction fun) {
- updateEvent -= fun;
- }
- }
-
-
- // -----------------------------------------------------
- public class MonoMgr : BaseManager<MonoMgr> {
- private MonoController controller;
-
- public MonoMgr() {
- // 保证了MonoController对象的唯一性
- GameObject obj = new GameObject("MonoController");
- controller = obj.AddComponent
(); - }
-
- public void AddUpdateListen