void AddAiPlayerController(int playerIndex) { Player player = players[playerIndex]; Common.AiImplementations[] teamAiTypes = MenuData.TeamAiImplementations; if (player.teamIndex >= teamAiTypes.Length) { Debug.LogError("attempting to attach AI for team index " + player.teamIndex + " but no AI for this index exists"); } Common.AiImplementations aiType = teamAiTypes[player.teamIndex]; if (aiType == Common.AiImplementations.Random) { aiType = (Common.AiImplementations)Random.Range((int)Common.AiImplementations.Default, (int)Common.AiImplementations.Random); } ICustomPlayerController aiController = null; switch (aiType) { case Common.AiImplementations.Default: { aiController = player.transform.gameObject.AddComponent <AiPlayerController>(); break; } case Common.AiImplementations.Aaron: { aiController = player.transform.gameObject.AddComponent <AaronAiPlayerController>(); break; } case Common.AiImplementations.Rich: { aiController = player.transform.gameObject.AddComponent <RichAiPlayerController>(); break; } default: { Debug.LogError("AddAiPlayerController - no implementation for ai type: " + aiType); break; } } player.controller.SetNameTag(aiController.GetDisplayTag()); aiController.SetPlayerController(player.controller); aiController.SetTeamIndex(player.teamIndex); player.customControllers.Add(aiController); }
private void StartGame() { Common.AiImplementations selectedTeamOneAi = (Common.AiImplementations)teamOneAiEdit.value; Common.AiImplementations selectedTeamTwoAi = (Common.AiImplementations)teamTwoAiEdit.value; Common.AiImplementations[] teamAiImplementations = new Common.AiImplementations[2]; teamAiImplementations[0] = selectedTeamOneAi; teamAiImplementations[1] = selectedTeamTwoAi; MenuData.TeamAiImplementations = teamAiImplementations; MenuData.GameWidth = int.Parse(gameWidthEdit.text); MenuData.GameHeight = int.Parse(gameHeightEdit.text); SceneManager.LoadScene("game", LoadSceneMode.Single); }
private void InitUi() { List <string> aiNames = new List <string>(); for (int i = 0; i <= (int)Common.AiImplementations.Random; i++) { Common.AiImplementations type = (Common.AiImplementations)i; aiNames.Add(Common.ToString(type)); } teamOneAiEdit.AddOptions(aiNames); teamTwoAiEdit.AddOptions(aiNames); Common.AiImplementations[] teamAiImplementations = MenuData.TeamAiImplementations; if (teamAiImplementations == null || teamAiImplementations.Length < 2) { Debug.LogError("teamAiImplementations array in MenuData not the expected length"); } teamOneAiEdit.value = (int)MenuData.TeamAiImplementations[0]; teamTwoAiEdit.value = (int)MenuData.TeamAiImplementations[1]; gameWidthEdit.text = "" + MenuData.GameWidth; gameHeightEdit.text = "" + MenuData.GameHeight; }