Check location param is invalid.

在编辑器下检测资源路径是否合法并警告。
pull/4/head
hevinci 2022-04-14 19:01:39 +08:00
parent b25f656372
commit 4591d0b5f6
1 changed files with 28 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
@ -13,6 +14,10 @@ namespace YooAsset
} }
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location) public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
{ {
#if UNITY_EDITOR
CheckLocation(location);
#endif
if (playMode == YooAssets.EPlayMode.EditorPlayMode) if (playMode == YooAssets.EPlayMode.EditorPlayMode)
{ {
string filePath = CombineAssetPath(_resourceRoot, location); string filePath = CombineAssetPath(_resourceRoot, location);
@ -73,5 +78,28 @@ namespace YooAsset
throw new System.NotImplementedException(); throw new System.NotImplementedException();
#endif #endif
} }
#if UNITY_EDITOR
private void CheckLocation(string location)
{
if (string.IsNullOrEmpty(location))
{
Debug.LogError("location param is null or empty!");
}
else
{
// 检查路径末尾是否有空格
int index = location.LastIndexOf(" ");
if (index != -1)
{
if (location.Length == index + 1)
Debug.LogWarning($"Found blank character in location : \"{location}\"");
}
if (location.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
Debug.LogWarning($"Found illegal character in location : \"{location}\"");
}
}
#endif
} }
} }