diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs
index 1e05ca5..c598a8d 100644
--- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs
+++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs
@@ -92,41 +92,29 @@ internal class FsmInitialize : IStateNode
{
//string hostServerIP = "http://10.0.2.2"; //安卓模拟器地址
string hostServerIP = "http://127.0.0.1";
- string gameVersion = "v1.0";
+ string appVersion = "v1.0";
#if UNITY_EDITOR
if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.Android)
- return $"{hostServerIP}/CDN/Android/{gameVersion}";
+ return $"{hostServerIP}/CDN/Android/{appVersion}";
else if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.iOS)
- return $"{hostServerIP}/CDN/IPhone/{gameVersion}";
+ return $"{hostServerIP}/CDN/IPhone/{appVersion}";
else if (UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.WebGL)
- return $"{hostServerIP}/CDN/WebGL/{gameVersion}";
+ return $"{hostServerIP}/CDN/WebGL/{appVersion}";
else
- return $"{hostServerIP}/CDN/PC/{gameVersion}";
+ return $"{hostServerIP}/CDN/PC/{appVersion}";
#else
if (Application.platform == RuntimePlatform.Android)
- return $"{hostServerIP}/CDN/Android/{gameVersion}";
+ return $"{hostServerIP}/CDN/Android/{appVersion}";
else if (Application.platform == RuntimePlatform.IPhonePlayer)
- return $"{hostServerIP}/CDN/IPhone/{gameVersion}";
+ return $"{hostServerIP}/CDN/IPhone/{appVersion}";
else if (Application.platform == RuntimePlatform.WebGLPlayer)
- return $"{hostServerIP}/CDN/WebGL/{gameVersion}";
+ return $"{hostServerIP}/CDN/WebGL/{appVersion}";
else
- return $"{hostServerIP}/CDN/PC/{gameVersion}";
+ return $"{hostServerIP}/CDN/PC/{appVersion}";
#endif
}
- ///
- /// 内置文件查询服务类
- ///
- private class GameQueryServices : IQueryServices
- {
- public bool QueryStreamingAssets(string fileName)
- {
- string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
- return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
- }
- }
-
///
/// 资源文件解密服务类
///
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs
new file mode 100644
index 0000000..c36d20f
--- /dev/null
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+///
+/// 内置资源清单
+///
+public class BuildinFileManifest : ScriptableObject
+{
+ public List BuildinFiles = new List();
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta
new file mode 100644
index 0000000..428aff2
--- /dev/null
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 71b02dfa7aa9d4545b3417a18477fbee
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs
index 1943007..aa37d57 100644
--- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs
@@ -1,134 +1,89 @@
-//-------------------------------------
-// 作者:Stark
-//-------------------------------------
+using System.IO;
using System.Collections.Generic;
using UnityEngine;
+using YooAsset;
+
+///
+/// 内置文件查询服务类
+///
+public class GameQueryServices : IQueryServices
+{
+ public bool QueryStreamingAssets(string fileName)
+ {
+ // 注意:fileName包含文件格式
+ return StreamingAssetsHelper.FileExists(fileName);
+ }
+}
///
/// StreamingAssets目录下资源查询帮助类
///
public sealed class StreamingAssetsHelper
{
- private static readonly Dictionary _cacheData = new Dictionary(1000);
+ private static bool _isInit = false;
+ private static readonly HashSet _cacheData = new HashSet();
-#if UNITY_ANDROID && !UNITY_EDITOR
- private static AndroidJavaClass _unityPlayerClass;
- public static AndroidJavaClass UnityPlayerClass
+ ///
+ /// 初始化
+ ///
+ public static void Init()
{
- get
+ if (_isInit == false)
{
- if (_unityPlayerClass == null)
- _unityPlayerClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
- return _unityPlayerClass;
- }
- }
-
- private static AndroidJavaObject _currentActivity;
- public static AndroidJavaObject CurrentActivity
- {
- get
- {
- if (_currentActivity == null)
- _currentActivity = UnityPlayerClass.GetStatic("currentActivity");
- return _currentActivity;
+ _isInit = true;
+ var manifest = Resources.Load("BuildinFileManifest");
+ foreach (string fileName in manifest.BuildinFiles)
+ {
+ _cacheData.Add(fileName);
+ }
}
}
///
- /// 利用安卓原生接口查询内置文件是否存在
+ /// 内置文件查询方法
///
- public static bool FileExists(string filePath)
+ public static bool FileExists(string fileName)
{
- if (_cacheData.TryGetValue(filePath, out bool result) == false)
- {
- result = CurrentActivity.Call("CheckAssetExist", filePath);
- _cacheData.Add(filePath, result);
- }
- return result;
+ if (_isInit == false)
+ Init();
+
+ return _cacheData.Contains(fileName);
}
-#else
- public static bool FileExists(string filePath)
- {
- if (_cacheData.TryGetValue(filePath, out bool result) == false)
- {
- result = System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, filePath));
- _cacheData.Add(filePath, result);
- }
- return result;
- }
-#endif
}
-
-#if UNITY_ANDROID && UNITY_EDITOR
-///
-/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
-///
-internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProject
+#if UNITY_EDITOR
+internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
{
- public int callbackOrder => 99;
- public void OnPostGenerateGradleAndroidProject(string path)
- {
- path = path.Replace("\\", "/");
- string untityActivityFilePath = $"{path}/src/main/java/com/unity3d/player/UnityPlayerActivity.java";
- var readContent = System.IO.File.ReadAllLines(untityActivityFilePath);
- string postContent =
- " //auto-gen-function \n" +
- " public boolean CheckAssetExist(String filePath) \n" +
- " { \n" +
- " android.content.res.AssetManager assetManager = getAssets(); \n" +
- " try \n" +
- " { \n" +
- " java.io.InputStream inputStream = assetManager.open(filePath); \n" +
- " if (null != inputStream) \n" +
- " { \n" +
- " inputStream.close(); \n" +
- " return true; \n" +
- " } \n" +
- " } \n" +
- " catch(java.io.IOException e) \n" +
- " { \n" +
- " } \n" +
- " return false; \n" +
- " } \n" +
- "}";
+ public int callbackOrder { get { return 0; } }
- if (CheckFunctionExist(readContent) == false)
- readContent[readContent.Length - 1] = postContent;
- System.IO.File.WriteAllLines(untityActivityFilePath, readContent);
- }
- private bool CheckFunctionExist(string[] contents)
+ ///
+ /// 在构建应用程序前处理
+ ///
+ public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
{
- for (int i = 0; i < contents.Length; i++)
+ var manifest = ScriptableObject.CreateInstance();
+
+ string folderPath = $"{Application.dataPath}/StreamingAssets/BuildinFiles";
+ DirectoryInfo root = new DirectoryInfo(folderPath);
+ FileInfo[] files = root.GetFiles();
+ foreach (var fileInfo in files)
{
- if (contents[i].Contains("CheckAssetExist"))
- {
- return true;
- }
+ if (fileInfo.Extension == ".meta")
+ continue;
+ if (fileInfo.Name.StartsWith("PackageManifest_"))
+ continue;
+ manifest.BuildinFiles.Add(fileInfo.Name);
}
- return false;
+
+ 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);
+ UnityEditor.AssetDatabase.SaveAssets();
+ UnityEditor.AssetDatabase.Refresh();
+ Debug.Log($"内置资源清单保存成功 : {saveFilePath}");
}
}
-#endif
-
-/*
-//auto-gen-function
-public boolean CheckAssetExist(String filePath)
-{
- android.content.res.AssetManager assetManager = getAssets();
- try
- {
- java.io.InputStream inputStream = assetManager.open(filePath);
- if(null != inputStream)
- {
- inputStream.close();
- return true;
- }
- }
- catch(java.io.IOException e)
- {
- //e.printStackTrace();
- }
- return false;
-}
-*/
\ No newline at end of file
+#endif
\ No newline at end of file
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta
index 774fc7f..e7f3da4 100644
--- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 358145d67e230b34883002b08b23cba3
+guid: ca0617f5ec2b4504b923e3205dc77f54
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs
new file mode 100644
index 0000000..0e453f8
--- /dev/null
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs
@@ -0,0 +1,150 @@
+//-------------------------------------
+// 作者:Stark
+//-------------------------------------
+using System.Collections.Generic;
+using UnityEngine;
+using YooAsset;
+
+/*
+///
+/// 内置文件查询服务类
+///
+public class GameQueryServices : IQueryServices
+{
+ public bool QueryStreamingAssets(string fileName)
+ {
+ string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
+ return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
+ }
+}
+
+///
+/// StreamingAssets目录下资源查询帮助类
+///
+public sealed class StreamingAssetsHelper
+{
+ private static readonly Dictionary _cacheData = new Dictionary(1000);
+
+#if UNITY_ANDROID && !UNITY_EDITOR
+ private static AndroidJavaClass _unityPlayerClass;
+ public static AndroidJavaClass UnityPlayerClass
+ {
+ get
+ {
+ if (_unityPlayerClass == null)
+ _unityPlayerClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
+ return _unityPlayerClass;
+ }
+ }
+
+ private static AndroidJavaObject _currentActivity;
+ public static AndroidJavaObject CurrentActivity
+ {
+ get
+ {
+ if (_currentActivity == null)
+ _currentActivity = UnityPlayerClass.GetStatic("currentActivity");
+ return _currentActivity;
+ }
+ }
+
+ ///
+ /// 利用安卓原生接口查询内置文件是否存在
+ ///
+ public static bool FileExists(string filePath)
+ {
+ if (_cacheData.TryGetValue(filePath, out bool result) == false)
+ {
+ result = CurrentActivity.Call("CheckAssetExist", filePath);
+ _cacheData.Add(filePath, result);
+ }
+ return result;
+ }
+#else
+ public static bool FileExists(string filePath)
+ {
+ if (_cacheData.TryGetValue(filePath, out bool result) == false)
+ {
+ result = System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, filePath));
+ _cacheData.Add(filePath, result);
+ }
+ return result;
+ }
+#endif
+}
+
+
+#if UNITY_ANDROID && UNITY_EDITOR
+///
+/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
+///
+internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProject
+{
+ public int callbackOrder => 99;
+ public void OnPostGenerateGradleAndroidProject(string path)
+ {
+ path = path.Replace("\\", "/");
+ string untityActivityFilePath = $"{path}/src/main/java/com/unity3d/player/UnityPlayerActivity.java";
+ var readContent = System.IO.File.ReadAllLines(untityActivityFilePath);
+ string postContent =
+ " //auto-gen-function \n" +
+ " public boolean CheckAssetExist(String filePath) \n" +
+ " { \n" +
+ " android.content.res.AssetManager assetManager = getAssets(); \n" +
+ " try \n" +
+ " { \n" +
+ " java.io.InputStream inputStream = assetManager.open(filePath); \n" +
+ " if (null != inputStream) \n" +
+ " { \n" +
+ " inputStream.close(); \n" +
+ " return true; \n" +
+ " } \n" +
+ " } \n" +
+ " catch(java.io.IOException e) \n" +
+ " { \n" +
+ " } \n" +
+ " return false; \n" +
+ " } \n" +
+ "}";
+
+ if (CheckFunctionExist(readContent) == false)
+ readContent[readContent.Length - 1] = postContent;
+ System.IO.File.WriteAllLines(untityActivityFilePath, readContent);
+ }
+ private bool CheckFunctionExist(string[] contents)
+ {
+ for (int i = 0; i < contents.Length; i++)
+ {
+ if (contents[i].Contains("CheckAssetExist"))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+#endif
+*/
+
+
+/*
+//auto-gen-function
+public boolean CheckAssetExist(String filePath)
+{
+ android.content.res.AssetManager assetManager = getAssets();
+ try
+ {
+ java.io.InputStream inputStream = assetManager.open(filePath);
+ if(null != inputStream)
+ {
+ inputStream.close();
+ return true;
+ }
+ }
+ catch(java.io.IOException e)
+ {
+ //e.printStackTrace();
+ }
+ return false;
+}
+*/
\ No newline at end of file
diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs.meta
new file mode 100644
index 0000000..774fc7f
--- /dev/null
+++ b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelperOLD.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 358145d67e230b34883002b08b23cba3
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: