Foerming/Assets/Scripts/HoverManager.cs
d-hain ce1f6ed389 added cost amount to items
added Shop UI
added Shop.cs
 * you now can buy items and you lose the cost when bought
 * shop is scrollable

added comments in Inventory.cs, InventorySlot.cs, InventoryUI.cs
now showing description when hovering over items in shop or inventory
2022-06-02 00:08:37 +02:00

48 lines
No EOL
1.4 KiB
C#

using System;
using TMPro;
using UnityEngine;
public class HoverManager : MonoBehaviour {
public TextMeshProUGUI descriptionText;
public RectTransform descriptionHoverBackground;
public static Action<string, Vector2> onMouseHover;
public static Action onMouseExit;
private void OnEnable() {
onMouseHover += ShowDescription;
onMouseExit += HideDescription;
}
private void OnDisable() {
onMouseHover -= ShowDescription;
onMouseExit -= HideDescription;
}
private void Start() {
HideDescription();
}
/**
* Show the description Text at the mouse position
*/
private void ShowDescription(string description, Vector2 mousePos) {
descriptionText.text = description;
descriptionHoverBackground.sizeDelta =
new Vector2(descriptionText.preferredWidth > 200 ? 200 : descriptionText.preferredWidth,
descriptionText.preferredHeight);
descriptionHoverBackground.gameObject.SetActive(true);
float descBgX = descriptionHoverBackground.sizeDelta.x;
descriptionHoverBackground.transform.position =
new Vector2(mousePos.x + (descBgX / 2) + (descBgX / 16), mousePos.y);
}
/**
* Hide the description Text
*/
private void HideDescription() {
descriptionText.text = default;
descriptionHoverBackground.gameObject.SetActive(false);
}
}