备份CatanBuilding瘦身独立工程
This commit is contained in:
90
Assets/Scripts/OfferChainsChest/OfferChainsInfoPanel.cs
Normal file
90
Assets/Scripts/OfferChainsChest/OfferChainsInfoPanel.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using DataCenter;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace OfferChainsChest
|
||||
{
|
||||
internal class UIElement
|
||||
{
|
||||
public RewardItemNew Reward;
|
||||
public TMP_Text TextProbability;
|
||||
}
|
||||
public class OfferChainsInfoPanel : MonoBehaviour
|
||||
{
|
||||
private const int MaxElem = 8;
|
||||
|
||||
private OfferChainsChestManager _offerChainsChestManager;
|
||||
|
||||
private TMP_Text _textInfo;
|
||||
private TMP_Text _textTitle;
|
||||
private readonly UIElement[] _uiElements = new UIElement[MaxElem];
|
||||
//
|
||||
// private List<ItemData> _itemDataList = new ();
|
||||
private struct WeightItemData
|
||||
{
|
||||
public ItemData ItemData;
|
||||
public float Weight;
|
||||
}
|
||||
private readonly List<WeightItemData> _weightItemDataList = new();
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_offerChainsChestManager = GContext.container.Resolve<OfferChainsChestManager>();
|
||||
|
||||
_textInfo = transform.Find("root/text_info").GetComponent<TMP_Text>();
|
||||
_textTitle = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
||||
|
||||
for (var i = 0; i < MaxElem; ++i)
|
||||
{
|
||||
var fixIdx = i + 1;
|
||||
_uiElements[i] = new UIElement
|
||||
{
|
||||
Reward = transform.Find($"root/layout/reward_{fixIdx}/reward").GetComponent<RewardItemNew>(),
|
||||
TextProbability = transform.Find($"root/layout/reward_{fixIdx}/text_probability").GetComponent<TMP_Text>(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var items= _offerChainsChestManager.OfferChainsData.Items;
|
||||
_weightItemDataList.Clear();
|
||||
foreach (var item in items)
|
||||
{
|
||||
_weightItemDataList.Add(new WeightItemData
|
||||
{
|
||||
ItemData = new ItemData
|
||||
{
|
||||
id = item.Item,
|
||||
count = item.Number,
|
||||
},
|
||||
Weight = item.Status == 2 ? 1000: _offerChainsChestManager.GetProbability(item.Id),
|
||||
});
|
||||
}
|
||||
_weightItemDataList.Sort((p1, p2) => p1.Weight.CompareTo(p2.Weight));
|
||||
Log($"_weightItemDataList -> {string.Join(',', _weightItemDataList)}");
|
||||
for ( var i = 0;i < MaxElem; ++i)
|
||||
{
|
||||
var weightItemData = _weightItemDataList[i];
|
||||
_uiElements[i].Reward.SetData(weightItemData.ItemData);
|
||||
_uiElements[i].TextProbability.text = weightItemData.Weight >= 1000 ? "" : $"{weightItemData.Weight}%";
|
||||
_uiElements[i].Reward.SetReceived(weightItemData.Weight >= 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private void Log(string t)
|
||||
{
|
||||
Debug.Log($"<color=purple>OfferChainsInfoPanel ->{t}</color>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user