优雅的QSignleton (四) 通过属性器实现MonoSingleton
2024-10-21 06:35:43
大家都出去过周六了,而我却在家写代码T.T... 接下来介绍通过属性器实现MonoSingleton。 代码如下:
MonoSingletonProperty.cs
namespace QFramework.Example
{
using System.Collections;
using UnityEngine; class Class2MonoSingletonProperty : MonoBehaviour,ISingleton
{
public static Class2MonoSingletonProperty Instance
{
get { return QMonoSingletonProperty<Class2MonoSingletonProperty>.Instance; }
} public void Dispose()
{
QMonoSingletonProperty<Class2MonoSingletonProperty>.Dispose();
} public void OnSingletonInit()
{
Debug.Log(name + ":" + "OnSingletonInit");
} private void Awake()
{
Debug.Log(name + ":" + "Awake");
} private void Start()
{
Debug.Log(name + ":" + "Start");
} protected void OnDestroy()
{
Debug.Log(name + ":" + "OnDestroy");
}
} public class MonoSingletonProperty : MonoBehaviour
{
private IEnumerator Start()
{
var instance = Class2MonoSingletonProperty.Instance; yield return new WaitForSeconds(3.0f); instance.Dispose();
}
}
}
结果:
三秒之后,同样触发了OnDestroy事件
转载请注明地址:凉鞋的笔记:liangxiegame.com
更多内容
QFramework 地址:https://github.com/liangxiegame/QFramework
QQ 交流群:623597263
Unity 进阶小班:
- 主要训练内容:
- 框架搭建训练(第一年)
- 跟着案例学 Shader(第一年)
- 副业的孵化(第二年、第三年)
- 权益、授课形式等具体详情请查看《小班产品手册》:https://liangxiegame.com/master/intro
- 主要训练内容:
关注公众号:liangxiegame 获取第一时间更新通知及更多的免费内容。
最新文章
- 美团大众点评服务框架Pigeon
- 转-临界区对象TCriticalSection与TRTLCriticalSection的区别
- centos7 firewalld
- 去除 UINavigationController.navigationBar下方的横线
- ionic中返回上一页
- sublime ctags
- TWaver家族新成员 — Legolas工业自动化设计平台
- [转载]AxureRP 7.0部件详解(一)
- ok6410 android driver(8)
- C#创建Windows Service(Windows 服务)基础教程
- JAVA元运算符,一元运算符,二元运算符,三元运算符
- db2 identity列重置,reset/restart
- 足球3v3心得
- vue.js的学习中的简单案例
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(二)
- Excel藏的很深(1)
- content-type的几种取值
- API设计和命名
- tcpdump命令抓包参数
- Vue知识点(面试常见点)
热门文章
- 【Ubuntu】设置静态ip地址
- select操作大全
- Git读档
- Spring课程 Spring入门篇 4-4 Spring bean装配(下)之Autowired注解说明3 多选一 qualifier
- CentOS 7 学习笔记
- iDempiere 开发指南 Process(iDem后台进程)及插件的开发及部署
- microkernel architecture - Proxy
- Linux CentOS如何汉化系统
- JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
- DLRS(深度学习应用于推荐系统论文汇总--2017年8月整理)