using System.Collections; using System.Collections.Generic; using UnityEngine; using static Unity.IO.LowLevel.Unsafe.AsyncReadManagerMetrics; using UnityEngine.Playables; public class FriendPanel : MonoBehaviour { public GameObject friendinfoPrefab; public Transform friendList; public GameObject invitefriendsPanel; public getInviteList62 getInviteList62=new getInviteList62(); public InviteInfoList inviteInfoList=new InviteInfoList(); public List friendInfos = new List();//好友信息列表 // Start is called before the first frame update async void Start() { inviteInfoList= await getInviteList62.queryInviteHigherInfo(); CreateItem(); //for(int i=0;i<6;i++) //{ // GameObject slot = GameObject.Instantiate(friendinfoPrefab, friendList); //} } // Update is called once per frame void Update() { } public void CreateItem() { foreach (InviteUserInfo item in inviteInfoList.data.dataList) { GameObject newItem = Instantiate(friendinfoPrefab, friendList); FriendInfo ItemComponent = newItem.GetComponent(); // 设置实例化对象的内容 ItemComponent.nameTxt.text=item.nickName; ItemComponent.phonrNumberTxt.text=item.userName; ItemComponent.UserId=item.userId; ItemComponent.timeTxt.text =item.bindTime; // 判断是否已存在 bool exists = false; foreach (FriendInfo info in friendInfos) { if (info.UserId == item.userId) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { friendInfos.Add(newItem.GetComponent()); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newItem); } } } public void SetFriendPanel() { transform.gameObject.SetActive(false); invitefriendsPanel.SetActive(true); } }