102 lines
3.1 KiB
C#
102 lines
3.1 KiB
C#
using System;
|
|
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using PlayFab.ClientModels;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class SocialLeadboardItem : PanelItemBase<LeadboardItemData>
|
|
{
|
|
public GameObject bg_myself;
|
|
List<GameObject> rank = new List<GameObject>();
|
|
public TMP_Text text_rank;
|
|
public TMP_Text text_name;
|
|
public Head head;
|
|
public TMP_Text text_count;
|
|
public TMP_Text text_count_skyscraper;
|
|
string playFabId;
|
|
bool isInit;
|
|
GameObject skyscraper;
|
|
|
|
//private void Awake()
|
|
//{
|
|
// if (!isInit)
|
|
// {
|
|
// InitPanel();
|
|
// }
|
|
//}
|
|
void InitPanel()
|
|
{
|
|
skyscraper = transform.Find("icon_skyscraper").gameObject;
|
|
bg_myself = transform.Find("bg_myself").gameObject;
|
|
text_rank = transform.Find("rank/rank/text_rank").GetComponent<TMP_Text>();
|
|
text_name = transform.Find("text_name").GetComponent<TMP_Text>();
|
|
head = transform.Find("btn_head").GetComponent<Head>();
|
|
//reward_panel = transform.Find("reward_panel").gameObject;
|
|
text_count = transform.Find("icon_rank/text_num").GetComponent<TMP_Text>();
|
|
text_count_skyscraper = transform.Find("icon_skyscraper/text_num").GetComponent<TMP_Text>();
|
|
Transform rank_panel = transform.Find("rank");
|
|
rank.Clear();
|
|
for (int i = 0; i < rank_panel.childCount; i++)
|
|
{
|
|
rank.Add(rank_panel.GetChild(i).gameObject);
|
|
}
|
|
isInit = true;
|
|
}
|
|
public override void OnInit()
|
|
{
|
|
if (!isInit)
|
|
{
|
|
InitPanel();
|
|
}
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
playFabId = data.playFabId;
|
|
bg_myself.SetActive(data.playFabId == userService.UserId);
|
|
for (int i = 0; i < rank.Count - 1; i++)
|
|
{
|
|
rank[i].SetActive(data.rank == i + 1);
|
|
}
|
|
rank[^1].SetActive(data.rank >= rank.Count);
|
|
text_rank.text = data.rank.ToString();
|
|
int level = data.value / LeadboardData.LV_MODELING;
|
|
int level2 = data.value % LeadboardData.LV_MODELING;
|
|
if (level > 0)
|
|
{
|
|
text_count.text = level.ToString();
|
|
text_count_skyscraper.text = level2.ToString();
|
|
}
|
|
else
|
|
{
|
|
text_count_skyscraper.text = "0";
|
|
text_count.text = data.value.ToString();
|
|
}
|
|
skyscraper.SetActive(level2 > 0);
|
|
|
|
text_name.text = data.displayName;
|
|
head.SetData(data.avatarUrl);
|
|
}
|
|
}
|
|
public class LeadboardItemData
|
|
{
|
|
public int position;
|
|
public int rank;
|
|
public int value = 1;
|
|
//public string entityKey;
|
|
public string playFabId;
|
|
public string displayName;
|
|
public string avatarUrl;
|
|
public DateTime? LastLogin;
|
|
public void SetData(PlayerLeaderboardEntry data)
|
|
{
|
|
playFabId = data.PlayFabId;
|
|
position = data.Position;
|
|
rank = data.Position + 1;
|
|
value = data.StatValue;
|
|
displayName = data.Profile.DisplayName;
|
|
avatarUrl = data.Profile.AvatarUrl;
|
|
LastLogin = data.Profile.LastLogin;
|
|
}
|
|
}
|