You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
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<UserInfoItemViewModel> 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<PrivateChatPanel>(Type.ToString()) |
|
.OnShow = (v) => |
|
(v as PrivateChatPanel).UsersInfo = users; |
|
|
|
//UIView-OnHide |
|
UIManager.GetView<PrivateChatPanel>(Type.ToString()) |
|
.OnHide = (v) => |
|
GetComponent<Toggle>().isOn = false; |
|
|
|
//显示页面 |
|
UIManager.ShowView<PrivateChatPanel>(Type.ToString()); |
|
} |
|
else |
|
{ |
|
//隐藏页面 |
|
UIManager.HideView<PrivateChatPanel>(Type.ToString()); |
|
} |
|
} |
|
} |
|
public enum SupOrSub |
|
{ |
|
Sup, |
|
Sub |
|
}
|
|
|