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.
77 lines
2.5 KiB
77 lines
2.5 KiB
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class GetUserIcons : MonoBehaviour { |
|
public GameObject itemPre; |
|
// Use this for initialization |
|
void Awake () { |
|
if (itemPre == null) |
|
{ |
|
itemPre = Resources.Load("4GTransfer/PersonIconItem") as GameObject; |
|
} |
|
MessageDispatcher.AddListener("UpdateTransferUserItems", CreateItems); |
|
} |
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("UpdateTransferUserItems", CreateItems); |
|
} |
|
private void CreateItems(IMessage obj) |
|
{ |
|
var users = (List<CloneGameObjInfo>)obj.Data; |
|
//删除没有同传的人员 |
|
for (int i = 0; i < transform.childCount; i++) |
|
{ |
|
CloneGameObjInfo checkInfo = transform.GetChild(i).GetComponent<PersonIconItemCtrl>().userInfo; |
|
if (!users.Contains(checkInfo)) //usersContains(users,checkInfo)==false) |
|
{ |
|
Destroy(transform.GetChild(i).gameObject); |
|
} |
|
} |
|
foreach (CloneGameObjInfo userInfo in users) |
|
{ |
|
if (!checkHasItem(userInfo)) //如果还没生成这个item |
|
{ |
|
GameObject item = Instantiate(itemPre, transform); |
|
UserData userData = CurrentUserInfo.room.FindUserById(userInfo.UserID); |
|
item.GetComponent<PersonIconItemCtrl>().SetIconInfo(userInfo, userData); |
|
} |
|
} |
|
for (int i = 0; i < transform.childCount; i++) |
|
{ |
|
transform.GetChild(i).name = "PersonItem-" + i.ToString(); |
|
} |
|
} |
|
|
|
private bool usersContains(List<CloneGameObjInfo> list,CloneGameObjInfo checkInfo) |
|
{ |
|
foreach(CloneGameObjInfo info in list) |
|
{ |
|
if(info.gameObjID==checkInfo.gameObjID) |
|
{ |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
/// <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<PersonIconItemCtrl>().userInfo; |
|
if (checkInfo.gameObjID == userInfo.gameObjID) |
|
{ |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
}
|
|
|