using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public enum SelectionInitType { 所有, 总队, 支队, 大队, 中队, 战斗班 } public class RolesInit : MonoBehaviour { private Transform PrefabParent; private ToggleGroup Group; public static SelectionInitType NowInitType; public UI_Control_ScrollFlow _ScrollFlow; public GameObject CanMouPrefab; public GameObject DaDuiZhiHuiPrefab; public GameObject DaoDiaoPrefab; public GameObject GuanChaTuanPrefab; public GameObject ZhanDouBanZhangPrefab; public GameObject ZhiDuiZhiHuiPrefab; public GameObject ZongDuiZhiHuiZhongXinPrefab; public GameObject ZhiDuiZhiHuiZhongXinPrefab; public GameObject ZhongDuiZhuiHuiPrefab; public GameObject ZongDuiZhiHuiPrefab; public void Awake() { PrefabParent = transform; _ScrollFlow = GetComponent(); //if (GameSettings.othersSettings.mode != Mode.manoeuvre) // Init(SelectionInitType.所有); } /// /// 重新加载角色选择项 /// /// 需要加载的角色类型 public void Init(SelectionInitType Type) { foreach (Transform t in PrefabParent) { Destroy(t.gameObject); } PrefabParent.GetComponent().Items.Clear(); switch (Type) { case SelectionInitType.总队: ClonePrefab(ZongDuiZhiHuiZhongXinPrefab); ClonePrefab(DaoDiaoPrefab); ClonePrefab(GuanChaTuanPrefab); ClonePrefab(ZongDuiZhiHuiPrefab); ClonePrefab(CanMouPrefab); NowInitType = SelectionInitType.总队; break; case SelectionInitType.支队: ClonePrefab(ZhiDuiZhiHuiZhongXinPrefab); ClonePrefab(DaoDiaoPrefab); ClonePrefab(GuanChaTuanPrefab); ClonePrefab(ZhiDuiZhiHuiPrefab); ClonePrefab(CanMouPrefab); NowInitType = SelectionInitType.支队; break; case SelectionInitType.大队: ClonePrefab(GuanChaTuanPrefab); ClonePrefab(DaDuiZhiHuiPrefab); ClonePrefab(CanMouPrefab); ClonePrefab(GuanChaTuanPrefab); ClonePrefab(DaDuiZhiHuiPrefab); ClonePrefab(CanMouPrefab); NowInitType = SelectionInitType.大队; break; case SelectionInitType.中队: ClonePrefab(ZhongDuiZhuiHuiPrefab); ClonePrefab(ZhongDuiZhuiHuiPrefab); ClonePrefab(ZhongDuiZhuiHuiPrefab); ClonePrefab(ZhongDuiZhuiHuiPrefab); NowInitType = SelectionInitType.中队; break; case SelectionInitType.战斗班: ClonePrefab(ZhanDouBanZhangPrefab); ClonePrefab(ZhanDouBanZhangPrefab); ClonePrefab(ZhanDouBanZhangPrefab); ClonePrefab(ZhanDouBanZhangPrefab); NowInitType = SelectionInitType.战斗班; break; default: ClonePrefab(ZongDuiZhiHuiZhongXinPrefab); ClonePrefab(ZhiDuiZhiHuiZhongXinPrefab); ClonePrefab(DaoDiaoPrefab); ClonePrefab(GuanChaTuanPrefab); ClonePrefab(ZongDuiZhiHuiPrefab); ClonePrefab(ZhiDuiZhiHuiPrefab); ClonePrefab(DaDuiZhiHuiPrefab); ClonePrefab(ZhongDuiZhuiHuiPrefab); ClonePrefab(ZhanDouBanZhangPrefab); ClonePrefab(CanMouPrefab); NowInitType = SelectionInitType.所有; break; } StartCoroutine(Wait()); } private void ClonePrefab(GameObject Prefab) { GameObject g = Instantiate(Prefab, PrefabParent); g.name = Prefab.name; } IEnumerator Wait() { yield return new WaitForSeconds(0.3f); _ScrollFlow.Refresh(); for (int i = 0; i < PrefabParent.childCount; i++)//重新分组使角色选择只能选一个 { PrefabParent.GetChild(i).GetComponentInChildren().group = PrefabParent.GetComponent(); } } }