From 8eadba3aa6a0bf73bdaa8a02b27ef412a4a28b1f Mon Sep 17 00:00:00 2001
From: hevinci <hevinci@hotmail.com>
Date: Wed, 5 Jul 2023 16:31:29 +0800
Subject: [PATCH] update space shooter

---
 .../StreamingAssetsHelper.cs                  | 22 ++++++++++++-------
 .../StreamingAssetsHelperOLD.cs               | 10 ++++++---
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs
index 2091051..5ab922d 100644
--- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs	
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs	
@@ -3,15 +3,20 @@ using System.Collections.Generic;
 using UnityEngine;
 using YooAsset;
 
+public class StreamingAssetsDefine
+{
+	public const string RootFolderName = "yoo";
+}
+
 /// <summary>
 /// 内置文件查询服务类
 /// </summary>
 public class GameQueryServices : IQueryServices
 {
-	public bool QueryStreamingAssets(string fileName)
+	public bool QueryStreamingAssets(string packageName, string fileName)
 	{
 		// 注意:fileName包含文件格式
-		return StreamingAssetsHelper.FileExists(fileName);
+		return StreamingAssetsHelper.FileExists(packageName, fileName);
 	}
 }
 
@@ -22,9 +27,10 @@ public class GameQueryServices : IQueryServices
 public sealed class StreamingAssetsHelper
 {
 	public static void Init() { }
-	public static bool FileExists(string fileName)
+	public static bool FileExists(string packageName, string fileName)
 	{
-		return File.Exists(Path.Combine(Application.streamingAssetsPath, "BuildinFiles", fileName));
+		string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName);
+		return File.Exists(filePath);
 	}
 }
 #else
@@ -55,7 +61,7 @@ public sealed class StreamingAssetsHelper
 	/// <summary>
 	/// 内置文件查询方法
 	/// </summary>
-	public static bool FileExists(string fileName)
+	public static bool FileExists(string packageName, string fileName)
 	{
 		if (_isInit == false)
 			Init();
@@ -77,9 +83,9 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
 	{
 		var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
 
-		string folderPath = $"{Application.dataPath}/StreamingAssets/BuildinFiles";
+		string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
 		DirectoryInfo root = new DirectoryInfo(folderPath);
-		FileInfo[] files = root.GetFiles();
+		FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
 		foreach (var fileInfo in files)
 		{
 			if (fileInfo.Extension == ".meta")
@@ -97,7 +103,7 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
 		UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
 		UnityEditor.AssetDatabase.SaveAssets();
 		UnityEditor.AssetDatabase.Refresh();
-		Debug.Log($"内置资源清单保存成功 : {saveFilePath}");
+		Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
 	}
 }
 #endif
\ No newline at end of file
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs
index 0e453f8..cf6be3a 100644
--- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs	
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs	
@@ -6,15 +6,19 @@ using UnityEngine;
 using YooAsset;
 
 /*
+public class StreamingAssetsDefine
+{
+	public const string RootFolderName = "yoo";
+}
+
 /// <summary>
 /// 内置文件查询服务类
 /// </summary>
 public class GameQueryServices : IQueryServices
 {
-	public bool QueryStreamingAssets(string fileName)
+	public bool QueryStreamingAssets(string packageName, string fileName)
 	{
-		string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
-		return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
+		return StreamingAssetsHelper.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");
 	}
 }