InviteUserPanel.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using Blue;
  3. using Newtonsoft.Json;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /// <summary>
  7. /// 舍弃InviteDlg
  8. /// </summary>
  9. public class InviteUserPanel : SingletonMonobehaviour<InviteUserPanel>
  10. {
  11. public Button mCall_Btn;
  12. public Button mClose_Btn;
  13. public Dictionary<int, RTCUserInfo> InviteUserDic = new Dictionary<int, RTCUserInfo>(); // 邀请用户的字典
  14. public List<InviteUserItem> InitDataList = new List<InviteUserItem>();
  15. void Start()
  16. {
  17. mClose_Btn.onClick.AddListener(ClickOnClose);
  18. mCall_Btn.onClick.AddListener(ClickOnInvite);
  19. }
  20. private void OnEnable()
  21. {
  22. for (int i = 0; i < InitDataList.Count; i++)
  23. {
  24. InitDataList[i].InitData(null, InitDataList[i].mCurrentRTCUserInfo);
  25. InitDataList[i].toggle.isOn = false;
  26. }
  27. }
  28. public void TestInitData()
  29. {
  30. for (int i = 0; i < InitDataList.Count; i++)
  31. {
  32. RTCUserInfo RTCUserInfo = new RTCUserInfo()
  33. {
  34. UserID = 600000 + i,
  35. UserName = "韩" + i.ToString(),
  36. Level = "组" + i.ToString(),
  37. };
  38. if (i % 3 == 0)
  39. RTCUserInfo.State = "0";
  40. else if (i % 3 == 1)
  41. RTCUserInfo.State = "1";
  42. else if (i % 3 == 2)
  43. RTCUserInfo.State = "2";
  44. InitDataList[i].InitData(null, RTCUserInfo);
  45. }
  46. }
  47. private string mInviteUserIDList;
  48. private void ClickOnInvite()
  49. {
  50. string json = JsonConvert.SerializeObject(InviteUserDic.Values);
  51. Debug.LogError($"ClickOnInvite:邀请指定用户,{json}");
  52. RTCRoomMain.Instance.mRoomOtherUser.SetActive(true);
  53. RTCRoomMain.Instance.mRoomOtherUser.GetComponent<RoomOtherUserPanel>().ExeCuteInvite(InviteUserDic);
  54. this.gameObject.SetActive(false);
  55. }
  56. private void ClickOnClose()
  57. {
  58. // TODO : 关闭邀请
  59. this.gameObject.SetActive(false);
  60. }
  61. public void SelectInviteUser(RTCUserInfo mCurrentRTCUserInfo, bool isOn)
  62. {
  63. if (isOn)
  64. {
  65. if (!InviteUserDic.ContainsKey(mCurrentRTCUserInfo.UserID))
  66. InviteUserDic.Add(mCurrentRTCUserInfo.UserID, mCurrentRTCUserInfo);
  67. }
  68. else
  69. {
  70. if (InviteUserDic.ContainsKey(mCurrentRTCUserInfo.UserID))
  71. InviteUserDic.Remove(mCurrentRTCUserInfo.UserID);
  72. }
  73. foreach (RTCUserInfo RTCUserInfo in InviteUserDic.Values)
  74. {
  75. Debug.LogError($"选择了{RTCUserInfo.UserName},ID为:{RTCUserInfo.UserID}");
  76. }
  77. }
  78. public void Reset()
  79. {
  80. InviteUserDic.Clear();
  81. foreach (InviteUserItem item in InitDataList) // 选择用户面板的勾
  82. {
  83. Toggle toggle = item.GetComponent<Toggle>();
  84. if (toggle.isOn) toggle.isOn = false;
  85. }
  86. }
  87. }