优化
This commit is contained in:
@@ -26,31 +26,58 @@ namespace Script
|
||||
|
||||
private List<ChatData> _chatDatas = new();
|
||||
|
||||
private InputField _messageInput;
|
||||
private Button _sendButton;
|
||||
|
||||
public void Initialize(GameObject panelGo, MainPanel mainPanel)
|
||||
{
|
||||
PanelGo = panelGo;
|
||||
_mainPanel = mainPanel;
|
||||
_content = panelGo.transform.Find("MeetingGrid/Viewport/Content");
|
||||
_objectRightPool = panelGo.transform.Find("MeetingGrid/LeftPool").GetComponent<GameObjectPool>();
|
||||
_objectLeftPool = panelGo.transform.Find("MeetingGrid/RightPool").GetComponent<GameObjectPool>();
|
||||
|
||||
_objectLeftPool = panelGo.transform.Find("MeetingGrid/LeftPool").GetComponent<GameObjectPool>();
|
||||
_objectRightPool = panelGo.transform.Find("MeetingGrid/RightPool").GetComponent<GameObjectPool>();
|
||||
_connectionTimeText = panelGo.transform.Find("MeetingNum/Time").GetComponent<Text>();
|
||||
_connectionTimeText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionStartTime();
|
||||
|
||||
_userCountText = panelGo.transform.Find("MeetingNum/Num").GetComponent<Text>();
|
||||
_userCountText.text = this.GetSystem<IGlobalConfigSystem>().GetUserCount().ToString();
|
||||
}
|
||||
|
||||
public async void OnEnter()
|
||||
{
|
||||
_messageInput = panelGo.transform.Find("MettingSend/InputField").GetComponent<InputField>();
|
||||
_sendButton = panelGo.transform.Find("MettingSend/SendBtn").GetComponent<Button>();
|
||||
_sendButton.onClick.AddListener(OnSendButtonClick);
|
||||
OnUserCountChangedEvent += OnUserCountChanged;
|
||||
GameObject.FindObjectOfType<MessageChannel>().OnChatMessageReceived += OnChatMessageReceivedEvent;
|
||||
}
|
||||
|
||||
public async void OnExit()
|
||||
|
||||
public async void OnEnter()
|
||||
{
|
||||
_connectionTimeText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionStartTime();
|
||||
_userCountText.text = this.GetSystem<IGlobalConfigSystem>().GetUserCount().ToString();
|
||||
}
|
||||
|
||||
public async void OnDestroy()
|
||||
{
|
||||
OnUserCountChangedEvent -= OnUserCountChanged;
|
||||
GameObject.FindObjectOfType<MessageChannel>().OnChatMessageReceived -= OnChatMessageReceivedEvent;
|
||||
_objectRightPool.AllRelease();
|
||||
_objectLeftPool.AllRelease();
|
||||
}
|
||||
|
||||
private void OnSendButtonClick()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_messageInput.text)) return;
|
||||
var chatData = new ChatData
|
||||
{
|
||||
id = "msg_" + Guid.NewGuid().ToString(),
|
||||
senderId = this.GetSystem<IGlobalConfigSystem>().GetUserId(),
|
||||
senderName = this.GetSystem<IGlobalConfigSystem>().GetConnectionName(),
|
||||
senderAvatar = $"{this.GetSystem<IGlobalConfigSystem>().IP}/images/head/" +
|
||||
$"{this.GetSystem<IGlobalConfigSystem>().GetConnectionTexture()}.png",
|
||||
type = "text",
|
||||
content = _messageInput.text,
|
||||
isSelf = "true",
|
||||
timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
GameObject.FindObjectOfType<MessageChannel>().SendMessage<ChatData>(_messageInput.text, chatData);
|
||||
_messageInput.text = "";
|
||||
}
|
||||
|
||||
private void OnChatMessageReceivedEvent(string connectionId, ChatData data)
|
||||
@@ -66,7 +93,7 @@ namespace Script
|
||||
|
||||
private void SetMessageEntry(ChatData data, GameObject entry)
|
||||
{
|
||||
var head = entry.transform.Find("head");
|
||||
var head = entry.transform.Find("head/image");
|
||||
var name = entry.transform.Find("name");
|
||||
var message = entry.transform.Find("message");
|
||||
var sprite = entry.transform.Find("sprite");
|
||||
@@ -89,11 +116,15 @@ namespace Script
|
||||
message.GetComponent<Text>().text = data.content;
|
||||
sprite.gameObject.SetActive(false);
|
||||
}
|
||||
else if (data.type == "image")
|
||||
else if (data.type == "file")
|
||||
{
|
||||
message.gameObject.SetActive(false);
|
||||
sprite.gameObject.SetActive(true);
|
||||
//TODO 图片传输功能
|
||||
if (WebRTCUtil.TryDecodeDataUrlToTexture(data.content, out var texture))
|
||||
sprite.GetComponent<Image>().sprite = Sprite.Create(texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
Vector2.one);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user