fix: UnityPathProvider 首次运行自动复制数据文件
从 StreamingAssets 自动拷贝 defaults.json + planner_config.json 到 persistentDataPath 前端文档更新: 文件放 Assets/StreamingAssets/ 即可,无需手动放 persistentDataPath
This commit is contained in:
parent
5b6ccccba6
commit
18f7b79401
@ -13,8 +13,10 @@
|
||||
```
|
||||
src/Unity/Assets/Plugins/ ← DLL(Core + sqlite + JSON)
|
||||
src/Unity/Assets/Scripts/Managers/ ← 桥接脚本
|
||||
data/defaults.json ← 默认数据(弹药/航线/火力单元/无人机/天气,放到 persistentDataPath 下)
|
||||
data/planner_config.json ← 规划器配置(放到 persistentDataPath 下)
|
||||
|
||||
将以下文件放到 Unity 项目 Assets/StreamingAssets/ 目录下:
|
||||
data/defaults.json ← 默认数据(首次运行自动复制到 persistentDataPath)
|
||||
data/planner_config.json ← 规划器配置(同上)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -7,6 +7,7 @@ namespace CounterDrone.Unity
|
||||
public class UnityPathProvider : IPathProvider
|
||||
{
|
||||
private string _root;
|
||||
private bool _copied;
|
||||
|
||||
public string GetDataRoot()
|
||||
{
|
||||
@ -14,10 +15,27 @@ namespace CounterDrone.Unity
|
||||
{
|
||||
_root = Application.persistentDataPath;
|
||||
Directory.CreateDirectory(_root);
|
||||
CopyDataFiles();
|
||||
}
|
||||
return _root;
|
||||
}
|
||||
|
||||
/// <summary>首次运行时从 StreamingAssets 复制默认数据文件到 persistentDataPath</summary>
|
||||
private void CopyDataFiles()
|
||||
{
|
||||
if (_copied) return;
|
||||
_copied = true;
|
||||
var sourceDir = Application.streamingAssetsPath;
|
||||
if (!Directory.Exists(sourceDir)) return;
|
||||
foreach (var file in new[] { "defaults.json", "planner_config.json" })
|
||||
{
|
||||
var dst = Path.Combine(_root, file);
|
||||
if (File.Exists(dst)) continue;
|
||||
var src = Path.Combine(sourceDir, file);
|
||||
if (File.Exists(src)) File.Copy(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetMainDbPath() => Path.Combine(GetDataRoot(), "main.db");
|
||||
|
||||
public string GetFramesDir()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user