using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections.Generic; using System.Collections; using System.IO; public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { [Header("Inspector")] public Image dlc_profileImgae; public Text dlcName; public Text dlcID; public Text dlcProducer; public Text dlcPubliushDate; public Text dlcSongsAmount; public Image dlc_nowSelectedImageBoarder; [Header("Inspector")] public GameObject dlcDetailParent; public Text dlcDescription; [Header("Inspector")] public dlcData dlcDataSO; [Header("Inspector")] public List dlcContent = new List(); [Header("Inspector")] public string editorSearchFolder = "Assets/Resources/dlc_dlcIndex"; public string runtimeResourcesFolder = "Resources/dlc_dlcIndex"; private Button _btn; public bool Resolved { get; private set; } // Shared cache to avoid repeated Resources.LoadAll scans private static Dictionary cachedById = new Dictionary(); private static List cachedAll = new List(); private static bool cacheBuilt = false; private static bool cacheBuilding = false; private static string cachedFolder = string.Empty; // Selection management (shared across all dlcButton instances) private static List allButtons = new List(); private static int selectedIndex = -1; private const string PlayerPrefsKey = "dlc_selected_index"; private int instanceIndex = -1; private Coroutine hoverCoroutine; public void OnPointerEnter(PointerEventData eventData) { if (hoverCoroutine != null) StopCoroutine(hoverCoroutine); hoverCoroutine = StartCoroutine(HandleHover()); } public void OnPointerExit(PointerEventData eventData) { if (hoverCoroutine != null) StopCoroutine(hoverCoroutine); if (dlcDetailParent != null) dlcDetailParent.SetActive(false); } private IEnumerator HandleHover() { yield return new WaitForSecondsRealtime(0.5f); // 尝试从场景中查找 dlcDetailParent (如果自身引用的为空) if (dlcDetailParent == null) { var details = GameObject.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None); foreach (var b in details) { if (b != this && b.dlcDetailParent != null) { dlcDetailParent = b.dlcDetailParent; dlcDescription = b.dlcDescription; break; } } } if (dlcDetailParent != null) { dlcDetailParent.SetActive(true); // 更新简介信息 if (dlcDescription != null) { if (dlcDataSO != null) { dlcDescription.text = string.IsNullOrEmpty(dlcDataSO.dlcDescription) ? "暂无DLC简介信息。" : dlcDataSO.dlcDescription; } else { dlcDescription.text = "暂无DLC简介信息。"; } } } } void Awake() { _btn = GetComponent