有没有办法使用SceneManager类或类似的其他功能来保存我的Unity游戏?

huangapple go评论53阅读模式
英文:

Is there any way for me to save my Unity game using the SceneManager class or some other feature like it?

问题

我制作了一个简单的Minecraft风格的游戏,我想创建一个新场景,并复制我的当前(默认)场景的内容,以便“保存”游戏。我试图避免更复杂的解决方案,所以我要求最简单和最快的已知解决方案。谢谢。

英文:

I made a simple Minecraft like game and I'd like to create a new scene and copy the contents of my current(dafault) scene in order to "save" the game. I'm trying to avoid more complicated solutions so I'm asking for the simplest and fastest known solution. Thanks.

答案1

得分: 1

你想在游戏运行时进行这个操作,还是只是创建一个完全新的场景,以便您可以在复制的版本上进行工作?

如果您想进行后者,请进入文件浏览器 > Unity Game > Assets > 并将 UnityScene.scene 复制回您的资产文件夹,创建一个重复的场景。

如果您想在运行时执行此操作,您可以使用 DontDestroyOnLoad,这将防止您的场景销毁其对象,从而在您玩下一关时保留其内容。

英文:

Do you want to do this while the game is running or just make an entirely new scene with the contents you have right now, so that you can work on a duplicated version of that scene?

If you want to do the latter, go into file explorer > Unity Game > Assets > and copy the UnityScene.scene back into your assets folder- creating a dupe scene.

If you want to do this in runtime, you can do DontDestroyOnLoad and that prevents your scene from destroying its object- therefore preserving its contents while you play the next level.

答案2

得分: 1

最短的答案是:没有简单的方法来保存和加载游戏状态。

用快速的方式来做,最好的办法是购买一个能满足你所有需求的资源。
Asset Store 示例

手动处理的方式是:

  1. 你必须将游戏的所有数据存储到一个文件中。
    • 例如玩家:玩家位置,背包,技能,已击杀的怪物,统计数据等。
  2. 同样地,存储所有世界数据。
    • 在你的情况下,每个方块的位置以及它的类型。
  3. 重复以下步骤,直到你拥有创建新场景所需的所有信息。
  4. 创建一个脚本,将保存的文件中的信息加载到你当前的世界中。

如果你想了解更多:

Unity 3D 官方教程 - 保存和加载数据

英文:

The shortest answer for the question is: There is no easy way to save and load a game state.

To do in the quick way, the best idea is to buy a Asset that fulfill all your needs.<br>
Asset Store Example

The DO IT BY HAND way is:

  1. You have to store all data regarding your game into a file.
    • For example player: Player Position, Inventory, Skills, Monsters Killed, Statistics, etc.
  2. Store all world data as well.
    • In your case, position for every block and what type it is.
  3. Keep repeating steps bellow until you have all information that you need to create the new scene.
  4. Create a script that loads information from saved files into your current world.

If you want to learn more about it:

Unity 3D Official Course - Saving and Loading Data

huangapple
  • 本文由 发表于 2023年4月17日 07:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定