Files
MinFt/Client/Assets/Scripts/UI/Grade/PlayerGradeReward.cs
2026-04-27 12:07:32 +08:00

64 lines
2.2 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerGradeReward : MonoBehaviour
{
PanelScroll scrollRect;
Image bar;
GameObject gradeItem;
List<GradeItemData> gradeDatas = new List<GradeItemData>();
float itemHigh = 250;
private void Awake()
{
bar = transform.Find("ScrollView/Viewport/Content/bg_bar/bar").GetComponent<Image>();
scrollRect = transform.Find("ScrollView").GetComponent<PanelScroll>();
gradeItem = transform.Find("ScrollView/Viewport/Content/item").gameObject;
gradeItem.SetActive(false);
itemHigh = gradeItem.GetComponent<RectTransform>().sizeDelta.y;
scrollRect.isReversal = true;
}
private void Start()
{
gradeDatas.Clear();
var account = GContext.container.Resolve<Tables>().TbAccount.DataList;
int nextIndex = account.Count - 1;
for (int i = 0; i < account.Count; i++)
{
if (GContext.container.Resolve<PlayerData>().lv < account[i].ID)
{
nextIndex = i;
break;
}
}
bar.fillAmount = (GContext.container.Resolve<PlayerData>().lv - 1) / ((float)account[0].ID - 1);
int showCount = nextIndex + 10;
if (showCount > account.Count)
{
showCount = account.Count;
}
for (int i = 0; i < showCount; i++)
{
gradeDatas.Add(new GradeItemData() { account = account[i], nextIndex = nextIndex });
}
if (nextIndex > 0)
{
int startLv = account[nextIndex - 1].ID;
var nextAccountData = account[nextIndex];
gradeDatas[nextIndex - 1].fillAmount = (GContext.container.Resolve<PlayerData>().lv - startLv) / (float)(nextAccountData.ID - startLv);
gradeDatas[nextIndex].next = true;
nextIndex--;
}
else if (GContext.container.Resolve<PlayerData>().lv < account[0].ID)
{
gradeDatas[0].next = true;
}
gradeDatas[^1].bar = false;
scrollRect.Init<GradeItem, GradeItemData>(itemHigh, gradeItem, null, gradeDatas, _currentIndex: nextIndex, _minShowAdd: 3);
}
}