| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using cfg;
- using Sirenix.OdinInspector;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- public class ShopUI : MonoBehaviour
- {
- [FoldoutGroup("组件")] public TextMeshProUGUI moneyText;
- [FoldoutGroup("组件")] public TreasuresSaleUI[] treasuresSaleUI;
- [FoldoutGroup("组件")] public Sprite[] tagsUI;
- [FoldoutGroup("组件")] public TextMeshProUGUI refreshPriceText;
- [FoldoutGroup("组件")] public RadarChart radarChart;
- [FoldoutGroup("组件")] public GameObject treasureInBag;
- [FoldoutGroup("组件")] public GameObject treasureDetails_inBag;
- [FoldoutGroup("组件")] public Transform bagContent;
- [FoldoutGroup("组件")] public Transform detailsParent;
- [FoldoutGroup("组件")] public Sprite[] qualityBox;
- [FoldoutGroup("组件")] public Color[] qualitysText;
- [FoldoutGroup("组件")] public TextMeshProUGUI[] polygonText;
- [FoldoutGroup("组件")] public List<Sprite> treasureBackgrounds;
- [LabelText("标签间隔")] public float interval;
- [LabelText("雷达图初始最大值")] public int polygonInitMax;
- [LabelText("雷达图最大值间隔")] public int polygonMaxInterval;
- public int refreshPrice;
- public int refreshNum;
-
- public void Init()
- {
- GameManager gameManager = GameManager.instance;
- refreshPrice = refreshNum + 1;
- moneyText.text = $"{gameManager.money}";
- refreshPriceText.text = $"-{refreshPrice}";
- //List<int> randomTreasure = new List<int>();
- //for (int i = 0; i < 5; i++)
- //{
- // if (treasuresSaleUI[i].islock)
- // {
- // randomTreasure.Add(treasuresSaleUI[i].treasure.id);
- // }
- //}
- for (int i = 0; i < 5; i++)
- {
- if (treasuresSaleUI[i].islock)
- {
- continue;
- }
- int targetQualityID = 0;
- float randomQuality = Random.Range(0f, 100f);
- float refreshChance = 0;
- for(int j = 0; j < 4; j++)
- {
- refreshChance += gameManager.trueRefreshChance[j];
- if(randomQuality <= refreshChance)
- {
- targetQualityID = j;
- break;
- }
- }
- int targetTag = 0;
- if(targetQualityID != 0 && gameManager.maxTreasuresTag!=-1)
- {
- int targetTagWeight = -1;
- float randomTagWeight = Random.Range(0f, 100f);
- refreshChance = 0;
- for (int j = 0; j < 3; j++)
- {
- refreshChance += gameManager.tagWeight[j];
- if (randomTagWeight <= refreshChance)
- {
- targetTagWeight = j;
- break;
- }
- }
- switch (targetTagWeight)
- {
- case 0:
- targetTag = gameManager.maxTreasuresTag + 1;
- break;
- case 1:
- List<int> targetTags = new List<int>();
- for(int j = 0; j < 8; j++)
- {
- if(gameManager.myTreasuresTag[j] > 0)
- {
- targetTags.Add(j + 1);
- }
- }
- targetTag = targetTags[Random.Range(0, targetTags.Count)];
- break;
- }
- }
- int randId = Random.Range(0, gameManager.treasuresList[targetQualityID][targetTag].Count);
- SingleTreasureConfig singleTreasureConfig = gameManager.treasuresList[targetQualityID][targetTag][randId];
- //while (randomTreasure.Exists(x => x == singleTreasureConfig.ID))
- //{
- // randId = Random.Range(0, gameManager.treasuresList[targetQualityID][targetTag].Count);
- // singleTreasureConfig = gameManager.treasuresList[targetQualityID][targetTag][randId];
- // string aa = "";
- // for (int a = 0; a < randomTreasure.Count; a++)
- // {
- // aa += $"{randomTreasure[a]}";
- // }
- // Debug.Log(aa);
- // Debug.Log($"{singleTreasureConfig.ID}");
- //}
- Sprite sprite = Resources.Load<Sprite>($"Textures/UI/Treasure/{singleTreasureConfig.SpriteName}");
- List<Sprite> tags = new List<Sprite>();
- for (int j = 0; j < singleTreasureConfig.Tag.Count; j++)
- {
- tags.Add(tagsUI[singleTreasureConfig.Tag[j] - 1]);
- }
- Treasure treasure = new Treasure(
- singleTreasureConfig.ID,
- singleTreasureConfig.Name,
- sprite,
- treasureBackgrounds[singleTreasureConfig.Quality],
- qualityBox[singleTreasureConfig.Quality],
- qualitysText[singleTreasureConfig.Quality],
- singleTreasureConfig.Tag,
- tags,
- singleTreasureConfig.Attribute,
- singleTreasureConfig.Price,
- singleTreasureConfig.Type,
- singleTreasureConfig.Data
- );
- treasuresSaleUI[i].treasure = treasure;
- treasuresSaleUI[i].Init();
- //randomTreasure.Add(singleTreasureConfig.ID);
- }
- DrawUIPolygon();
- DrawBag();
- gameObject.SetActive(true);
- }
- public void Refresh()
- {
- if(GameManager.instance.money - refreshPrice < 0)
- {
- return;
- }
- GameManager.instance.money -= refreshPrice;
- refreshNum += 1;
- Init();
- }
- public void DrawUIPolygon()
- {
- GameManager gameManager = GameManager.instance;
- int range = polygonInitMax;
- while (range <= gameManager.maxTreasuresTag)
- {
- range += polygonMaxInterval;
- }
- List<float> polygon = new List<float>();
- for(int i = 0; i < 8; i++)
- {
- float rate = gameManager.myTreasuresTag[i] * 1f / range;
- polygon.Add(rate);
- }
- radarChart.SetRatioList(polygon);
- }
- public void DrawBag()
- {
- List<Treasure> treasures = GameManager.instance.myTreasures;
- for(int i = 0; i < treasures.Count; i++)
- {
- TreasureInBag treasureInBag;
- TreasuresSaleUI treasuresSaleUI;
- if (i >= bagContent.childCount)
- {
- GameObject obj = Instantiate(this.treasureInBag,bagContent);
- GameObject objDetails = Instantiate(treasureDetails_inBag, detailsParent);
- objDetails.SetActive(false);
- treasureInBag = obj.GetComponent<TreasureInBag>();
- treasuresSaleUI = objDetails.GetComponent<TreasuresSaleUI>();
- }
- else
- {
- treasureInBag = bagContent.GetChild(i).GetComponent<TreasureInBag>();
- treasuresSaleUI = detailsParent.GetChild(i).GetComponent<TreasuresSaleUI>();
- }
- treasureInBag.treasuresSaleUI = treasuresSaleUI;
- treasureInBag.sprite = treasures[i].sprite;
- treasureInBag.box = treasures[i].qualityBox;
- treasureInBag.shopUI = this;
- treasuresSaleUI.owner = treasureInBag;
- treasuresSaleUI.treasure = treasures[i];
- treasuresSaleUI.transform.position = treasureInBag.transform.position;
- treasureInBag.Refresh();
- }
- for(int i = treasures.Count; i < bagContent.childCount; i++)
- {
- Destroy(bagContent.GetChild(i));
- }
- }
- }
|