网演高层钦州
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
2.5 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetUsersInOne : MonoBehaviour {
public GameObject itemPre;
public List<CloneGameObjInfo> users = new List<CloneGameObjInfo>();
void Awake()
{
if(itemPre == null)
{
itemPre = Resources.Load("4GTransfer/4GPersonItemOne") as GameObject;
}
MessageDispatcher.AddListener("UpdateTransferUserItems", CreateItems);
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("UpdateTransferUserItems", CreateItems);
}
void CreateItems(IMessage obj)
{
users = (List<CloneGameObjInfo>)obj.Data;
//删除没有同传的人员
for (int i = 0; i < transform.childCount; i++)
{
CloneGameObjInfo checkInfo = transform.GetChild(i).GetComponent<TransferPersonItemOne>().info;
if (/*!users.Contains(checkInfo)*/ usersContains(users, checkInfo) == false)
{
Destroy(transform.GetChild(i).gameObject);
}
}
foreach (CloneGameObjInfo userInfo in users)
{
if (!checkHasItem(userInfo))
{
GameObject item = Instantiate(itemPre, transform);
UserData userData = CurrentUserInfo.room.FindUserById(userInfo.UserID);
item.GetComponent<TransferPersonItemOne>().SetPersonInfo(userInfo, userData);
}
}
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).name = "4GPersonItemOne-" + i.ToString();
}
}
/// <summary>
/// 查找是否已经生成该人员的toggle
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
private bool checkHasItem(CloneGameObjInfo userInfo)
{
for (int i = 0; i < transform.childCount; i++)
{
CloneGameObjInfo checkInfo = transform.GetChild(i).GetComponent<TransferPersonItemOne>().info;
if (checkInfo.gameObjID == userInfo.gameObjID)
{
return true;
}
}
return false;
}
private bool usersContains(List<CloneGameObjInfo> list, CloneGameObjInfo checkInfo)
{
foreach (CloneGameObjInfo info in list)
{
if (info.gameObjID == checkInfo.gameObjID)
{
return true;
}
}
return false;
}
}