void Start() { Players = new List <Player>(); vc = GetComponent <VectoryCondition>(); BattleBegin = false; for (int i = 0; i < playersParent.childCount; i++) { var player = playersParent.GetChild(i).GetComponent <Player>(); if (player != null) { Players.Add(player); } else { Debug.LogError("Invalid object in Players Parent game object"); } } NumberOfPlayers = Players.Count; CurrentPlayerNumber = Players.Min(p => p.playerNumber); GameController.GetInstance().Invoke(() => { Units = UnitManager.GetInstance().units; StartCoroutine(GameStart()); }, 0.1f); }
void Start() { Players = new List <Player>(); Units = UnitManager.GetInstance().units; vc = GetComponent <VectoryCondition>(); //Units.ForEach(u => { u.Initialize(); }); //调整了SkillManager的执行顺序,放在Default之前,这里把Initialize挪到UnitManager中执行。方便其他场景的角色初始化。 for (int i = 0; i < playersParent.childCount; i++) { var player = playersParent.GetChild(i).GetComponent <Player>(); if (player != null) { Players.Add(player); } else { Debug.LogError("Invalid object in Players Parent game object"); } } foreach (var unit in Units) { unit.UnitClicked += OnUnitClicked; unit.UnitDestroyed += OnUnitDestroyed; //设置同盟列表。 } NumberOfPlayers = Players.Count; CurrentPlayerNumber = Players.Min(p => p.playerNumber); StartCoroutine(GameStart()); }
IEnumerator LoadLevel() { //LoadPrefab var r = Resources.LoadAsync("Prefabs/Level/Level_" + Global.GetInstance().IndexToString(Global.GetInstance().BattleIndex)); yield return(r); //LevelInit var go = Instantiate(r.asset) as GameObject; level = go.transform; level.name = r.asset.name; var rtsCamera = Camera.main.GetComponent <RTSCamera>(); rtsCamera.cameraRange = level.Find("CameraRange").gameObject; rtsCamera.enabled = true; //VectoryCondition vc = level.GetComponent <VectoryCondition>(); //LoadUnits var characterParent = level.Find("Characters"); var spawnPointParent = level.Find("SpawnPoints"); for (int i = 0; i < spawnPointParent.childCount; i++) { var c = Resources.Load("Prefabs/Character/" + spawnPointParent.GetChild(i).name.Substring(0, spawnPointParent.GetChild(i).name.IndexOf('_'))) as GameObject; var cInstance = Instantiate(c, characterParent); cInstance.transform.position = spawnPointParent.GetChild(i).position; cInstance.transform.rotation = spawnPointParent.GetChild(i).rotation; cInstance.GetComponent <CharacterStatus>().playerNumber = int.Parse(spawnPointParent.GetChild(i).name.Substring(spawnPointParent.GetChild(i).name.IndexOf('_') + 1)); cInstance.name = spawnPointParent.GetChild(i).name; } Destroy(spawnPointParent.gameObject); //Units var unitManager = UnitManager.GetInstance(); unitManager.InitUnits(); unitManager.units.ForEach(u => u.GetComponent <Unit>().UnitSelected += UIManager.GetInstance().OnUnitSelected); Units = unitManager.units; //DialogManager DialogManager.GetInstance().enabled = true; //Task var task = GameObject.Find("Canvas").transform.Find("BattlePrepare").Find("Task"); task.Find("TaskTitle").GetComponent <Text>().text = level.Find("TaskTitle").GetComponent <Text>().text; task.Find("TaskContent").GetComponent <Text>().text = level.Find("TaskContent").GetComponent <Text>().text; Destroy(level.Find("TaskTitle").gameObject); Destroy(level.Find("TaskContent").gameObject); BattleFieldManager.GetInstance().BuildFloors(level.GetComponent <LevelInfo>().GridX, level.GetComponent <LevelInfo>().GridY); yield return(StartCoroutine(XMLManager.LoadAsync <CharacterDataBase>(Application.streamingAssetsPath + "/XML/Core/Level/Level_Battle_" + Global.GetInstance().IndexToString(Global.GetInstance().BattleIndex) + ".xml", result => Global.GetInstance().levelCharacterDB = result))); BattleBegin = false; //Players Players = new List <Player>(); playersParent = level.Find("Players"); for (int i = 0; i < playersParent.childCount; i++) { var player = playersParent.GetChild(i).GetComponent <Player>(); if (player != null) { Players.Add(player); } else { Debug.LogError("Invalid object in Players Parent game object"); } } NumberOfPlayers = Players.Count; CurrentPlayerNumber = Players.Min(p => p.playerNumber); yield return(new WaitForSeconds(0.1f)); if (Global.GetInstance().levelCharacterDB != null && Global.GetInstance().levelCharacterDB.characterDataList.Count > 0) { foreach (var characterData in Global.GetInstance().levelCharacterDB.characterDataList) { Global.GetInstance().characterDB.characterDataList.Add(characterData); } } }