Files
2026-05-26 16:15:54 +08:00

129 lines
3.7 KiB
C#

using asap.core;
using game;
using GameCore;
using System;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class DialogueBase : MonoBehaviour
{
protected IUserService userService;
public Head head;
public GameObject player_info;
public TMP_Text text_name;
public TMP_Text text_time;
public Button btn_head;
public Transform tips_dock_trans;
public Vector2 tips_dock_offset = Vector2.zero;
protected string playFabId = null;
protected string displayName = null;
protected string avatarUrl = null;
IDisposable disposable;
#if UNITY_EDITOR
private void Reset()
{
text_name = transform.Find("player_info/text_name")?.GetComponent<TMP_Text>();
text_time = transform.Find("player_info/text_time").GetComponent<TMP_Text>();
head = transform.Find("btn_head").GetComponent<Head>();
player_info = transform.Find("player_info").gameObject;
}
#endif
protected virtual void Awake()
{
userService = GContext.container.Resolve<IUserService>();
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
}
protected void Init(DateTime timeSpan, bool isSame)
{
if (isSame)
{
head.gameObject.SetActive(false);
player_info.gameObject.SetActive(false);
disposable?.Dispose();
disposable = null;
return;
}
text_time.text = timeSpan.ToString();
if (playFabId == userService.UserId)
{
if (text_name != null)
text_name.text = userService.DisplayName;
head.SetData(userService.AvatarUrl);
displayName = userService.DisplayName;
avatarUrl = userService.AvatarUrl;
}
else
{
if (playFabId == null)
{
playFabId = "";
}
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
if (clubPlayInfo != null)
{
if (text_name != null)
text_name.text = clubPlayInfo.name;
head.SetData(clubPlayInfo.avatarUrl);
displayName = clubPlayInfo.name;
avatarUrl = clubPlayInfo.avatarUrl;
}
}
if (btn_head != null)
{
btn_head.onClick.RemoveAllListeners();
btn_head.onClick.AddListener(OnBtnHeadClickListener);
}
}
private async void OnBtnHeadClickListener()
{
if (tips_dock_trans == null) return;
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
if (clubPlayInfo == null) return;
GameObject go = await UIManager.Instance.ShowUI(UITypes.SocialClubPlayerTips);
if (go == null) return;
BFriendInfo friendInfo = new BFriendInfo()
{
PlayFabId = playFabId,
DisplayName = displayName,
AvatarUrl = avatarUrl,
Level = -1
};
SocialClubPlayerTips tips = go.GetComponent<SocialClubPlayerTips>();
tips.SetData(tips_dock_trans, tips_dock_offset, friendInfo);
}
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
{
if (getClubPlayInfoEvent.id == playFabId)
{
if (text_name != null)
text_name.text = getClubPlayInfoEvent.name;
head.SetData(getClubPlayInfoEvent.avatarUrl);
displayName = getClubPlayInfoEvent.name;
avatarUrl = getClubPlayInfoEvent.avatarUrl;
}
}
private void OnDestroy()
{
disposable?.Dispose();
disposable = null;
playFabId = null;
displayName = null;
avatarUrl = null;
}
}