From 2eeffaf74f89dfdb556c81f16df89fa35964d7be Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 14 Mar 2025 20:20:47 +0800 Subject: [PATCH] fix script search by name. --- src/Internal/ScriptsCache.cs | 36 ++++++++++++++++--- .../DragonDocs/Editors/DragonDocsWindow.cs | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Internal/ScriptsCache.cs b/src/Internal/ScriptsCache.cs index 2eb0aba..9319f78 100644 --- a/src/Internal/ScriptsCache.cs +++ b/src/Internal/ScriptsCache.cs @@ -121,7 +121,6 @@ namespace DCFApixels.DragonECS.Unity.Editors #endregion #region Get - public static bool TryGetScriptAsset(Type type, out MonoScript script) { return TryGetScriptAsset(type.ToMeta(), out script); } public static bool TryGetScriptAsset(TypeMeta meta, out MonoScript script) { int uniqueID = meta.GetHashCode(); @@ -154,25 +153,52 @@ namespace DCFApixels.DragonECS.Unity.Editors if (script == null) { - //Ищем совпадения имет в ассетах + //Ищем совпадения имен в ассетах string name = meta.TypeName; int genericTypeCharIndex = name.IndexOf('<'); if (genericTypeCharIndex >= 0) { name = name.Substring(0, genericTypeCharIndex); } - var guids = AssetDatabase.FindAssets($"{name} t:MonoScript"); + string[] guids = AssetDatabase.FindAssets($"{name} t:MonoScript"); + string[] skipped = Array.Empty(); + int skippedCount = 0; + for (var i = 0; i < guids.Length; i++) { - MonoScript textAsset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[i])); + string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]); + + if (assetPath.IndexOf("Packages/com.unity.") == 0) + { + if(skippedCount == 0) + { + skipped = new string[guids.Length]; + } + skipped[skippedCount++] = assetPath; + continue; + } + MonoScript textAsset = AssetDatabase.LoadAssetAtPath(assetPath); if (textAsset != null && textAsset.name == name) { script = textAsset; break; } } - } + if(script == null) + { + foreach (var assetPath in new ReadOnlySpan(skipped, 0, skippedCount)) + { + MonoScript textAsset = AssetDatabase.LoadAssetAtPath(assetPath); + if (textAsset != null && textAsset.name == name) + { + script = textAsset; + break; + } + } + } + + } _scriptsAssets.Add(uniqueID, script); } return script != null; diff --git a/src/Tools/DragonDocs/Editors/DragonDocsWindow.cs b/src/Tools/DragonDocs/Editors/DragonDocsWindow.cs index 2cf1b50..a34a625 100644 --- a/src/Tools/DragonDocs/Editors/DragonDocsWindow.cs +++ b/src/Tools/DragonDocs/Editors/DragonDocsWindow.cs @@ -261,7 +261,7 @@ namespace DCFApixels.DragonECS.Unity.Docs.Editors { GUILayout.TextArea(IsUseCustomNames ? meta.Name : meta.TypeName, EditorStyles.boldLabel, GUILayout.ExpandWidth(false)); - if (meta.TryGetSourceType(out System.Type targetType) && ScriptsCache.TryGetScriptAsset(targetType, out MonoScript script)) + if (meta.TryGetSourceType(out System.Type targetType) && ScriptsCache.TryGetScriptAsset(targetType.ToMeta(), out MonoScript script)) { EcsGUI.Layout.ScriptAssetButton(script, GUILayout.Width(18f)); }