diff options
| author | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
| commit | 7f493f682503f5186308de7b8f74b5b49233cfe4 (patch) | |
| tree | 8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/PerkSelectionItem.cs | |
+init
Diffstat (limited to 'GameCode/PerkSelectionItem.cs')
| -rw-r--r-- | GameCode/PerkSelectionItem.cs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/GameCode/PerkSelectionItem.cs b/GameCode/PerkSelectionItem.cs new file mode 100644 index 0000000..6e43dea --- /dev/null +++ b/GameCode/PerkSelectionItem.cs @@ -0,0 +1,80 @@ +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +public class PerkSelectionItem : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler +{ + private LevelSelectManager levelSelectManager; + + [SerializeField] + private GameObject selectedMarker; + + private PerkSelectionGroup perkSelectionGroup; + + private Color colorBasic; + + private Image image; + + [SerializeField] + private Color hoverColor; + + private bool mouseIsOver; + + private Equippable equippable; + + public Equippable Equippable => equippable; + + public bool Selected + { + get + { + return selectedMarker.activeInHierarchy; + } + set + { + selectedMarker.SetActive(value); + } + } + + public void OnPointerEnter(PointerEventData eventData) + { + mouseIsOver = true; + } + + public void OnPointerExit(PointerEventData eventData) + { + mouseIsOver = false; + if (levelSelectManager.ShowingTooltipFor == equippable) + { + levelSelectManager.ShowTooltip(null); + } + } + + private void Update() + { + image.color = (mouseIsOver ? hoverColor : colorBasic); + if (mouseIsOver) + { + levelSelectManager.ShowTooltip(equippable); + } + if (Input.GetMouseButtonDown(0) && mouseIsOver && (bool)perkSelectionGroup) + { + perkSelectionGroup.SelectPerk(this); + } + } + + public void Initialize(Equippable _equippable) + { + image = GetComponent<Image>(); + colorBasic = image.color; + perkSelectionGroup = GetComponentInParent<PerkSelectionGroup>(); + Debug.Log(perkSelectionGroup); + levelSelectManager = LevelSelectManager.instance; + image.sprite = _equippable.icon; + equippable = _equippable; + if (PerkManager.instance.CurrentlyEquipped.Contains(equippable) && (bool)perkSelectionGroup) + { + perkSelectionGroup.SelectPerk(this); + } + } +} |
