mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 18:14:35 +08:00
fix script search by name.
This commit is contained in:
parent
88f729b868
commit
2eeffaf74f
@ -121,7 +121,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Get
|
#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)
|
public static bool TryGetScriptAsset(TypeMeta meta, out MonoScript script)
|
||||||
{
|
{
|
||||||
int uniqueID = meta.GetHashCode();
|
int uniqueID = meta.GetHashCode();
|
||||||
@ -154,17 +153,43 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
if (script == null)
|
if (script == null)
|
||||||
{
|
{
|
||||||
//Ищем совпадения имет в ассетах
|
//Ищем совпадения имен в ассетах
|
||||||
string name = meta.TypeName;
|
string name = meta.TypeName;
|
||||||
int genericTypeCharIndex = name.IndexOf('<');
|
int genericTypeCharIndex = name.IndexOf('<');
|
||||||
if (genericTypeCharIndex >= 0)
|
if (genericTypeCharIndex >= 0)
|
||||||
{
|
{
|
||||||
name = name.Substring(0, genericTypeCharIndex);
|
name = name.Substring(0, genericTypeCharIndex);
|
||||||
}
|
}
|
||||||
var guids = AssetDatabase.FindAssets($"{name} t:MonoScript");
|
string[] guids = AssetDatabase.FindAssets($"{name} t:MonoScript");
|
||||||
|
string[] skipped = Array.Empty<string>();
|
||||||
|
int skippedCount = 0;
|
||||||
|
|
||||||
for (var i = 0; i < guids.Length; i++)
|
for (var i = 0; i < guids.Length; i++)
|
||||||
{
|
{
|
||||||
MonoScript textAsset = AssetDatabase.LoadAssetAtPath<MonoScript>(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<MonoScript>(assetPath);
|
||||||
|
if (textAsset != null && textAsset.name == name)
|
||||||
|
{
|
||||||
|
script = textAsset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(script == null)
|
||||||
|
{
|
||||||
|
foreach (var assetPath in new ReadOnlySpan<string>(skipped, 0, skippedCount))
|
||||||
|
{
|
||||||
|
MonoScript textAsset = AssetDatabase.LoadAssetAtPath<MonoScript>(assetPath);
|
||||||
if (textAsset != null && textAsset.name == name)
|
if (textAsset != null && textAsset.name == name)
|
||||||
{
|
{
|
||||||
script = textAsset;
|
script = textAsset;
|
||||||
@ -173,6 +198,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
_scriptsAssets.Add(uniqueID, script);
|
_scriptsAssets.Add(uniqueID, script);
|
||||||
}
|
}
|
||||||
return script != null;
|
return script != null;
|
||||||
|
@ -261,7 +261,7 @@ namespace DCFApixels.DragonECS.Unity.Docs.Editors
|
|||||||
{
|
{
|
||||||
GUILayout.TextArea(IsUseCustomNames ? meta.Name : meta.TypeName, EditorStyles.boldLabel, GUILayout.ExpandWidth(false));
|
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));
|
EcsGUI.Layout.ScriptAssetButton(script, GUILayout.Width(18f));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user