diff --git a/Assets/TEngine/Runtime/FileSystem/FileSystem.cs b/Assets/TEngine/Runtime/FileSystem/FileSystem.cs index 77ac5b70..5869fbb0 100644 --- a/Assets/TEngine/Runtime/FileSystem/FileSystem.cs +++ b/Assets/TEngine/Runtime/FileSystem/FileSystem.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using UnityEngine; +using UnityEngine.Networking; namespace TEngine { @@ -137,7 +138,19 @@ namespace TEngine if (string.IsNullOrEmpty(filePath)) return null; +#if UNITY_ANDROID && !UNITY_EDITOR + //外部目录 + if (filePath.StartsWith(Application.persistentDataPath)) + { + return ReadAllBytesFromOutFolder(filePath); + } + else //内部目录 + { + return ReadAllBytesFromInnerFolder(filePath); + } +#else return ReadAllBytesFromOutFolder(filePath); +#endif } private static byte[] ReadAllBytesFromOutFolder(string filePath) @@ -149,5 +162,37 @@ namespace TEngine } return File.ReadAllBytes(filePath); } + + private static byte[] ReadAllBytesFromInnerFolder(string filePath) + { +#if !UNITY_ANDROID || UNITY_EDITOR + filePath = $"file://{filePath}"; +#endif + UnityWebRequest www = UnityWebRequest.Get(filePath); + UnityWebRequestAsyncOperation request = www.SendWebRequest(); + while (!request.isDone) ; + byte[] data = www.downloadHandler.data; + www.downloadHandler.Dispose(); + www.Dispose(); + www = null; + return data; + } + + /// + /// 读取内部目录 + /// + /// 文件完整路径 + /// + private static string ReadTextFromInnerFolder(string filePath) + { +#if !UNITY_ANDROID || UNITY_EDITOR + filePath = $"file://{filePath}"; +#endif + UnityWebRequest www = UnityWebRequest.Get(filePath); + UnityWebRequestAsyncOperation request = www.SendWebRequest(); + while (!request.isDone) ; + + return www.downloadHandler.text; + } } } \ No newline at end of file diff --git a/TEngineHotUpdate/src/TEngineCore/FileSystem/FileSystem.cs b/TEngineHotUpdate/src/TEngineCore/FileSystem/FileSystem.cs index 2e746e56..f9cc3cde 100644 --- a/TEngineHotUpdate/src/TEngineCore/FileSystem/FileSystem.cs +++ b/TEngineHotUpdate/src/TEngineCore/FileSystem/FileSystem.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using UnityEngine; +using UnityEngine.Networking; namespace TEngineCore { @@ -137,7 +138,19 @@ namespace TEngineCore if (string.IsNullOrEmpty(filePath)) return null; +#if UNITY_ANDROID && !UNITY_EDITOR + //外部目录 + if (filePath.StartsWith(Application.persistentDataPath)) + { + return ReadAllBytesFromOutFolder(filePath); + } + else //内部目录 + { + return ReadAllBytesFromInnerFolder(filePath); + } +#else return ReadAllBytesFromOutFolder(filePath); +#endif } private static byte[] ReadAllBytesFromOutFolder(string filePath) @@ -149,5 +162,37 @@ namespace TEngineCore } return File.ReadAllBytes(filePath); } + + private static byte[] ReadAllBytesFromInnerFolder(string filePath) + { +#if !UNITY_ANDROID || UNITY_EDITOR + filePath = $"file://{filePath}"; +#endif + UnityWebRequest www = UnityWebRequest.Get(filePath); + UnityWebRequestAsyncOperation request = www.SendWebRequest(); + while (!request.isDone) ; + byte[] data = www.downloadHandler.data; + www.downloadHandler.Dispose(); + www.Dispose(); + www = null; + return data; + } + + /// + /// 读取内部目录 + /// + /// 文件完整路径 + /// + private static string ReadTextFromInnerFolder(string filePath) + { +#if !UNITY_ANDROID || UNITY_EDITOR + filePath = $"file://{filePath}"; +#endif + UnityWebRequest www = UnityWebRequest.Get(filePath); + UnityWebRequestAsyncOperation request = www.SendWebRequest(); + while (!request.isDone) ; + + return www.downloadHandler.text; + } } } \ No newline at end of file