InviteUserItem.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using TMPro;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class InviteUserItem : MonoBehaviour
  5. {
  6. public TMP_Text mUserName_Text; // 用户名
  7. public TMP_Text mLevel_Text; // 级别
  8. public Image mState_Image; // 状态
  9. public TMP_Text mState_Text; // 状态
  10. public Image mHead_Image; // 头像
  11. public Toggle toggle;
  12. public RTCUserInfo mCurrentRTCUserInfo = null;
  13. private void Start()
  14. {
  15. toggle.onValueChanged.AddListener((state) =>
  16. {
  17. OnValueChange(state);
  18. });
  19. }
  20. public void InitData(Sprite headImage, RTCUserInfo userInfo)
  21. {
  22. if(userInfo==null) return;
  23. if (headImage != null) this.mHead_Image.sprite = headImage;
  24. mUserName_Text.text = userInfo.UserName;
  25. this.mLevel_Text.text = userInfo.Level;
  26. this.mCurrentRTCUserInfo = userInfo;
  27. switch (userInfo.State)
  28. {
  29. case "1":
  30. mState_Image.color = Color.green;
  31. mState_Text.text = "在线";
  32. toggle.interactable = true;
  33. break;
  34. case "2":
  35. mState_Image.color = Color.blue;
  36. mState_Text.text = "通话中";
  37. toggle.interactable = false;
  38. break;
  39. case "0":
  40. mState_Image.color = Color.red;
  41. mState_Text.text = "离线";
  42. toggle.interactable = false;
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. public void ResetData()
  49. {
  50. mUserName_Text.text = "韩风";
  51. this.mLevel_Text.text = "组长";
  52. mState_Image.color = Color.red;
  53. mState_Text.text = "离线";
  54. mCurrentRTCUserInfo = null;
  55. }
  56. private void OnValueChange(bool isOn)
  57. {
  58. if (mCurrentRTCUserInfo != null)
  59. {
  60. InviteUserPanel.Instance.SelectInviteUser(mCurrentRTCUserInfo, isOn);
  61. }
  62. }
  63. }