/// <summary> /// 生成按钮组 /// </summary> /// <param name="FloorList"></param> private void InitItem(List <MapFloor> FloorList) { int ListCount = FloorList.Count; int ChildCount = FloorButtonGroup.transform.childCount; if (ChildCount > ListCount) { for (int i = 0; i < ChildCount; i++) { Transform SwitchButton = FloorButtonGroup.transform.GetChild(i); if (i <= ListCount - 1) { AddSwitchInfo(SwitchButton, FloorList[i]); } else { SwitchButton.gameObject.SetActive(false); } } } else { for (int i = 0; i < ListCount; i++) { if (i <= ChildCount - 1) { Transform SwitchButton = FloorButtonGroup.transform.GetChild(i); AddSwitchInfo(SwitchButton, FloorList[i]); } else { GameObject obj = Instantiate(FloorButtonPrefab, FloorButtonGroup.transform) as GameObject; obj.SetActive(true); obj.transform.localScale = Vector3.one; MapSwitchItem item = obj.GetComponent <MapSwitchItem>(); ItemList.Add(item); item.SetItem(FloorList[i], this); } } } }