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
76 lines
2.5 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class GetUsersInFour : MonoBehaviour {
|
||
|
public List<CloneGameObjInfo> users = new List<CloneGameObjInfo>();
|
||
|
public GameObject itemPre;
|
||
|
void Awake()
|
||
|
{
|
||
|
if (itemPre == null)
|
||
|
{
|
||
|
itemPre = Resources.Load("4GTransfer/4GPersonItemFour") 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<TransferPersonItemFour>().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<TransferPersonItemFour>().SetPersonInfo(userInfo, userData);
|
||
|
}
|
||
|
}
|
||
|
for (int i = 0; i < transform.childCount; i++)
|
||
|
{
|
||
|
transform.GetChild(i).name = "4GPersonItemFour-" + 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<TransferPersonItemFour>().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;
|
||
|
}
|
||
|
}
|