- MonoSingleton.cs
namespace QFramework.Example
{
using System.Collections;
using UnityEngine;
class Class2MonoSingleton : QMonoSingleton<Class2MonoSingleton>
{
public override void OnSingletonInit()
{
Debug.Log(this.name + ":" + "OnSingletonInit");
}
private void Awake()
{
Debug.Log(this.name + ":" + "Awake");
}
private void Start()
{
Debug.Log(this.name + ":" + "Start");
}
protected override void OnDestroy()
{
base.OnDestroy();
Debug.Log(this.name + ":" + "OnDestroy");
}
}
public class MonoSingleton : MonoBehaviour
{
private IEnumerator Start()
{
var instance = Class2MonoSingleton.Instance;
yield return new WaitForSeconds(3.0f);
instance.Dispose();
}
}
}
结果:
三秒之后,单例GameObject消失,并且触发了OnDestroy事件。
转载请注明地址:凉鞋的笔记:liangxiegame.com
更多内容
QFramework 地址:https://github.com/liangxiegame/QFramework
QQ 交流群:623597263
-
Unity 进阶小班:
- 主要训练内容:
- 框架搭建训练(第一年)
- 跟着案例学 Shader(第一年)
- 副业的孵化(第二年、第三年)
- 权益、授课形式等具体详情请查看《小班产品手册》:https://liangxiegame.com/master/intro
- 主要训练内容:
-
关注公众号:liangxiegame 获取第一时间更新通知及更多的免费内容。