码迷,mamicode.com
首页 > 其他好文 > 详细

Scriptable Object

时间:2016-05-18 12:43:02      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:

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

Scriptable Object

标签:

原文地址:http://www.cnblogs.com/tekkaman/p/5504696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!