备份CatanBuilding瘦身独立工程
This commit is contained in:
63
Assets/Scripts/UI/Grade/PlayerGradeReward.cs
Normal file
63
Assets/Scripts/UI/Grade/PlayerGradeReward.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user