using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UserItem : MonoBehaviour { public RawImage mainImage; public Toggle toggle; public Text nameText; public Text account; public Text showState; public Text showState1; public Button imgBtn; private InviteUserConfig inviteUserConfig; private void Start() { toggle.onValueChanged.AddListener(OnValueChange); imgBtn.onClick.AddListener(ClickOnImg); } private void ClickOnImg() { if (this.inviteUserConfig.Online == "1") { toggle.isOn = !toggle.isOn; } } private void OnValueChange(bool isOn) { if (InviteDlg.Instance && inviteUserConfig != null) { if (isOn) { InviteDlg.Instance.InviteUnionIdList.Add(inviteUserConfig); if (InviteDlg.Instance.InviteUnionIdList.Count > 0) { InviteDlg.Instance.RecoverInviteBtn(); } } else { if (InviteDlg.Instance.InviteUnionIdList.Contains(inviteUserConfig)) { InviteDlg.Instance.InviteUnionIdList.Remove(inviteUserConfig); } if (InviteDlg.Instance.InviteUnionIdList.Count <= 0) { InviteDlg.Instance.InitInviteBtn(); } } } } private void OnDestroy() { } public void Init(InviteUserConfig inviteUserConfig) { if (inviteUserConfig != null) { this.inviteUserConfig = inviteUserConfig; nameText.text = inviteUserConfig.NickName; account.text = inviteUserConfig.Phone; switch (inviteUserConfig.Online) { case "0"://离线 toggle.gameObject.SetActive(false); showState.gameObject.SetActive(false); showState1.gameObject.SetActive(true); break; case "1"://在线 toggle.gameObject.SetActive(true); showState.gameObject.SetActive(false); showState1.gameObject.SetActive(false); break; case "2"://忙碌 toggle.gameObject.SetActive(false); showState.gameObject.SetActive(true); showState1.gameObject.SetActive(false); break; } if (!string.IsNullOrEmpty(inviteUserConfig.Avatar)) { NetWorkHeaders.Instance.getNetTexture(inviteUserConfig.Avatar, null, (Texture tex) => { if (tex) { mainImage.texture = tex; } }); } else { mainImage.texture = UserInfo.defaulttextIcon; } } } }