77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class DialogItem : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI tMP_content;
|
|
public GameObject waitMessage;
|
|
public GameObject messageDefeated;
|
|
public Image title;
|
|
public Image avatar;
|
|
public Image avatarFrame;
|
|
public bool showAvatar = true;
|
|
|
|
private void OnEnable()
|
|
{
|
|
GameManager.Instance.OnAvatarChanged += OnAvatarChanged;
|
|
GameManager.Instance.OnAvatarFrameChanged += OnAvatarFrameChanged;
|
|
|
|
if (showAvatar)
|
|
{
|
|
RefreshAvatar();
|
|
RefreshAvatarFrame();
|
|
}
|
|
//else
|
|
//{
|
|
// if (avatar != null) avatar.gameObject.SetActive(false);
|
|
// if (avatarFrame != null) avatarFrame.gameObject.SetActive(false);
|
|
//}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Instance.OnAvatarChanged -= OnAvatarChanged;
|
|
GameManager.Instance.OnAvatarFrameChanged -= OnAvatarFrameChanged;
|
|
}
|
|
}
|
|
|
|
private void RefreshAvatar()
|
|
{
|
|
if (avatar == null) return;
|
|
var sprite = GameManager.Instance.GetAvatarSprite(GameManager.Instance.user.BaseInfo.avatarUrl);
|
|
if (sprite != null) avatar.sprite = sprite;
|
|
avatar.gameObject.SetActive(true);
|
|
}
|
|
|
|
private void RefreshAvatarFrame()
|
|
{
|
|
if (avatarFrame == null) return;
|
|
var sprite = GameManager.Instance.GetAvatarFrameSprite(GameManager.Instance.user.BaseInfo.avatarFrame);
|
|
if (sprite != null) avatarFrame.sprite = sprite;
|
|
avatarFrame.gameObject.SetActive(sprite != null);
|
|
}
|
|
|
|
private void OnAvatarChanged(Sprite sprite)
|
|
{
|
|
if (!showAvatar || avatar == null || sprite == null) return;
|
|
avatar.sprite = sprite;
|
|
}
|
|
|
|
private void OnAvatarFrameChanged(Sprite sprite)
|
|
{
|
|
if (!showAvatar || avatarFrame == null || sprite == null) return;
|
|
avatarFrame.sprite = sprite;
|
|
}
|
|
|
|
public void SetMessage(string str)
|
|
{
|
|
if (tMP_content != null)
|
|
tMP_content.text = str;
|
|
}
|
|
}
|