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

56 lines
1.4 KiB
C#

using asap.core;
using game;
using System;
using TMPro;
using UniRx;
using UnityEngine;
public class ReportBase : MonoBehaviour
{
TMP_Text text_name;
Head head;
IUserService userService;
IDisposable disposable;
string playFabId;
protected virtual void Awake()
{
userService = GContext.container.Resolve<IUserService>();
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
text_name = transform.Find("info/text_name")?.GetComponent<TMP_Text>();
head = transform.Find("btn_head").GetComponent<Head>();
}
public void Init(string playFabId)
{
this.playFabId = playFabId;
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
SetAvatar(clubPlayInfo);
}
void SetAvatar(PlayInfo clubPlayInfo)
{
if (clubPlayInfo != null)
{
if (text_name != null)
{
text_name.text = clubPlayInfo.name;
}
head.SetData(clubPlayInfo.avatarUrl);
}
}
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
{
if (getClubPlayInfoEvent.id == playFabId)
{
text_name.text = getClubPlayInfoEvent.name;
head.SetData(getClubPlayInfoEvent.avatarUrl);
}
}
private void OnDestroy()
{
disposable?.Dispose();
disposable = null;
}
}