mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Fixed the FileSystem of Android
Fixed the FileSystem of Android
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace TEngine
|
namespace TEngine
|
||||||
{
|
{
|
||||||
@@ -137,7 +138,19 @@ namespace TEngine
|
|||||||
if (string.IsNullOrEmpty(filePath))
|
if (string.IsNullOrEmpty(filePath))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||||
|
//外部目录
|
||||||
|
if (filePath.StartsWith(Application.persistentDataPath))
|
||||||
|
{
|
||||||
|
return ReadAllBytesFromOutFolder(filePath);
|
||||||
|
}
|
||||||
|
else //内部目录
|
||||||
|
{
|
||||||
|
return ReadAllBytesFromInnerFolder(filePath);
|
||||||
|
}
|
||||||
|
#else
|
||||||
return ReadAllBytesFromOutFolder(filePath);
|
return ReadAllBytesFromOutFolder(filePath);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] ReadAllBytesFromOutFolder(string filePath)
|
private static byte[] ReadAllBytesFromOutFolder(string filePath)
|
||||||
@@ -149,5 +162,37 @@ namespace TEngine
|
|||||||
}
|
}
|
||||||
return File.ReadAllBytes(filePath);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取内部目录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">文件完整路径</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace TEngineCore
|
namespace TEngineCore
|
||||||
{
|
{
|
||||||
@@ -137,7 +138,19 @@ namespace TEngineCore
|
|||||||
if (string.IsNullOrEmpty(filePath))
|
if (string.IsNullOrEmpty(filePath))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||||
|
//外部目录
|
||||||
|
if (filePath.StartsWith(Application.persistentDataPath))
|
||||||
|
{
|
||||||
|
return ReadAllBytesFromOutFolder(filePath);
|
||||||
|
}
|
||||||
|
else //内部目录
|
||||||
|
{
|
||||||
|
return ReadAllBytesFromInnerFolder(filePath);
|
||||||
|
}
|
||||||
|
#else
|
||||||
return ReadAllBytesFromOutFolder(filePath);
|
return ReadAllBytesFromOutFolder(filePath);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] ReadAllBytesFromOutFolder(string filePath)
|
private static byte[] ReadAllBytesFromOutFolder(string filePath)
|
||||||
@@ -149,5 +162,37 @@ namespace TEngineCore
|
|||||||
}
|
}
|
||||||
return File.ReadAllBytes(filePath);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取内部目录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">文件完整路径</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user