45 lines
969 B
C#
45 lines
969 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;
|
|
|
|
// Use this for initialization
|
|
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;
|
|
}
|
|
}
|