大家都出去过周六了,而我却在家写代码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

更多内容

最新文章

  1. 美团大众点评服务框架Pigeon
  2. 转-临界区对象TCriticalSection与TRTLCriticalSection的区别
  3. centos7 firewalld
  4. 去除 UINavigationController.navigationBar下方的横线
  5. ionic中返回上一页
  6. sublime ctags
  7. TWaver家族新成员 — Legolas工业自动化设计平台
  8. [转载]AxureRP 7.0部件详解(一)
  9. ok6410 android driver(8)
  10. C#创建Windows Service(Windows 服务)基础教程
  11. JAVA元运算符,一元运算符,二元运算符,三元运算符
  12. db2 identity列重置,reset/restart
  13. 足球3v3心得
  14. vue.js的学习中的简单案例
  15. (NO.00003)iOS游戏简单的机器人投射游戏成形记(二)
  16. Excel藏的很深(1)
  17. content-type的几种取值
  18. API设计和命名
  19. tcpdump命令抓包参数
  20. Vue知识点(面试常见点)

热门文章

  1. 【Ubuntu】设置静态ip地址
  2. select操作大全
  3. Git读档
  4. Spring课程 Spring入门篇 4-4 Spring bean装配(下)之Autowired注解说明3 多选一 qualifier
  5. CentOS 7 学习笔记
  6. iDempiere 开发指南 Process(iDem后台进程)及插件的开发及部署
  7. microkernel architecture - Proxy
  8. Linux CentOS如何汉化系统
  9. JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
  10. DLRS(深度学习应用于推荐系统论文汇总--2017年8月整理)