创造你的世界
脚本编写
可编程对象
4min
ZepetoScriptableObject 支持 Unity ScriptableObject。ZepetoScriptableObject 是一个数据容器,可以保存大量数据,例如世界数据设置和角色选项。
要创建一个新的 ZepetoScriptableObject 文件,请单击项目面板左上角的 [+] 图标,或单击资产 → 创建 → ZEPETO → ScriptableObject。

新创建的 ZepetoScriptableObject 需要通过创建具有定义数据类的脚本进行连接。

创建一个新的 ZEPETOScript 文件,并声明您将用作成员变量的数据。
以下是一些可以用作数据的示例代码。
当您将 ZEPETOScript 与定义的数据类链接到 ZepetoScriptableObjects 时,您将在检查器窗口中看到这些数据,如下所示。

创建一个 ZEPETOScript 文件以从 ZepetoScriptableObject 中调用数据。
从 ZEPETOScript 导入 ZepetoScriptableObject,并导入您声明的数据类型。

在ZEPETOScript中声明ZepetoScriptableObject的属性。
在ZEPETOScript中打开检查器窗口,为ZepetoScriptableObject属性分配值,如下所示。

这个示例展示了如何使用ZepetoScriptableObject并访问它的值。
要访问原始类型的成员变量,请将其声明为通用类型或使用类型转换,如下面的示例所示。
查看ScriptableObject的完整代码示例。