From 829ea66d0ec8b7e9fd4967ae053f5168f2ccbf4a Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 12 Jul 2023 17:18:40 +0800 Subject: [PATCH] update sapce shooter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复生成内置文件清单的时候,目录不存在引发的异常。 --- .../StreamingAssetsHelper.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs index 5ab922d..e041c72 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs @@ -51,9 +51,12 @@ public sealed class StreamingAssetsHelper { _isInit = true; var manifest = Resources.Load("BuildinFileManifest"); - foreach (string fileName in manifest.BuildinFiles) + if (manifest != null) { - _cacheData.Add(fileName); + foreach (string fileName in manifest.BuildinFiles) + { + _cacheData.Add(fileName); + } } } } @@ -81,10 +84,19 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport /// public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report) { - var manifest = ScriptableObject.CreateInstance(); + string saveFilePath = "Assets/Resources/BuildinFileManifest.asset"; + if (File.Exists(saveFilePath)) + File.Delete(saveFilePath); string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}"; DirectoryInfo root = new DirectoryInfo(folderPath); + if (root.Exists == false) + { + Debug.Log($"没有发现YooAsset内置目录 : {folderPath}"); + return; + } + + var manifest = ScriptableObject.CreateInstance(); FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories); foreach (var fileInfo in files) { @@ -95,9 +107,6 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport manifest.BuildinFiles.Add(fileInfo.Name); } - string saveFilePath = "Assets/Resources/BuildinFileManifest.asset"; - if (File.Exists(saveFilePath)) - File.Delete(saveFilePath); if (Directory.Exists("Assets/Resources") == false) Directory.CreateDirectory("Assets/Resources"); UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);