using UnityEngine; using UnityEngine.UI; using TMPro; public class eqpmtSkillPrefabItem : MonoBehaviour { public int skillId; public Image skillIcon; public Text skillName; public Text skillIdText; public void Bind(int id) { skillId = id; SkillGroup skillGroup = EquipmentSkillGroupLibrary.ResolveSkillGroup(skillId); string displayName = skillGroup != null && !string.IsNullOrWhiteSpace(skillGroup.groupName) ? skillGroup.groupName : $"Skill {skillId}"; Sprite displayIcon = skillGroup != null ? skillGroup.groupIcon : null; EnsureFallbackReferences(); if (skillName != null) { skillName.text = displayName; } else { TMP_Text tmpName = GetFirstTmpTextExcludingId(); if (tmpName != null) { tmpName.text = displayName; } } if (skillIdText != null) { skillIdText.text = skillId.ToString(); } else { TMP_Text tmpId = GetLastTmpText(); if (tmpId != null) { tmpId.text = skillId.ToString(); } } if (skillIcon != null) { skillIcon.sprite = displayIcon; skillIcon.enabled = displayIcon != null; } } private void EnsureFallbackReferences() { if (skillIcon == null) { Image[] images = GetComponentsInChildren(true); for (int i = 0; i < images.Length; i++) { if (images[i] != null && images[i] != GetComponent()) { skillIcon = images[i]; break; } } } if (skillName == null || skillIdText == null) { Text[] texts = GetComponentsInChildren(true); if (texts.Length > 0) { if (skillName == null) { skillName = texts[0]; } if (skillIdText == null && texts.Length > 1) { skillIdText = texts[texts.Length - 1]; } } } } private TMP_Text GetFirstTmpTextExcludingId() { TMP_Text[] texts = GetComponentsInChildren(true); return texts.Length > 0 ? texts[0] : null; } private TMP_Text GetLastTmpText() { TMP_Text[] texts = GetComponentsInChildren(true); return texts.Length > 1 ? texts[texts.Length - 1] : null; } }