using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PrivateChatToggle : BaseToggle { public SupOrSub Type; public GameObject UnReadObj; public Text UnReadText; private List users = null; private void Start() { MessageDispatcher.AddListener("REFRESH_UNREAD_MSG", GetUnReadMsg); UnReadObj.SetActive(false); } public override void OnDestroy() { MessageDispatcher.RemoveListener("REFRESH_UNREAD_MSG", GetUnReadMsg); } private void GetUnReadMsg(IMessage msg) { // 查找所有下级或上级频道 switch (Type) { case SupOrSub.Sup: users = ChatManager.Instance.FindAllSupUser(); break; case SupOrSub.Sub: users = ChatManager.Instance.FindAllSubUser(); break; } int count = 0; foreach (var item in users) { count += ChatManager.Instance.GetUnReadMsgsCount(item.ChannelId); } SetCount(count); } public void SetCount(int num) { if (num > 0) { UnReadText.text = num.ToString(); UnReadObj.SetActive(true); } else { UnReadObj.SetActive(false); } } public override void RespondFun(bool value) { if (value) { switch (Type) { case SupOrSub.Sup: users = ChatManager.Instance.FindAllSupUser(); break; case SupOrSub.Sub: users = ChatManager.Instance.FindAllSubUser(); break; } //UIView-OnShow UIManager.GetView(Type.ToString()) .OnShow = (v) => (v as PrivateChatPanel).UsersInfo = users; //UIView-OnHide UIManager.GetView(Type.ToString()) .OnHide = (v) => GetComponent().isOn = false; //显示页面 UIManager.ShowView(Type.ToString()); } else { //隐藏页面 UIManager.HideView(Type.ToString()); } } } public enum SupOrSub { Sup, Sub }