using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public class FriendView : MonoBehaviour { [SerializeField] GameObject myFriendBox; [SerializeField] GameObject friendRequestBox; [SerializeField] GameObject searchPlayerBox; void Awake() { InitBtnTabs(); InitMyFriendBox(); InitFriendRequestBox(); InitSearchPlayerBox(); } void Start() { SetBtnTabSelected(btnTabs[0]); } #region myFriend void InitMyFriendBox() { myFriendBox.SetActive(false); GetMyFriendItemPrefab().SetActive(false); } Transform GetMyFriendItemParent() { return myFriendBox.transform.Find("ScrollView/Viewport/Content"); } GameObject GetMyFriendItemPrefab() { return GetMyFriendItemParent().Find("Item").gameObject; } void EnterMyFriendBox() { myFriendBox.SetActive(true); Action cb = delegate(JArray list) { if (list.Count > 0) { foreach (var itemInfo in list) { int friendID = itemInfo.Value("friendID"); int avatarID = itemInfo.Value("avatarID"); string nickname = itemInfo.Value("nickname"); bool online = itemInfo.Value("online"); for (int i = 1; i < GetMyFriendItemParent().childCount; i++) { Destroy(GetMyFriendItemParent().GetChild(i).gameObject); } GameObject o = GameObject.Instantiate(GetMyFriendItemPrefab(), GetMyFriendItemParent()); o.SetActive(true); o.name = friendID.ToString(); o.transform.Find("Avatar/Sprite").GetComponent().sprite = RoleMgr.GetAvatar(avatarID); o.transform.Find("Name").GetComponent().text = nickname; o.transform.Find("Point").GetComponent().color = online ? Color.green : Color.red; Button btnDelete = o.transform.Find("BtnDelete").GetComponent