Files
YooAssetScene/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemHelper.cs
T

86 lines
2.8 KiB
C#

using UnityEngine.Networking;
using UnityEngine;
namespace YooAsset
{
internal class DownloadSystemHelper
{
/// <summary>
/// 获取WWW加载本地资源的路径
/// </summary>
public static string ConvertToWWWPath(string path)
{
string url;
// 获取对应平台的URL地址
// 说明:苹果不同设备上操作系统不同。
// 说明:iPhone和iPod对应的是iOS系统。
// 说明:iPad对应的是iPadOS系统。
// 说明:AppleTV对应的是tvOS系统。
#if UNITY_EDITOR_OSX
url = StringUtility.Format("file://{0}", path);
#elif UNITY_EDITOR_WIN
url = StringUtility.Format("file:///{0}", path);
#elif UNITY_WEBGL
url = path;
#elif UNITY_IOS || UNITY_IPHONE
url = StringUtility.Format("file://{0}", path);
#elif UNITY_ANDROID
if (path.StartsWith("jar:file://"))
url = path;
else
url = StringUtility.Format("jar:file://{0}", path);
#elif UNITY_OPENHARMONY
if (UnityEngine.Application.streamingAssetsPath.StartsWith("jar:file://"))
{
if (path.StartsWith("jar:file://"))
url = path;
else
url = StringUtility.Format("jar:file://{0}", path);
}
else
{
if (path.StartsWith("file://"))
url = path;
else
url = StringUtility.Format("file://{0}", path);
}
#elif UNITY_WSA
url = StringUtility.Format("file:///{0}", path);
#elif UNITY_TVOS
url = StringUtility.Format("file:///{0}", path);
#elif UNITY_STANDALONE_OSX
url = new System.Uri(path).ToString();
#elif UNITY_STANDALONE_WIN
url = StringUtility.Format("file:///{0}", path);
#elif UNITY_STANDALONE_LINUX
url = StringUtility.Format("file:///root/{0}", path);
#else
throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] not implemented platform: {UnityEngine.Application.platform}");
#endif
// For some special cases when users have special characters in their devices, url paths can not be identified correctly.
return url.Replace("+", "%2B").Replace("#", "%23").Replace("?", "%3F");
}
/// <summary>
/// 是否请求的本地文件
/// </summary>
public static bool IsRequestLocalFile(string url)
{
//TODO UNITY_STANDALONE_OSX平台目前无法确定
// 本地文件传输协议
if (url.StartsWith("file:"))
return true;
// JAR文件协议
if (url.StartsWith("jar:file:"))
return true;
return false;
}
}
}