How do I save/load the state of every gameObject in a sandbox game?

☆樱花仙子☆ 提交于 2019-12-11 06:32:13

问题


I am struggeling to grasp how to handle save/load of every GameObject in a Scene. I currently save data in a Json and it works fine, the part I'm struggeling with is the logic of saving an entire game state.

For example, I'm making a sandbox game where you can shop trees, hoe ground, plant crops, pick herbs, etc, etc. All of these interactable GameObjects are created from prefabs and that works fine. But I need to somehow save every GameObject and its state (i.e is a crop fully grown or not, etc) to a file that I can save/load every time I exit/enter a scene (or the game).

Take this scene I created below, All tiles (except the tall grass) are interactable, i.e I can cut down those trees, pick the flowers, and I planted some crops that have grown:

I cannot wrap my head around how to best save/load all this information. Say I save every GameObject in a file, then would I read that file and Instantiate each object at runtime every time I enter the scene? Is it even possible to save an entire GameObject and just Instantiate it from file? How would I best go about doing this? And this would also mean a scene would load differently depending on if it's the first time I enter it (Everything is in original state) and any time after that it will load from file (without creating a bunch of duplicates).

I use this method by Programmer to save/load data.

来源:https://stackoverflow.com/questions/45388307/how-do-i-save-load-the-state-of-every-gameobject-in-a-sandbox-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!