Scriptable Object
2016-05-18 11:58
381 查看
【Scriptable Object】
ScriptableObject 是一个可继承的Class,适用于存储大数据的情形。
Consider for example that you have made a prefab with a script which has an array of a million integers. The array occupies 4MB of memory and is owned by the prefab. Each time you instantiate that prefab, you will get a copy of that array. If you created 10 game objects, then you would end up with 40MB of array data for the 10 instances.
Unity serializes all primitive types, strings, arrays, lists, types specific to Unity such as Vector3 and your custom classes with the Serializable attribute as copies belonging to the object they were declared in.This means that if you created a ScriptableObject and stored the million integers in an array it declares then the array will be stored with that instance. The instances are thought to own their individual data.
If you have a script with a reference to the ScriptableObject with the million integers, Unity will only store a reference to the ScriptableObject in the script data. The ScriptableObject in turn stores the array. 10 instances of a prefab that has a reference to a ScriptableObject, that holds 4MB data, would total to roughly 4MB and not 40MB as discussed in the other example.
【CreateAssetMenuAttribute】
Mark a ScriptableObject-derived type to be automatically listed in the Assets/Create submenu, so that instances of the type can be easily created and stored in the project as ".asset" files.
在 ScriptableObject 类定义的上一行加上 [CreateAssetMenu] ,即可通过 Asset/Create 菜单来创建此 ScriptableObject 类的asset。
参考:
1、http://docs.unity3d.com/Manual/class-ScriptableObject.html
2、http://docs.unity3d.com/ScriptReference/CreateAssetMenuAttribute.html
ScriptableObject 是一个可继承的Class,适用于存储大数据的情形。
Consider for example that you have made a prefab with a script which has an array of a million integers. The array occupies 4MB of memory and is owned by the prefab. Each time you instantiate that prefab, you will get a copy of that array. If you created 10 game objects, then you would end up with 40MB of array data for the 10 instances.
Unity serializes all primitive types, strings, arrays, lists, types specific to Unity such as Vector3 and your custom classes with the Serializable attribute as copies belonging to the object they were declared in.This means that if you created a ScriptableObject and stored the million integers in an array it declares then the array will be stored with that instance. The instances are thought to own their individual data.
If you have a script with a reference to the ScriptableObject with the million integers, Unity will only store a reference to the ScriptableObject in the script data. The ScriptableObject in turn stores the array. 10 instances of a prefab that has a reference to a ScriptableObject, that holds 4MB data, would total to roughly 4MB and not 40MB as discussed in the other example.
【CreateAssetMenuAttribute】
Mark a ScriptableObject-derived type to be automatically listed in the Assets/Create submenu, so that instances of the type can be easily created and stored in the project as ".asset" files.
在 ScriptableObject 类定义的上一行加上 [CreateAssetMenu] ,即可通过 Asset/Create 菜单来创建此 ScriptableObject 类的asset。
参考:
1、http://docs.unity3d.com/Manual/class-ScriptableObject.html
2、http://docs.unity3d.com/ScriptReference/CreateAssetMenuAttribute.html
相关文章推荐
- Cloneable接口和Object的clone()方法
- [IOS/翻译]GCD-4 Managing Dispatch Objects
- objective-c内存管理的实现机制,并简述什么时候由你负责释放对象,什么时候不由你释放?
- 在Objective-C声明Block的几种方式
- Java NIO框架Netty教程(三) – Object对象传递
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Object-C之继承
- Xcode7 安装VVDocumenter-Xcode步骤
- [PWA] 13. New db and object store
- Objective-C ---NSArray(梳理整理)
- effective objective-c 2.0 笔记 第五章 :内存管理
- 读书笔记《iPhone应用开发从入门到精通》——Objective-C的内存管理
- Object Attributes
- objective-c中的self和super关键字
- org.springframework.jdbc.object
- Java中的Object类介绍
- Objective-C类成员变量深度剖析
- 多线程之NSThread和NSObject
- [__NSCFArray insertObject:atIndex:]: mutating method sent to immutable objec
- 字符串模版替换的方法MessageFormat.format(String pattern, Object ... arguments)