简体   繁体   English

Unity 在构建中生成 ScriptableObject

[英]Unity make ScriptableObject on a build

I'm new to scriptable objects, but I've seen a lot of tutorials using them for an inventory system and recipes.我不熟悉可编写脚本的对象,但我看过很多教程将它们用于库存系统和配方。 My question is if it is possible for a future player of my game to create new "recipes" in the final build that will be saved as scriptable objects.我的问题是我的游戏的未来玩家是否有可能在最终版本中创建新的“配方”,并将其保存为可编写脚本的对象。 Similar in Minecraft where you can use data packs to create new recipes.与 Minecraft 类似,您可以在其中使用数据包创建新食谱。

ScriptableObjects aren't really intended to be used that way. ScriptableObjects 并不是真正打算以这种方式使用。 They are assets in your build, just like objects saved in your scenes during edit time.它们是您构建中的资产,就像在编辑时保存在场景中的对象一样。

One option could be to try to save them as Addressables or AssetBundles so the game could load them dynamically.一种选择是尝试将它们保存为 Addressables 或 AssetBundles,以便游戏可以动态加载它们。 I don't think any of those facilities are available at runtime, so you would have to jump through a lot of hoops to get the storage format correct.我认为这些功能在运行时都不可用,因此您必须克服很多困难才能获得正确的存储格式。 I'd recommend against that and just use regular object serialization to save stuff.我不建议这样做,只使用常规的 object 序列化来保存内容。

It's worth noting, when you run your game in the editor and directly update your ScriptableObjects at runtime, it will update the asset and will save with the project.值得注意的是,当您在编辑器中运行您的游戏并在运行时直接更新您的 ScriptableObjects 时,它会更新资产并与项目一起保存。 Although it might seem like its working, that only works in the editor.虽然它可能看起来很有效,但它只在编辑器中有效。 In a real build of your game it will not be saved, and will have it's original values every time you start your game (just like the scene objects all return to their original states).在你的游戏的真实构建中,它不会被保存,并且每次你开始你的游戏时都会有它的原始值(就像场景对象都恢复到它们的原始状态一样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM