| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using Sirenix.OdinInspector;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public struct Treasure
- {
- public int id;
- public string name;
- public Sprite sprite;
- public Sprite qualityBox;
- public Color qualityText;
- public List<int> tagsId;
- public List<Sprite> tags;
- public string attribute;
- public int price;
- public List<string> type;
- public List<float> data;
- public Treasure(int id, string name, Sprite sprite, Sprite qualityBox, Color qualityText, List<int> tagsId, List<Sprite> tags, string attribute, int price, List<string> type, List<float>data)
- {
- this.id = id;
- this.name = name;
- this.sprite = sprite;
- this.qualityBox = qualityBox;
- this.qualityText = qualityText;
- this.tagsId = new List<int>(tagsId);
- this.tags = new List<Sprite>(tags);
- this.attribute = attribute;
- this.price = price;
- this.type = type;
- this.data = data;
- }
- }
- public class TreasuresSaleUI : MonoBehaviour
- {
- [FoldoutGroup("组件")] public ShopUI shopUI;
- [FoldoutGroup("组件")] public ButtonUI unlock;
- [FoldoutGroup("组件")] public Image iconBackground;
- [FoldoutGroup("组件")] public Image icon;
- [FoldoutGroup("组件")] public Image[] tags;
- [FoldoutGroup("组件")] public TextMeshProUGUI nameText;
- [FoldoutGroup("组件")] public TextMeshProUGUI attribute;
- [FoldoutGroup("组件")] public ButtonUI buy;
- [FoldoutGroup("组件")] public TextMeshProUGUI price;
- [FoldoutGroup("组件")] public List<Sprite> TreasureBackgrounds;
- [FoldoutGroup("组件")] public Image background;
- public bool islock;
- public bool isNull;
- public Treasure treasure;
- public TreasureInBag owner;
- private void Update()
- {
- if(owner!=null && gameObject.activeSelf)
- {
- transform.position = owner.transform.position;
- }
- }
- public void Init()
- {
- if (unlock != null)
- {
- ShowLockImg();
- }
-
- iconBackground.sprite = treasure.qualityBox;
- icon.sprite = treasure.sprite;
- int type = treasure.tags.Count % 2;
- int len = treasure.tags.Count / 2;
- float interval = shopUI.interval;
- float left = 0;
- switch (type)
- {
- case 0:
- left = -interval / 2 - (len - 1) * interval;
- break;
- case 1:
- left = -len * interval;
- break;
- }
- for (int i = 0; i < 8; i++)
- {
- Image tag = tags[i];
- if (i < treasure.tags.Count)
- {
- tag.transform.localPosition = new Vector3(left + i * interval, 0, 0);
- tag.sprite = treasure.tags[i];
- tag.gameObject.SetActive(true);
- }
- else
- {
- tag.gameObject.SetActive(false);
- }
- }
- if (treasure.tags.Count == 0)
- {
- background.sprite = TreasureBackgrounds[1];
- }
- else
- {
- background.sprite = TreasureBackgrounds[0];
- }
- nameText.text = treasure.name;
- nameText.color = treasure.qualityText;
- attribute.text = treasure.attribute;
- if (price != null)
- {
- price.text = $"{treasure.price}";
- gameObject.SetActive(true);
- }
- isNull = false;
- }
- public void ChangeLock()
- {
- islock = !islock;
- ShowLockImg();
- }
- public void ShowLockImg()
- {
- if (islock)
- {
- unlock.ChangeImg(1);
- }
- else
- {
- unlock.ChangeImg(0);
- }
- }
- public void Buy()
- {
- GameManager gameManager = GameManager.instance;
- if(gameManager.money - treasure.price < 0)
- {
- return;
- }
- gameManager.money -= treasure.price;
- shopUI.moneyText.text = $"{gameManager.money}";
- gameManager.myTreasures.Add(treasure);
- for(int i = 0; i < treasure.tagsId.Count; i++)
- {
- gameManager.myTreasuresTag[treasure.tagsId[i] - 1]++;
- }
- List<int> tagsId = gameManager.myTreasuresTag;
- int maxId = tagsId[0];
- for (int i = 1; i < 8; i++)
- {
- maxId = Mathf.Max(maxId, tagsId[i]);
- }
- gameManager.maxTreasuresTag = maxId;
- shopUI.DrawUIPolygon();
- shopUI.DrawBag();
- gameObject.SetActive(false);
- isNull = true;
- islock = false;
- gameManager.GetTreasure(treasure);
- }
- }
|