using System; using UnityEngine; public class PurchaseButton : MonoBehaviour { public StoreMenu Parent { get; set; } public SpriteRenderer PurchasedIcon; public TextRenderer NameText; public SpriteRenderer HatImage; public Sprite MannequinFrame; public SpriteRenderer Background; public IBuyable Product; public bool Purchased; public string Name; public string Price; public string ProductId; public void SetItem(IBuyable product, string productId, string name, string price, bool purchased) { this.Product = product; this.Purchased = purchased; this.Name = name; this.Price = price; this.ProductId = productId; this.PurchasedIcon.enabled = this.Purchased; if (this.Product is HatBehaviour) { HatBehaviour hat = (HatBehaviour)this.Product; this.NameText.gameObject.SetActive(false); this.HatImage.transform.parent.gameObject.SetActive(true); PlayerControl.SetHatImage(hat, this.HatImage); this.SetSquare(); return; } if (this.Product is SkinData) { SkinData skin = (SkinData)this.Product; this.NameText.gameObject.SetActive(false); this.HatImage.transform.parent.gameObject.SetActive(true); this.HatImage.transform.parent.GetComponent().sprite = this.MannequinFrame; this.HatImage.transform.parent.localPosition = new Vector3(0f, 0f, -0.01f); this.HatImage.transform.parent.localScale = Vector3.one * 0.3f; this.HatImage.transform.localPosition = new Vector3(0f, 0f, -0.01f); this.HatImage.transform.localScale = Vector3.one * 2f; PlayerControl.SetSkinImage(skin, this.HatImage); this.SetSquare(); return; } if (this.Product is PetBehaviour) { PetBehaviour petBehaviour = (PetBehaviour)this.Product; this.NameText.gameObject.SetActive(false); this.HatImage.transform.parent.gameObject.SetActive(true); this.HatImage.transform.parent.GetComponent().enabled = false; this.HatImage.material = new Material(petBehaviour.rend.sharedMaterial); PlayerControl.SetPetImage(petBehaviour, (int)SaveManager.BodyColor, this.HatImage); this.SetSquare(); return; } this.NameText.Text = this.Name; } private void SetSquare() { this.Background.size = new Vector2(0.7f, 0.7f); this.Background.GetComponent().size = new Vector2(0.7f, 0.7f); this.PurchasedIcon.transform.localPosition = new Vector3(0f, 0f, -1f); } internal void SetPurchased() { this.Purchased = true; this.PurchasedIcon.enabled = true; } public void DoPurchase() { this.Parent.SetProduct(this); } }