UI换了很多,spine主视觉停用
This commit is contained in:
@@ -8,6 +8,13 @@ using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using DG.Tweening;
|
||||
|
||||
[Serializable]
|
||||
public class UI_FunctionHoverSceneBinding
|
||||
{
|
||||
public string path;
|
||||
public RectTransform target;
|
||||
}
|
||||
|
||||
public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
{
|
||||
[Header("Scene")]
|
||||
@@ -31,6 +38,7 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
public RawImage functionIconRaw;
|
||||
public TMP_Text functionTextTmp;
|
||||
public Text functionTextLegacy;
|
||||
public List<UI_FunctionHoverSceneBinding> sceneBindings = new();
|
||||
|
||||
[Header("Animation")]
|
||||
public float iconStartScale = 0.6f;
|
||||
@@ -177,9 +185,9 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
{
|
||||
GameObject go = null;
|
||||
if (!string.IsNullOrWhiteSpace(functionRootPath))
|
||||
go = GameObject.Find(functionRootPath);
|
||||
go = SceneObjectLookupCache.Find(functionRootPath);
|
||||
if (go == null && !string.IsNullOrWhiteSpace(targetBasePath))
|
||||
go = GameObject.Find(CombinePath(targetBasePath, functionRootName));
|
||||
go = SceneObjectLookupCache.Find(CombinePath(targetBasePath, functionRootName));
|
||||
if (go == null)
|
||||
go = FindByNameContains(functionRootName);
|
||||
if (go != null)
|
||||
@@ -190,12 +198,12 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
|
||||
if (functionIcon == null)
|
||||
{
|
||||
var icon = FindChildGraphic(functionRoot, iconNameContains);
|
||||
var icon = FindChildGraphic(functionRoot, "ICON");
|
||||
if (icon != null) functionIcon = icon;
|
||||
}
|
||||
if (functionIconRaw == null && functionIcon == null)
|
||||
{
|
||||
var raw = FindChildRawImage(functionRoot, iconNameContains);
|
||||
var raw = FindChildRawImage(functionRoot, "ICON");
|
||||
if (raw != null) functionIconRaw = raw;
|
||||
}
|
||||
|
||||
@@ -268,16 +276,31 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
{
|
||||
var entry = config.entries[i];
|
||||
if (entry == null || string.IsNullOrWhiteSpace(entry.path)) continue;
|
||||
var target = FindByPath(entry.path);
|
||||
if (target == null)
|
||||
int entryWired = 0;
|
||||
var explicitTargets = FindExplicitTargets(entry.path);
|
||||
for (int t = 0; t < explicitTargets.Count; t++)
|
||||
{
|
||||
if (debugLogs)
|
||||
Debug.LogWarning("UI_FunctionHoverGuide: target not found for path: " + entry.path);
|
||||
continue;
|
||||
var explicitTarget = explicitTargets[t];
|
||||
if (explicitTarget == null) continue;
|
||||
if (AttachHoverTargets(explicitTarget.transform, entry))
|
||||
entryWired++;
|
||||
}
|
||||
|
||||
if (AttachHoverTargets(target.transform, entry))
|
||||
wired++;
|
||||
if (entryWired <= 0)
|
||||
{
|
||||
var target = FindByPath(entry.path);
|
||||
if (target == null)
|
||||
{
|
||||
if (debugLogs)
|
||||
Debug.LogWarning("UI_FunctionHoverGuide: target not found for path: " + entry.path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AttachHoverTargets(target.transform, entry))
|
||||
entryWired++;
|
||||
}
|
||||
|
||||
wired += entryWired;
|
||||
}
|
||||
return wired;
|
||||
}
|
||||
@@ -393,12 +416,12 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
private GameObject FindByPath(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) return null;
|
||||
var go = GameObject.Find(path);
|
||||
var go = SceneObjectLookupCache.Find(path);
|
||||
if (go != null) return go;
|
||||
if (!string.IsNullOrWhiteSpace(targetBasePath))
|
||||
{
|
||||
var combined = CombinePath(targetBasePath, path);
|
||||
go = GameObject.Find(combined);
|
||||
go = SceneObjectLookupCache.Find(combined);
|
||||
if (go != null) return go;
|
||||
}
|
||||
|
||||
@@ -422,9 +445,33 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
return FindByNameContains(last);
|
||||
}
|
||||
|
||||
private List<GameObject> FindExplicitTargets(string path)
|
||||
{
|
||||
var result = new List<GameObject>();
|
||||
if (sceneBindings == null || sceneBindings.Count == 0 || string.IsNullOrWhiteSpace(path))
|
||||
return result;
|
||||
|
||||
string normalizedTarget = NormalizePath(path);
|
||||
for (int i = 0; i < sceneBindings.Count; i++)
|
||||
{
|
||||
var binding = sceneBindings[i];
|
||||
if (binding == null || binding.target == null || string.IsNullOrWhiteSpace(binding.path))
|
||||
continue;
|
||||
|
||||
if (!string.Equals(NormalizePath(binding.path), normalizedTarget, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
result.Add(binding.target.gameObject);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private GameObject FindByNameContains(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name)) return null;
|
||||
var exact = SceneObjectLookupCache.Find(name);
|
||||
if (exact != null) return exact;
|
||||
var all = Resources.FindObjectsOfTypeAll<Transform>();
|
||||
string target = name.Replace(" ", "");
|
||||
for (int i = 0; i < all.Length; i++)
|
||||
@@ -470,48 +517,47 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
return string.Join("/", parts);
|
||||
}
|
||||
|
||||
private static Image FindChildGraphic(Transform root, string nameContains)
|
||||
private static Image FindChildGraphic(Transform root, string exactName)
|
||||
{
|
||||
var imgs = root.GetComponentsInChildren<Image>(true);
|
||||
if (imgs == null || imgs.Length == 0) return null;
|
||||
if (!string.IsNullOrEmpty(nameContains))
|
||||
{
|
||||
string target = nameContains.Replace(" ", "");
|
||||
for (int i = 0; i < imgs.Length; i++)
|
||||
{
|
||||
var img = imgs[i];
|
||||
if (img == null) continue;
|
||||
string n = img.name.Replace(" ", "");
|
||||
if (n.IndexOf(target, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return img;
|
||||
}
|
||||
}
|
||||
return imgs[0];
|
||||
return FindChildGraphicExact(imgs, exactName);
|
||||
}
|
||||
|
||||
private static RawImage FindChildRawImage(Transform root, string nameContains)
|
||||
private static Image FindChildGraphicExact(Image[] imgs, string exactName)
|
||||
{
|
||||
if (imgs == null || string.IsNullOrWhiteSpace(exactName)) return null;
|
||||
for (int i = 0; i < imgs.Length; i++)
|
||||
{
|
||||
var img = imgs[i];
|
||||
if (img == null) continue;
|
||||
if (string.Equals(img.name, exactName, StringComparison.OrdinalIgnoreCase))
|
||||
return img;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static RawImage FindChildRawImage(Transform root, string exactName)
|
||||
{
|
||||
var raws = root.GetComponentsInChildren<RawImage>(true);
|
||||
if (raws == null || raws.Length == 0) return null;
|
||||
if (!string.IsNullOrEmpty(nameContains))
|
||||
if (string.IsNullOrWhiteSpace(exactName)) return null;
|
||||
for (int i = 0; i < raws.Length; i++)
|
||||
{
|
||||
string target = nameContains.Replace(" ", "");
|
||||
for (int i = 0; i < raws.Length; i++)
|
||||
{
|
||||
var img = raws[i];
|
||||
if (img == null) continue;
|
||||
string n = img.name.Replace(" ", "");
|
||||
if (n.IndexOf(target, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return img;
|
||||
}
|
||||
var raw = raws[i];
|
||||
if (raw == null) continue;
|
||||
if (string.Equals(raw.name, exactName, StringComparison.OrdinalIgnoreCase))
|
||||
return raw;
|
||||
}
|
||||
return raws[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TMP_Text FindChildTmp(Transform root, string nameContains)
|
||||
{
|
||||
var tmps = root.GetComponentsInChildren<TMP_Text>(true);
|
||||
if (tmps == null || tmps.Length == 0) return null;
|
||||
var exact = FindChildTmpExact(tmps, "TEXT");
|
||||
if (exact != null) return exact;
|
||||
if (!string.IsNullOrEmpty(nameContains))
|
||||
{
|
||||
string target = nameContains.Replace(" ", "");
|
||||
@@ -527,10 +573,25 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
return tmps[0];
|
||||
}
|
||||
|
||||
private static TMP_Text FindChildTmpExact(TMP_Text[] tmps, string exactName)
|
||||
{
|
||||
if (tmps == null || string.IsNullOrWhiteSpace(exactName)) return null;
|
||||
for (int i = 0; i < tmps.Length; i++)
|
||||
{
|
||||
var tmp = tmps[i];
|
||||
if (tmp == null) continue;
|
||||
if (string.Equals(tmp.name, exactName, StringComparison.OrdinalIgnoreCase))
|
||||
return tmp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Text FindChildLegacyText(Transform root, string nameContains)
|
||||
{
|
||||
var texts = root.GetComponentsInChildren<Text>(true);
|
||||
if (texts == null || texts.Length == 0) return null;
|
||||
var exact = FindChildLegacyTextExact(texts, "TEXT");
|
||||
if (exact != null) return exact;
|
||||
if (!string.IsNullOrEmpty(nameContains))
|
||||
{
|
||||
string target = nameContains.Replace(" ", "");
|
||||
@@ -546,6 +607,19 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
return texts[0];
|
||||
}
|
||||
|
||||
private static Text FindChildLegacyTextExact(Text[] texts, string exactName)
|
||||
{
|
||||
if (texts == null || string.IsNullOrWhiteSpace(exactName)) return null;
|
||||
for (int i = 0; i < texts.Length; i++)
|
||||
{
|
||||
var text = texts[i];
|
||||
if (text == null) continue;
|
||||
if (string.Equals(text.name, exactName, StringComparison.OrdinalIgnoreCase))
|
||||
return text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void EnsureRaycastTarget(GameObject go)
|
||||
{
|
||||
var graphics = go.GetComponentsInChildren<Graphic>(true);
|
||||
@@ -656,10 +730,8 @@ public class UI_FunctionHoverGuide : MonoBehaviour
|
||||
{
|
||||
if (!scene.IsValid()) return;
|
||||
if (scene.name.IndexOf("UI_UI", StringComparison.OrdinalIgnoreCase) < 0) return;
|
||||
if (UnityEngine.Object.FindAnyObjectByType<UI_FunctionHoverGuide>() != null) return;
|
||||
if (SceneObjectLookupCache.FindAny<UI_FunctionHoverGuide>() != null) return;
|
||||
var go = new GameObject("UI_FunctionHoverGuide");
|
||||
go.AddComponent<UI_FunctionHoverGuide>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user