12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #if !COMBAT_SERVER
- using System.IO;
- using UnityEngine;
- namespace Fort23.Core
- {
- public static class PathHelper
- {
- /// <summary>
- ///应用程序外部资源路径存放路径(热更新资源路径)
- /// </summary>
- public static string AppHotfixResPath
- {
- get
- {
- if (!Directory.Exists($"{Application.persistentDataPath}/{Application.identifier}/"))
- {
- Debug.Log("创建目录:" + $"{Application.persistentDataPath}/{Application.identifier}/");
- Directory.CreateDirectory($"{Application.persistentDataPath}/{Application.identifier}/");
- }
- return $"{Application.persistentDataPath}/{Application.identifier}/";
- }
- }
- /// <summary>
- /// 应用程序内部资源路径存放路径
- /// </summary>
- public static string AppResPath
- {
- get
- {
- #if UNITY_EDITOR
- return Application.streamingAssetsPath;
- #elif UNITY_ANDROID
- return Application.streamingAssetsPath;
- #elif UNITY_IOS
- return Application.streamingAssetsPath;
- #else
- return Application.streamingAssetsPath;
- #endif
- }
- }
- /// <summary>
- /// 应用程序内部资源路径存放路径(www/webrequest专用)
- /// </summary>
- public static string AppResPath4Web
- {
- get
- {
- #if UNITY_IOS || UNITY_STANDALONE_OSX
- return $"file://{Application.streamingAssetsPath}";
- #else
- return Application.streamingAssetsPath;
- #endif
- }
- }
- public static string GetWebRequestPath(string resourceName)
- {
- string p = GetResPath(resourceName);
- // webRequest要加file://
- if (!p.Contains("://"))
- {
- p = "file://" + p;
- }
- return p;
- }
- /// <summary>
- /// 先从热更路径读取(表示已经热更过),在从内部路径读取(Application.streamingAssetsPath不能用File.Exists判断,无效)
- /// </summary>
- /// <param name="resourceName"></param>
- /// <returns></returns>
- private static string GetResPath(string resourceName)
- {
- string p = Path.Combine(AppHotfixResPath, resourceName);
- if (!File.Exists(p))
- {
- p = Path.Combine(Application.streamingAssetsPath, resourceName);
- }
- return p;
- }
- }
- }
- #endif
|