聊天接入

This commit is contained in:
2026-05-24 17:52:30 +08:00
parent 81834ebe09
commit 9b6ed2bcd6
3 changed files with 38 additions and 16 deletions

View File

@@ -159,10 +159,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 5953434083280990437}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 282.7511, y: 116.16}
m_SizeDelta: {x: 210.7176, y: 48.88}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -302.2489, y: -29.839996}
m_SizeDelta: {x: 210.71759, y: 48.880005}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4435424541891262489
CanvasRenderer:
@@ -367,7 +367,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1.2
m_Text: "\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F\u65B0\u529F\u80FD\u65B0\u529F"
m_Text: "\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473\u59D4\u5C48\u6076\u8DA3\u5473\u997F\u6211\u53BB\u6076\u8DA3\u5473"
--- !u!114 &6210788150876076281
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -508,9 +508,9 @@ RectTransform:
- {fileID: 1230631994026680119}
m_Father: {fileID: 5953434083280990437}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 478, y: 75.6}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -107, y: -70.40001}
m_SizeDelta: {x: 130, y: 130}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2318122004626110612
@@ -718,7 +718,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1.2
m_Text: "\u65B0\u529F\u80FD\u65B0\u529F"
m_Text:
--- !u!114 &4205897810838458374
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -765,9 +765,9 @@ RectTransform:
m_Children: []
m_Father: {fileID: 5953434083280990437}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 835, y: -189}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -335, y: -189}
m_SizeDelta: {x: 250, y: 250}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &800814340190462883

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using RenderStreaming;
using Script.Util;
using Stary.Evo;
@@ -73,18 +74,39 @@ namespace Script
$"{this.GetSystem<IGlobalConfigSystem>().GetConnectionTexture()}.png",
type = "text",
content = _messageInput.text,
isSelf = "true",
isSelf = false,
timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
GameObject.FindObjectOfType<MessageChannel>().SendMessage<ChatData>(_messageInput.text, chatData);
var message = new
{
type = "chat-message",
data = chatData
};
var data = new
{
message = message,
connectionId = this.GetSystem<IGlobalConfigSystem>().GetConnectionId()
};
var send = new
{
form = this.GetSystem<IGlobalConfigSystem>().GetConnectionId(),
to = "",
type = "on-message",
data = data
};
SignalingMessageHelper.SendMessage(JsonConvert.SerializeObject(send));
_messageInput.text = "";
chatData.isSelf = !chatData.isSelf;
_chatDatas.Add(chatData);
var entry = _objectRightPool.Get();
SetMessageEntry(chatData, entry);
}
private void OnChatMessageReceivedEvent(string connectionId, ChatData data)
{
if (connectionId != this.GetSystem<IGlobalConfigSystem>().GetConnectionId()) return;
_chatDatas.Add(data);
if (bool.Parse(data.isSelf) == false)
if (data.isSelf == false)
{
var entry = _objectLeftPool.Get();
SetMessageEntry(data, entry);

View File

@@ -25,7 +25,7 @@ namespace Unity.RenderStreaming
public string content;
public string type;
public string timestamp;
public string isSelf;
public bool isSelf;
}
[Serializable]