49 lines
923 B
C#
49 lines
923 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
/// <summary>
|
|
/// Mono的管理类
|
|
/// 1.声明周期函数
|
|
/// 2.事件
|
|
/// 3.协程
|
|
/// </summary>
|
|
public class MonoController : MonoBehaviour
|
|
{
|
|
private event UnityAction updateEvent;
|
|
|
|
void Start()
|
|
{
|
|
DontDestroyOnLoad(this.gameObject);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (updateEvent != null)
|
|
{
|
|
updateEvent();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 给外部提供的添加帧更新事件的函数
|
|
/// </summary>
|
|
/// <param name="fun"></param>
|
|
public void AddUpdateListener(UnityAction fun)
|
|
{
|
|
updateEvent += fun;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提供给外部 用于移除帧更新事件函数
|
|
/// </summary>
|
|
/// <param name="fun"></param>
|
|
public void RemoveUpdateListener(UnityAction fun)
|
|
{
|
|
updateEvent -= fun;
|
|
}
|
|
|
|
}
|