了解 SerializedPropertyType?

Understanding SerializedPropertyType?

我正在创建一个通用 class,它要求我检查其字段的 SerializedPropertyType,而且在大多数情况下,我知道 SerializedPropertyType 的每个值的含义,但是是我没有的两个值,API 文档没有提供可用信息,有问题的两个值是 SerializedPropertyType.ManagedReferenceSerializedPropertyType.FixedBufferSize.

ManagedReference 的页面显示“托管引用 属性”。作为描述,对于 FixedBufferSize,它指出“固定缓冲区大小 属性。”,两者都没有告诉我这些类型的用途。

具体问题不清楚。为了获得帮助,我会尝试通过您的尝试和您遇到的问题缩小问题范围以及代码片段。 如果它对“我不知道几种类型指的是什么,并且文档没有很好地解释我需要了解的类型”有任何帮助,您需要知道的是统一处理序列化本身以在检查器中显示字段,让您对编辑器进行编程 UI 等,因此您需要检查 Script Serialization 以检查哪些 class 是统一可序列化的。

对于您的情况,您很可能需要检查如何自定义序列化您的 class。第一步是如何编写一个简单的可序列化 class 继承自 Editor class,然后可能会转向更复杂的情况。

也可以检查是否已经有一些东西可以使用或启发你。 this 可能会有用。

Unity 的文档在查找特定文档页面时可能会很烦人。对于托管 属性,here 是一个有用的文档页面。如果 Unity 决定删除该页面,它会显示

Represents a property that references an object that does not derive from UnityEngine.Object.

This type is for fields that have the SerializeReference attribute, otherwise the object is stored inline (SerializedPropertyType.Generic).

至于 FixedBufferSize,我只能找到适度有用的文档,并且 SerializedProperty.fixedBufferSize, not SerializedPropertyType. I believe the fixedBufferSize is referring to a fixed buffer struct in C#, which you can read about here. The size is just a quick lookup for the physical size of the buffer - how many elements 包含在此缓冲区中。