godot-start/doc/demo14_file/file.md

1.3 KiB
Raw Blame History

1. godot的文件系统

Image text Image text

  • 资源路径
访问资源时使用主机OS文件系统布局可能很麻烦且不可移植。为了解决这个问题创建了特殊路径 res://。
路径res://将始终指向项目根目录 (project.godot所在的位置因此res://project.godot始终有效)
仅当从编辑器本地运行项目时,此文件系统才是读写的。
导出时或在其他设备例如手机或控制台或从DVD运行上运行时文件系统将变为只读状态并且将不再允许写入。 

Image text

  • 用户路径
诸如保存游戏状态或下载内容包之类的任务仍需要写入磁盘。
为此引擎确保存在始终可写的特殊路径user://。
根据项目运行所在的操作系统,此路径的解析方式有所不同。

Windows: %APPDATA%\Godot\

macOS: ~/Library/Application Support/Godot/

Linux: ~/.local/share/godot/

Image text Image text

2. 通过文件持久化游戏数据

Image text Image text

3. autoload单例模式

Image text Image text Image text Image text Image text