创造你的世界
脚本编写
可编程对象
4min
ZepetoScriptableObject 支持 Unity ScriptableObject。ZepetoScriptableObject 是一个数据容器,可以保存大量数据,例如世界数据设置和角色选项。
要创建一个新的 ZepetoScriptableObject 文件,请单击项目面板左上角的 [+] 图标,或单击资产 → 创建 → ZEPETO → ScriptableObject。
![Document image Document image](https://images.archbee.com/fCt3n1oCa8rgNJ8fw9I2N-ly1N62ko5k7yD_oi9a2Eg-20240904-102418.png?format=webp)
新创建的 ZepetoScriptableObject 需要通过创建具有定义数据类的脚本进行连接。
![Document image Document image](https://images.archbee.com/fCt3n1oCa8rgNJ8fw9I2N-UBN5P5kclKDUF0wl5s31n-20240904-102418.png?format=webp)
创建一个新的 ZEPETOScript 文件,并声明您将用作成员变量的数据。
以下是一些可以用作数据的示例代码。
当您将 ZEPETOScript 与定义的数据类链接到 ZepetoScriptableObjects 时,您将在检查器窗口中看到这些数据,如下所示。
![Document image Document image](https://images.archbee.com/fCt3n1oCa8rgNJ8fw9I2N-WxkBAYpAkQIw3rCI1VfT8-20240904-102418.png?format=webp)
创建一个 ZEPETOScript 文件以从 ZepetoScriptableObject 中调用数据。
从 ZEPETOScript 导入 ZepetoScriptableObject,并导入您声明的数据类型。
![Document image Document image](https://images.archbee.com/fCt3n1oCa8rgNJ8fw9I2N-WoXCJ6ZSrzFbrmoDprSmZ-20240904-102418.png?format=webp)
在ZEPETOScript中声明ZepetoScriptableObject的属性。
在ZEPETOScript中打开检查器窗口,为ZepetoScriptableObject属性分配值,如下所示。
![Document image Document image](https://images.archbee.com/fCt3n1oCa8rgNJ8fw9I2N-FlWp-r09qaGr43OQPrc7l-20240904-102418.png?format=webp)
这个示例展示了如何使用ZepetoScriptableObject并访问它的值。
要访问原始类型的成员变量,请将其声明为通用类型或使用类型转换,如下面的示例所示。
查看ScriptableObject的完整代码示例。