void UpdateChildrenCallback(int index, Transform trans) { InsteadOpenRoomPanelData iorpd = GameData.Instance.InsteadOpenRoomPanelData; InsteadOpenRecordMessage room = trans.GetComponent <InsteadOpenRecordMessage>(); room.RoomMessage = iorpd.RoomMessage[index]; room.index = index; room.ShowInsteadRecord(); }
/// <summary> /// 产生代开房间的预置体,如果玩家关闭之后 /// </summary> void SpwanInsteadOpenRecord() { InsteadOpenRoomPanelData iorpd = GameData.Instance.InsteadOpenRoomPanelData; if (iorpd.isNoRecord) { NoRecord.gameObject.SetActive(true); } else { NoRecord.gameObject.SetActive(false); } if (!iorpd.isFirstSpwanInsteadRecord) { return; } iorpd.isFirstSpwanInsteadRecord = false; //删除玩家的之前的面板 InsteadOpenRecordMessage[] rooms = InsteadOpenRecord.transform.Find("Content").GetComponentsInChildren <InsteadOpenRecordMessage>(); if (rooms.Length > 0) { for (int i = 0; i < rooms.Length; i++) { Destroy(rooms[i].gameObject); } } InsteadOpenRecord.transform.Find("Content").GetComponent <GridLayoutGroup>().enabled = true; InsteadOpenRecord.transform.Find("Content").GetComponent <ContentSizeFitter>().enabled = true; int count = iorpd.RoomMessage.Count; Debug.LogError("count:" + count); if (count <= 0) { return; } if (count > 5) { for (int i = 0; i < 5; i++) { GameObject go = Instantiate(Resources.Load <GameObject>("Lobby/InsteadCreatRoomPanel/InsteadOpenRecord")); go.transform.SetParent(InsteadOpenRecord.transform.Find("Content")); go.transform.localEulerAngles = Vector3.zero; go.transform.localPosition = new Vector3(go.transform.localPosition.x, go.transform.localPosition.y, 0); go.transform.localScale = Vector3.one; go.name = "InsteadOpenRecord" + i; } //初始化数据列表; infinityGridLayoutGroup = InsteadOpenRecord.transform.Find("Content").GetComponent <InfinityGridLayoutGroup>(); infinityGridLayoutGroup.Init(); //Invoke("SetAmount", 0.1f); infinityGridLayoutGroup.SetAmount(iorpd.RoomMessage.Count); infinityGridLayoutGroup.updateChildrenCallback = UpdateChildrenCallback; } else { for (int i = 0; i < count; i++) { GameObject go = Instantiate(Resources.Load <GameObject>("Lobby/InsteadCreatRoomPanel/InsteadOpenRecord")); go.transform.SetParent(InsteadOpenRecord.transform.Find("Content")); go.transform.localEulerAngles = Vector3.zero; go.transform.localPosition = new Vector3(go.transform.localPosition.x, go.transform.localPosition.y, 0); go.transform.localScale = Vector3.one; go.name = "InsteadOpenRecord" + i; InsteadOpenRecordMessage room = go.GetComponent <InsteadOpenRecordMessage>(); room.RoomMessage = iorpd.RoomMessage[i]; room.index = i; room.ShowInsteadRecord(); } } }