优雅的QSignleton (三) 通过属性器实现Singleton
来源:互联网 发布:mac bash 3.2 编辑:程序博客网 时间:2024/05/16 08:41
接下来介绍,不通过继承的方式实现单例模式。大家都出去嗨了,而我却在家码代码...
代码如下:
- MonoSingletonProperty.cs
namespace QFramework.Example{ using UnityEngine; class Class2SignetonProperty : ISingleton { public static Class2SignetonProperty Instance { get { return QSingletonProperty<Class2SignetonProperty>.Instance; } } private Class2SignetonProperty() {} private static int mIndex = 0; public void OnSingletonInit() { mIndex++; } public void Dispose() { QSingletonProperty<Class2SignetonProperty>.Dispose(); } public void Log(string content) { Debug.Log("Class2SingletonProperty" + mIndex + ":" + content); } } public class SingletonProperty : MonoBehaviour { // Use this for initialization void Start () { Class2SignetonProperty.Instance.Log("Hello World!"); // delete current instance Class2SignetonProperty.Instance.Dispose(); // new instance Class2SignetonProperty.Instance.Log("Hello World!"); } }}
- 必须要实现OnSingletonInit()、和Dispose()方法。
- 使用这种方式的好处有很多,导出给Lua的时候只需简单封装一个Wrapper就可以用了,而不用每个父类都进行导出Lua。而且有的Lua插件对泛型支持的不是很好。
结果:
相关链接
- QSingleton地址
- QFramework地址
转载请注明地址:凉鞋的笔记
微信公众号:liangxiegame
output/writing/Unity游戏框架搭建
阅读全文
0 0
- 优雅的QSignleton (三) 通过属性器实现Singleton
- 优雅的QSignleton (四) 通过属性器实现MonoSingleton
- 优雅的QSignleton (一) Singleton单例实现
- 优雅的QSignleton (二) MonoSingleton单例实现
- 优雅的QSignleton (五) 优雅地进行GameObject命名
- Unity 游戏框架搭建 (十四) 优雅的QSignleton(零) QuickStart
- 通过延迟加载实现Singleton
- Singleton 三种实现方式
- 单例模式的三种实现方式:singleton
- Singleton的安全实现!
- Singleton的各种实现
- Singleton 的使用实现
- Singleton的各种实现
- singleton的实现代码
- singleton的实现
- Singleton的实现方式
- bean的scope属性和singleton属性
- C++实现singleton(三种方法实现)
- ionic2 基于ngx-translate实现多语言切换
- Spring Boot 官方文档学习(一)入门及使用
- 优雅的QSignleton (二) MonoSingleton单例实现
- 大学生们颤抖吧,中学生已经开始学Python了!
- 关于app的logo广告页的制作
- 优雅的QSignleton (三) 通过属性器实现Singleton
- 文化之旅
- Ubuntu 14.04 LTS 版本(仅对32位操作系统,i686)下,安装 Java SE Development Kit 8u152(JDK 1.8.0_152)
- python一行代码实现人脸识别
- jQuery中调用WebService方法小结
- Hibernate框架
- P1078 文化之旅
- MFC 编辑框回车闪退问题
- 如何在NVMe SSD上安装Win7?手把手教你