public void EndGame() { EndRoundHandler.ResetTime(); _gameEnded = true; playerInfo.playerStats = new PlayerStats[players.Count]; for (int i = 0; i < Players.Count; i++) { Players[i].StopVibrating(); playerInfo.playerStats[i] = Players[i].Stats; Players[i].lockedByGame = true; } Serializacion.SaveJsonToDisk(playerInfo, "Registered Players"); var winner = Players.OrderByDescending(x => x.Stats.Score).First(); var winnerSkills = winner.GetComponentsInChildren <ComplementarySkillBase>(true).OrderBy(x => x.SkillIndex).ToArray(); _winPopup.Initialize(winner, winner.GetComponentInChildren <DefensiveSkillBase>(true), winner.GetComponentInChildren <Weapon>(true), winnerSkills[0], winnerSkills[1]); _winPopup.gameObject.SetActive(true); StartCoroutine(EndGameCoroutine(10f)); }
void OnGUI() { if (titleStyle == null) { titleStyle = new GUIStyle(); } titleStyle.fontStyle = FontStyle.Bold; if (reg == null) { //RegisteredPlayers reg = Serializacion.LoadJsonFromDisk <RegisteredPlayers>("Registered Players"); if (reg == null || reg.fileRegVersion < RegisteredPlayers.latestRegVersion) { reg = new RegisteredPlayers(); } else { regPlayers = reg.playerControllers.ToList(); allModes = Resources.LoadAll <SO_GameRules>("Scriptable Objects").Select(a => a.name.Substring(9)).ToArray(); int sceneCount = SceneManager.sceneCountInBuildSettings; allStages = new string[sceneCount]; for (int i = 0; i < sceneCount; i++) { allStages[i] = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i)); } allStages = allStages.Where(a => a.Split('_')[0] == "Stage").Select(a => a.Split('_')[1]).ToArray(); currentModeIndex = Mathf.Max(System.Array.IndexOf(allModes, reg.gameMode), 0); //currentStageIndex = Mathf.Max(System.Array.IndexOf(allStages, reg.stage.Split('_')[1]), 0); } } EditorGUILayout.LabelField("Game Configuration", titleStyle); EditorGUILayout.LabelField("Current Reg version: " + RegisteredPlayers.latestRegVersion); if (GUILayout.Button("Show Help")) { showRegHelp = !showRegHelp; } if (showRegHelp) { EditorGUILayout.HelpBox("This is the Game Configuration Window. Here, you can edit the amount of players and their respective controllers, as well as the game mode. Please remember that, when setting up the controllers, you must substract 1 from the actual controller number. For example, write 0 for controller 1", MessageType.Info); } if (regPlayers == null) { regPlayers = new List <int> { 0, 0 } } ; for (int i = 0; i < regPlayers.Count; i++) { EditorGUILayout.BeginHorizontal(); regPlayers[i] = EditorGUILayout.IntField("Player " + (i + 1) + " Controller", regPlayers[i]); if (regPlayers.Count > 2) { if (GUILayout.Button("Remove")) { regPlayers.RemoveAt(i); } } EditorGUILayout.EndHorizontal(); } if (regPlayers.Count < 4) { if (GUILayout.Button("Add")) { regPlayers.Add(0); } } if (allModes == null) { allModes = Resources.LoadAll <SO_GameRules>("Scriptable Objects").Select(a => a.name.Substring(9)).ToArray(); } if (modeIndexes == null) { modeIndexes = new int[allModes.Length]; for (int i = 0; i < modeIndexes.Length; i++) { modeIndexes[i] = i; } } currentModeIndex = EditorGUILayout.IntPopup("Mode:", currentModeIndex, allModes, modeIndexes); if (allStages == null) { int sceneCount = SceneManager.sceneCountInBuildSettings; allStages = new string[sceneCount]; for (int i = 0; i < sceneCount; i++) { allStages[i] = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i)); } allStages = allStages.Where(a => a.Split('_')[0] == "Stage").Select(a => a.Split('_')[1]).ToArray(); } if (stageIndexes == null) { stageIndexes = new int[allStages.Length]; for (int i = 0; i < stageIndexes.Length; i++) { stageIndexes[i] = i; } } currentStageIndex = EditorGUILayout.IntPopup("Stage:", currentStageIndex, allStages, stageIndexes); Debug.Log("stage: " + currentStageIndex); if (GUILayout.Button("Save Game Configuration")) { reg.playerControllers = new int[regPlayers.Count]; for (int i = 0; i < regPlayers.Count; i++) { reg.playerControllers[i] = regPlayers[i]; } reg.gameMode = allModes[currentModeIndex]; //Fix //reg.stage = "Stage_" + allStages[currentStageIndex]; Serializacion.SaveJsonToDisk(reg, "Registered Players"); } } }
void OnGUI() { if (titleStyle == null) { titleStyle = new GUIStyle(); } titleStyle.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField("Player URLs", titleStyle); player = EditorGUILayout.IntSlider(player, 1, 4); if (allBodies == null) { allBodies = Resources.LoadAll <GameObject>("Prefabs/Bodies").Select(a => a.name).ToArray(); } if (bodyIndexes == null) { bodyIndexes = new int[allBodies.Length]; for (int i = 0; i < bodyIndexes.Length; i++) { bodyIndexes[i] = i; } } if (allWeapons == null) { allWeapons = Resources.LoadAll <GameObject>("Prefabs/Weapons").Select(a => a.name).ToArray(); } if (weaponIndexes == null) { weaponIndexes = new int[allWeapons.Length]; for (int i = 0; i < weaponIndexes.Length; i++) { weaponIndexes[i] = i; } } if (allDefs == null) { allDefs = Resources.LoadAll <GameObject>("Prefabs/Skills/Defensive").Select(a => a.name).ToArray(); } if (defIndexes == null) { defIndexes = new int[allDefs.Length]; for (int i = 0; i < defIndexes.Length; i++) { defIndexes[i] = i; } } if (allComp1s == null) { allComp1s = Resources.LoadAll <GameObject>("Prefabs/Skills/Complementary").Select(a => a.name).ToArray(); } if (comp1Indexes == null) { comp1Indexes = new int[allComp1s.Length]; for (int i = 0; i < comp1Indexes.Length; i++) { comp1Indexes[i] = i; } } if (allComp2s == null) { allComp2s = Resources.LoadAll <GameObject>("Prefabs/Skills/Complementary").Select(a => a.name).ToArray(); } if (comp2Indexes == null) { comp2Indexes = new int[allComp2s.Length]; for (int i = 0; i < comp2Indexes.Length; i++) { comp2Indexes[i] = i; } } if (character == null) { character = new CharacterURLs(); character.complementaryURL = new string[2]; } currentBodyIndex = EditorGUILayout.IntPopup(currentBodyIndex, allBodies, bodyIndexes); character.bodyURL = allBodies[currentBodyIndex]; currentWeaponIndex = EditorGUILayout.IntPopup(currentWeaponIndex, allWeapons, weaponIndexes); character.weaponURL = allWeapons[currentWeaponIndex]; currentDefIndex = EditorGUILayout.IntPopup(currentDefIndex, allDefs, defIndexes); character.defensiveURL = allDefs[currentDefIndex]; currentComp1Index = EditorGUILayout.IntPopup(currentComp1Index, allComp1s, comp1Indexes); character.complementaryURL[0] = allComp1s[currentComp1Index]; currentComp2Index = EditorGUILayout.IntPopup(currentComp2Index, allComp2s, comp2Indexes); character.complementaryURL[1] = allComp2s[currentComp2Index]; if (GUILayout.Button("Save as Player " + player)) { Serializacion.SaveJsonToDisk(character, "Player " + player); } }
void Update() { previousGamePad = currentGamePad; currentGamePad = GamePad.GetState((PlayerIndex)selector); if (-0.3f < lastAnalogValue.x && lastAnalogValue.x < 0.3f) { if (/*JoystickInput.LeftAnalog(currentGamePad).x >= 0.3f ||*/JoystickInput.allKeys[JoystickKey.DPAD_RIGHT](previousGamePad, currentGamePad)) { selectedIndex = selectedIndex + 1 >= stages.Length ? 0 : selectedIndex + 1; } if (/*JoystickInput.LeftAnalog(currentGamePad).x <= -0.3f ||*/JoystickInput.allKeys[JoystickKey.DPAD_LEFT](previousGamePad, currentGamePad)) { selectedIndex = selectedIndex - 1 < 0 ? stages.Length - 1 : selectedIndex - 1; } if (JoystickInput.allKeys[JoystickKey.A](previousGamePad, currentGamePad)) { playerInfo.stage = stages[selectedIndex].stageScene.handle; print(playerInfo.stage); Serializacion.SaveJsonToDisk(playerInfo, "Registered Players"); if (!_loading) { StartCoroutine(StartGameCoroutine()); } } } #region KEYBOARD IMPLEMENTATION if (Input.GetKeyDown(KeyCode.RightArrow)) { selectedIndex = selectedIndex + 1 >= stages.Length ? 0 : selectedIndex + 1; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { selectedIndex = selectedIndex - 1 < 0 ? stages.Length : selectedIndex - 1; } if (Input.GetKeyDown(KeyCode.Return)) { if (!_loading) { StartCoroutine(StartGameCoroutine()); } } #endregion for (int i = 0; i < stages.Length; i++) { if (i != selectedIndex) { slotTexts[i].GetComponentInChildren <Transform>().localScale = new Vector3(1f, 1f, 1f); } else { slotTexts[i].GetComponentInChildren <Transform>().localScale = new Vector3(1.1f, 1.1f, 1.1f); } } }