using System; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class SelctedItem : MonoBehaviour, IPointerClickHandler { public SelctedGroup selctedGroup; public int ItemIndex; [SerializeField] public bool isOpen = false; public void Init() { switch (ItemIndex) { case 1://注入器 this.GetComponent().sprite = Resources.Load("image/yuankong"); break; case 2: this.GetComponent().sprite = Resources.Load("image/baibang"); break; case 3: this.GetComponent().sprite = Resources.Load("image/baibang"); break; case 4://设备 this.GetComponent().sprite = Resources.Load("image/yuankong"); break; } } public void OnPointerClick(PointerEventData eventData) { isOpen = !isOpen; if (isOpen) { selctedGroup.ShowItemList(ItemIndex); selctedGroup.CurrentItem = this; } else { selctedGroup.ResetItemList(); } } private void Update() { if (selctedGroup.CurrentItem != this) { isOpen = false; } } }