From 4591d0b5f69f0ae31d6a70f3c22845d21d3f7e52 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 14 Apr 2022 19:01:39 +0800 Subject: [PATCH] Check location param is invalid. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在编辑器下检测资源路径是否合法并警告。 --- .../Services/DefaultLocationServices.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs index b50e14f..a021da4 100644 --- a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs +++ b/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs @@ -1,4 +1,5 @@ using System.IO; +using UnityEngine; namespace YooAsset { @@ -13,6 +14,10 @@ namespace YooAsset } public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location) { +#if UNITY_EDITOR + CheckLocation(location); +#endif + if (playMode == YooAssets.EPlayMode.EditorPlayMode) { string filePath = CombineAssetPath(_resourceRoot, location); @@ -73,5 +78,28 @@ namespace YooAsset throw new System.NotImplementedException(); #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 } } \ No newline at end of file