diff --git a/docs/对接文档_Unity前端.md b/docs/对接文档_Unity前端.md index 006eddf..8288382 100644 --- a/docs/对接文档_Unity前端.md +++ b/docs/对接文档_Unity前端.md @@ -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 ← 规划器配置(同上) ``` --- diff --git a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll index e1351ae..3a16729 100644 Binary files a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll and b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll differ diff --git a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.pdb b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.pdb index 01a3dce..0959f3e 100644 Binary files a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.pdb and b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.pdb differ diff --git a/src/Unity/Assets/Scripts/Managers/UnityPathProvider.cs b/src/Unity/Assets/Scripts/Managers/UnityPathProvider.cs index ed542b8..c774f63 100644 --- a/src/Unity/Assets/Scripts/Managers/UnityPathProvider.cs +++ b/src/Unity/Assets/Scripts/Managers/UnityPathProvider.cs @@ -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; } + /// 首次运行时从 StreamingAssets 复制默认数据文件到 persistentDataPath + 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()