优化
This commit is contained in:
@@ -11,8 +11,8 @@ namespace Script
|
||||
{
|
||||
public class ContactEntryController : MonoBehaviour, IController
|
||||
{
|
||||
private Transform _background;
|
||||
private Transform _backgroundName;
|
||||
private Image _background;
|
||||
private Text _backgroundName;
|
||||
private GameObject _confirmBtnTime;
|
||||
private Text _confirmBtnTimeText;
|
||||
private Button _confirmButton;
|
||||
@@ -37,36 +37,24 @@ namespace Script
|
||||
{
|
||||
_usersItem = item;
|
||||
_meetingContacts = meetingContactsController;
|
||||
|
||||
_background = transform.Find("headBackground/image").GetComponent<Image>();
|
||||
_backgroundName = transform.Find("headBackground/Name").GetComponent<Text>();
|
||||
///头像赋值
|
||||
if (string.IsNullOrEmpty(item.avatar))
|
||||
{
|
||||
var randomColor = WebRTCUtil.GetRandomColor();
|
||||
_background = transform.Find("headBackground");
|
||||
if (_background != null)
|
||||
{
|
||||
var image = _background.GetComponent<Image>();
|
||||
if (image != null) image.color = randomColor;
|
||||
}
|
||||
|
||||
_backgroundName = _background.transform.Find("Name");
|
||||
if (_background != null) _background.color = randomColor;
|
||||
if (_backgroundName != null)
|
||||
{
|
||||
var textComponent = _backgroundName.GetComponent<Text>();
|
||||
if (textComponent != null && !string.IsNullOrEmpty(item.name))
|
||||
textComponent.text = item.name.Substring(0, 1);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(item.name))
|
||||
_backgroundName.text = item.name.Substring(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_background = transform.Find("headBackground");
|
||||
if (_background != null)
|
||||
{
|
||||
var imageComponent = _background.GetComponent<Image>();
|
||||
if (imageComponent != null) WebRTCUtil.DownloadAndSetAvatar(item.avatar, imageComponent);
|
||||
}
|
||||
|
||||
_backgroundName = _background.transform.Find("Name");
|
||||
if (_backgroundName != null) _backgroundName.GetComponent<Text>().text = "";
|
||||
if (_background != null)
|
||||
WebRTCUtil.DownloadAndSetAvatar(item.avatar, _background);
|
||||
if (_backgroundName != null) _backgroundName.text = "";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(item.name))
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Script.Util;
|
||||
using Stary.Evo;
|
||||
using Stary.Evo.UIFarme;
|
||||
using Unity.RenderStreaming;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -61,6 +62,7 @@ namespace Script
|
||||
public override string UIPath => "Canvas";
|
||||
|
||||
public Action<List<UsersItem>> OnUsersChangedEvnent;
|
||||
private Dictionary<UsersItem, GameObject> _userMap = new();
|
||||
|
||||
private GameObjectPool _objectPool;
|
||||
|
||||
@@ -90,8 +92,6 @@ namespace Script
|
||||
{
|
||||
base.OnEnter(complete);
|
||||
_meetingInfoList.OnEnter();
|
||||
;
|
||||
|
||||
_titleText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionName();
|
||||
this.GetSystem<IGlobalConfigSystem>().StartConnectionTime(_timeText);
|
||||
_idText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionId();
|
||||
@@ -100,15 +100,14 @@ namespace Script
|
||||
_contactsTog.onValueChanged.AddListener(OnContactsTog);
|
||||
_meetingOrganizersTog.onValueChanged.AddListener(OnMeetingOrganizersTog);
|
||||
OnUsersChangedEvnent += OnUsersChanged;
|
||||
GameObject.FindObjectOfType<HostConnection>().OnParticipantDisconnected += OnUsersChangedDisconnected;
|
||||
}
|
||||
|
||||
|
||||
public override void OnExit(float delay = 0)
|
||||
{
|
||||
base.OnExit(delay);
|
||||
_meetingContacts.OnExit();
|
||||
_meetingInfoList.OnExit();
|
||||
_meetingChat.OnExit();
|
||||
_arrowLeft.onClick.RemoveListener(OnArrowLeftClick);
|
||||
_chatTog.onValueChanged.RemoveListener(OnChatTog);
|
||||
_contactsTog.onValueChanged.RemoveListener(OnContactsTog);
|
||||
@@ -118,20 +117,44 @@ namespace Script
|
||||
|
||||
private async void OnUsersChanged(List<UsersItem> obj)
|
||||
{
|
||||
for (var i = 0; i < _objectPool.transform.childCount; i++)
|
||||
_objectPool.Release(_objectPool.transform.GetChild(i).gameObject);
|
||||
foreach (var user in _userMap) _objectPool.Release(user.Value.gameObject);
|
||||
|
||||
_userMap.Clear();
|
||||
_roomPeopleNumText.text = obj.Count.ToString();
|
||||
for (var i = 0; i < obj.Count; i++)
|
||||
{
|
||||
if (i > 4) break;
|
||||
var entry = _objectPool.Get();
|
||||
await WebRTCUtil.DownloadAndSetAvatar(obj[i].avatar,
|
||||
entry.transform.Find("image").GetComponent<Image>());
|
||||
_userMap.TryAdd(obj[i], entry);
|
||||
}
|
||||
|
||||
// 更新会议聊天面板人数
|
||||
_meetingChat.OnUserCountChangedEvent?.Invoke(obj.Count);
|
||||
}
|
||||
|
||||
private void OnUsersChangedDisconnected(string obj)
|
||||
{
|
||||
UsersItem usersItem = null;
|
||||
foreach (var item in _userMap.Keys)
|
||||
if (item.participantId == obj)
|
||||
{
|
||||
usersItem = item;
|
||||
break;
|
||||
}
|
||||
|
||||
if (usersItem != null)
|
||||
if (_userMap.TryGetValue(usersItem, out var entry))
|
||||
{
|
||||
_objectPool.Release(entry);
|
||||
_userMap.Remove(usersItem);
|
||||
}
|
||||
|
||||
_roomPeopleNumText.text = _userMap.Count.ToString();
|
||||
_meetingChat.OnUserCountChangedEvent?.Invoke(_userMap.Count);
|
||||
}
|
||||
|
||||
private void OnMeetingOrganizersTog(bool value)
|
||||
{
|
||||
_meetingInfoList.PanelGo.SetActive(value);
|
||||
@@ -140,13 +163,15 @@ namespace Script
|
||||
private void OnContactsTog(bool value)
|
||||
{
|
||||
_meetingContacts.PanelGo.SetActive(value);
|
||||
if (value) _meetingContacts.OnEnter();
|
||||
if (value)
|
||||
_meetingContacts.OnEnter();
|
||||
}
|
||||
|
||||
private void OnChatTog(bool value)
|
||||
{
|
||||
_meetingChat.PanelGo.SetActive(value);
|
||||
if (value) _meetingChat.OnEnter();
|
||||
if (value)
|
||||
_meetingChat.OnEnter();
|
||||
}
|
||||
|
||||
private void OnArrowLeftClick()
|
||||
@@ -156,6 +181,8 @@ namespace Script
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
_meetingChat.OnDestroy();
|
||||
_meetingContacts.OnDestroy();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Script
|
||||
_confirmButton = _confirmingPop.transform.Find("bg/invite").GetComponent<Button>();
|
||||
_cancelButton = _confirmingPop.transform.Find("bg/cancel").GetComponent<Button>();
|
||||
|
||||
_avatarImage = _confirmingPop.transform.Find("ParticipantEntry/head").GetComponent<Image>();
|
||||
_avatarImage = _confirmingPop.transform.Find("ParticipantEntry/head/image").GetComponent<Image>();
|
||||
_nameText = _confirmingPop.transform.Find("ParticipantEntry/Name").GetComponent<Text>();
|
||||
_messageText = _confirmingPop.transform.Find("ParticipantEntry/Message").GetComponent<Text>();
|
||||
|
||||
@@ -94,8 +94,9 @@ namespace Script
|
||||
}
|
||||
|
||||
|
||||
public void OnExit()
|
||||
public void OnDestroy()
|
||||
{
|
||||
_objectPool.AllRelease();
|
||||
}
|
||||
|
||||
public void ClickContactEntry(Sprite avatarImage, string name, MainPanel.UsersItem item)
|
||||
@@ -106,7 +107,7 @@ namespace Script
|
||||
_idText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionId();
|
||||
|
||||
_avatarImage.sprite = avatarImage;
|
||||
var avatarName = _avatarImage.transform.Find("Name").GetComponent<Text>();
|
||||
var avatarName = _confirmingPop.transform.Find("ParticipantEntry/head/Name").GetComponent<Text>();
|
||||
avatarName.text = name;
|
||||
_nameText.text = item.name;
|
||||
_messageText.text = item.userId;
|
||||
|
||||
@@ -123,8 +123,8 @@ namespace Script
|
||||
{
|
||||
var transform = entry.transform;
|
||||
///头像赋值
|
||||
var background = transform.Find("headBackground");
|
||||
var backgroundName = background.transform.Find("Name");
|
||||
var background = transform.Find("headBackground/image");
|
||||
var backgroundName = transform.Find("headBackground/Name");
|
||||
if (string.IsNullOrEmpty(item.avatar))
|
||||
{
|
||||
var randomColor = WebRTCUtil.GetRandomColor();
|
||||
@@ -145,7 +145,6 @@ namespace Script
|
||||
}
|
||||
else
|
||||
{
|
||||
background = transform.Find("headBackground");
|
||||
if (background != null)
|
||||
{
|
||||
var imageComponent = background.GetComponent<Image>();
|
||||
@@ -228,6 +227,11 @@ namespace Script
|
||||
GameObject.FindObjectOfType<HostConnection>().OnParticipantDisconnected -= OnParticipantDisconnected;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
_objectPool.AllRelease();
|
||||
}
|
||||
|
||||
public class MessageRecordInfo
|
||||
{
|
||||
public MainPanel.UsersItem item;
|
||||
|
||||
Reference in New Issue
Block a user