58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description: 聊天管理
|
|
* @Date: 2026年01月19日 星期一 11:01:05
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System.Collections.Generic;
|
|
using MemoryPack;
|
|
using TH1_Logic.Net;
|
|
using TH1_Logic.Steam;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace TH1_Logic.Chat
|
|
{
|
|
public class ChatManager
|
|
{
|
|
public static ChatManager Instance = new ChatManager();
|
|
public List<ChatItem> ChatItems = new List<ChatItem>();
|
|
private Dictionary<int, ChatItem> _chatItems = new Dictionary<int, ChatItem>();
|
|
|
|
|
|
public void SendChatItem(string message)
|
|
{
|
|
var item = new ChatItem();
|
|
item.Hash = System.Guid.NewGuid().GetHashCode();
|
|
item.SenderId = LobbyManager.Instance.Lobby.GetSelfMemberId();
|
|
item.Message = message;
|
|
item.Time = Time.time;
|
|
|
|
ChatItems.Add(item);
|
|
_chatItems[item.Hash] = item;
|
|
|
|
if (LobbyManager.Instance.Lobby.IsLobbyOwner()) GameNetSender.Instance.BroadcastChatMessage(item);
|
|
else GameNetSender.Instance.SendChatMessage(item);
|
|
}
|
|
|
|
public void ReceiveChatItem(ChatItem newItem)
|
|
{
|
|
if (newItem == null || _chatItems.ContainsKey(newItem.Hash)) return;
|
|
newItem.Time = Time.time;
|
|
ChatItems.Add(newItem);
|
|
if (LobbyManager.Instance.Lobby.IsLobbyOwner()) GameNetSender.Instance.BroadcastChatMessage(newItem);
|
|
}
|
|
}
|
|
|
|
|
|
[MemoryPackable]
|
|
public partial class ChatItem
|
|
{
|
|
public int Hash;
|
|
public float Time;
|
|
public ulong SenderId;
|
|
public string Message;
|
|
}
|
|
} |