UserItem.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class UserItem : MonoBehaviour
  7. {
  8. public RawImage mainImage;
  9. public Toggle toggle;
  10. public Text nameText;
  11. public Text account;
  12. public Text showState;
  13. public Text showState1;
  14. public Button imgBtn;
  15. private InviteUserConfig inviteUserConfig;
  16. private void Start()
  17. {
  18. toggle.onValueChanged.AddListener(OnValueChange);
  19. imgBtn.onClick.AddListener(ClickOnImg);
  20. }
  21. private void ClickOnImg()
  22. {
  23. if (this.inviteUserConfig.Online == "1")
  24. {
  25. toggle.isOn = !toggle.isOn;
  26. }
  27. }
  28. private void OnValueChange(bool isOn)
  29. {
  30. if (InviteDlg.Instance && inviteUserConfig != null)
  31. {
  32. if (isOn)
  33. {
  34. InviteDlg.Instance.InviteUnionIdList.Add(inviteUserConfig);
  35. if (InviteDlg.Instance.InviteUnionIdList.Count > 0)
  36. {
  37. InviteDlg.Instance.RecoverInviteBtn();
  38. }
  39. }
  40. else
  41. {
  42. if (InviteDlg.Instance.InviteUnionIdList.Contains(inviteUserConfig))
  43. {
  44. InviteDlg.Instance.InviteUnionIdList.Remove(inviteUserConfig);
  45. }
  46. if (InviteDlg.Instance.InviteUnionIdList.Count <= 0)
  47. {
  48. InviteDlg.Instance.InitInviteBtn();
  49. }
  50. }
  51. }
  52. }
  53. private void OnDestroy()
  54. {
  55. }
  56. public void Init(InviteUserConfig inviteUserConfig)
  57. {
  58. if (inviteUserConfig != null)
  59. {
  60. this.inviteUserConfig = inviteUserConfig;
  61. nameText.text = inviteUserConfig.NickName;
  62. account.text = inviteUserConfig.Phone;
  63. switch (inviteUserConfig.Online)
  64. {
  65. case "0"://离线
  66. toggle.gameObject.SetActive(false);
  67. showState.gameObject.SetActive(false);
  68. showState1.gameObject.SetActive(true);
  69. break;
  70. case "1"://在线
  71. toggle.gameObject.SetActive(true);
  72. showState.gameObject.SetActive(false);
  73. showState1.gameObject.SetActive(false);
  74. break;
  75. case "2"://忙碌
  76. toggle.gameObject.SetActive(false);
  77. showState.gameObject.SetActive(true);
  78. showState1.gameObject.SetActive(false);
  79. break;
  80. }
  81. if (!string.IsNullOrEmpty(inviteUserConfig.Avatar))
  82. {
  83. NetWorkHeaders.Instance.getNetTexture(inviteUserConfig.Avatar, null, (Texture tex) => {
  84. if (tex)
  85. {
  86. mainImage.texture = tex;
  87. }
  88. });
  89. }
  90. else
  91. {
  92. mainImage.texture = UserInfo.defaulttextIcon;
  93. }
  94. }
  95. }
  96. }