using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class BasicProductUI : MonoBehaviour, IProductUI { private delegate void ActionDelegate(); public int id; public GameObject uiName; public Image uiImage; public GameObject uiPrice; public GameObject uiDescription; public Button uiPurchaseButton; public GameObject uiPurchaseText; public Image frontPanel; public Sprite frontBackgroundUnlocked; public Sprite frontBackgroundLocked; public void SetInformation(int id, string name, string description, Sprite image, int price, bool isBuyable) { this.id = id; uiName.GetComponent().SetText(name); uiImage.sprite = image; uiPrice.GetComponent().SetText(price.ToString()); uiDescription.GetComponent().SetText(description); uiPurchaseText.GetComponent().SetText("Acheter pour " + price.ToString()); StoreManager storeManager = GameObject.FindGameObjectWithTag("GameController")?.GetComponent(); uiPurchaseButton.GetComponent().SetClickAction(() => storeManager.BuyProduct(id)); UpdateUI(isBuyable); } public void UpdateUI(bool isBuyable) { if(isBuyable) { uiPurchaseButton.interactable = true; frontPanel.sprite = frontBackgroundUnlocked; } else { uiPurchaseButton.interactable = false; frontPanel.sprite = frontBackgroundLocked; } } public void ClickTrigger() { GetComponent().SetBool("Acquired", true); } public void HighlightTrigger() { GetComponent().SetBool("Hover", true); } public void PressTrigger() { HighlightTrigger(); } public void NormalTrigger() { GetComponent().SetBool("Hover", false); GetComponent().SetBool("Acquired", false); } }