Scriptable Object

Posted Tekkaman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Scriptable Object相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

图书馆搜索引擎软件;iOS14桌面Scriptable精美脚本

Unity零基础到进阶 | Unity中Scriptable Object介绍学习

类转换:java.lang.String 不能转换为 org.mozilla.javascript.Scriptable

Unity零基础到进阶 | Unity中Scriptable Object介绍学习

AmplifyShaderEditor和Scriptable Render Pipline冲突解决方法

如何使用Scriptable Objects创建动态变量系统