Files
test/Assets/PerfectWorld/Scripts/Chat/UI/ServerErrorChatHandler.cs
2026-04-01 10:41:22 +07:00

44 lines
1.1 KiB
C#

#if UNITY_EDITOR
using UnityEngine;
using CSNetwork;
namespace BrewMonster.Scripts.ChatUI
{
public class ServerErrorChatHandler : MonoBehaviour
{
public ServerErrorSO errorDatabase;
private void Awake()
{
EventBus.Subscribe<GameSession.ServerErrorEvent>(OnServerError);
}
private void OnDestroy()
{
EventBus.Unsubscribe<GameSession.ServerErrorEvent>(OnServerError);
}
private void OnServerError(GameSession.ServerErrorEvent e)
{
string errorMsg = null;
if (errorDatabase != null)
{
errorMsg = errorDatabase.GetErrorString(e.ErrorCode);
}
if (string.IsNullOrEmpty(errorMsg))
{
errorMsg = $"Lỗi không xác định";
}
string coloredMsg = $"<color=red>{errorMsg}</color>";
EventBus.Publish(new GameSession.ChatMessageEvent(
coloredMsg,
(byte)CSNetwork.GPDataType.ChatChannel.GP_CHAT_SYSTEM
));
}
}
}
#endif