using GeometryTD.CustomEvent; using GeometryTD.Definition; using UnityEngine; namespace GeometryTD.UI { public class CombineSlotItem : MonoBehaviour { [SerializeField] private TowerCompSlotType _acceptSlotType = TowerCompSlotType.None; [SerializeField] private IconArea _iconArea; [SerializeField] private CommonButton _button; private long _boundItemId; private int _slotIndex = -1; public TowerCompSlotType AcceptSlotType => _acceptSlotType; public bool HasItem => _boundItemId > 0; public int SlotIndex => _slotIndex; public long BoundItemId => _boundItemId; public void OnInit(int slotIndex) { _slotIndex = slotIndex; ClearSlot(); _iconArea.OnReset(); } public void BindItem(RepoItemContext itemContext) { _boundItemId = itemContext?.InstanceId ?? 0; _button.Interactive = true; if (itemContext != null) { _iconArea.OnInit(itemContext.IconAreaContext); } } public void ClearSlot() { _boundItemId = 0; _button.Interactive = false; _iconArea.OnReset(); } public void OnReset() { _slotIndex = -1; ClearSlot(); _iconArea.OnReset(); } public void OnClick() { if (_slotIndex < 0) { return; } GameEntry.Event.Fire(this, CombineSlotClickedEventArgs.Create(_slotIndex)); } } }