public void LoadPreviousLevelData() { if (File.Exists(levelEndFileName)) { string jsonSave = File.ReadAllText(levelEndFileName); LevelEndData loadedLevelEndData = JsonUtility.FromJson <LevelEndData>(jsonSave); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); playerCont.maxActionPoints = loadedLevelEndData.playerAP; playerCont.maxHealth = loadedLevelEndData.playerMaxHealth; playerCont.visibilityMultiplier = loadedLevelEndData.playerVisibility; playerCont.damage = loadedLevelEndData.playerDamage; playerCont.isRepelAvailable = loadedLevelEndData.isRepelAvailable; playerCont.isRevealAvailable = loadedLevelEndData.isRevealAvailable; playerCont.isConvertAvailable = loadedLevelEndData.isConvertAvailable; } }
private void OnLevelEnd(bool obj) { var playerChoiceData = new PlayerChoiceData(); playerChoiceData.enduranceUpgradeCount = enduranceUpgradeCount; playerChoiceData.productionUpgradeCount = productionUpgradeCount; playerChoiceData.unitPercentChanged = unitPercentChangeCount; playerChoiceData.timeFor25Unit = unitPercentTimes[0]; playerChoiceData.timeFor50Unit = unitPercentTimes[1]; playerChoiceData.timeFor75Unit = unitPercentTimes[2]; playerChoiceData.timeFor100Unit = unitPercentTimes[3]; Analytics.SendPlayerChoiceData(playerChoiceData); var lvlEndData = new LevelEndData(); lvlEndData.playTime = LevelController.PlayTime; int totalUnitProduced = 0; var towers = TowerController.GetAllTowers(); foreach (var t in towers) { if (t.Faction == FactionController.PlayerFaction) { lvlEndData.playerControlledPlanets++; } else if (t.Faction == FactionController.NeutralFaction) { lvlEndData.neutralPlanets++; } else if (t.Faction == FactionController.OtherFaction1) { lvlEndData.opponentControlledPlanets++; } totalUnitProduced += t.Generator.TotalProduced; } if (obj) { lvlEndData.statusCode = LevelStatusCode.Victory; } else { lvlEndData.statusCode = LevelStatusCode.Defeat; } if (convergenceDefeat) { lvlEndData.statusCode = LevelStatusCode.Tie; } if (levelQuit) { lvlEndData.statusCode = LevelStatusCode.Surrender; } lvlEndData.unitsCreated = totalUnitProduced; lvlEndData.unitsDestroyed = unitsDestroyed; Analytics.SendLevelEnd(lvlEndData); }
public void SaveEndOfLevelData() { //level is done so delete any data that was kept in case of losing and having to revert upgrades string upgradeCostRevertFileName = Path.Combine(Application.persistentDataPath, "UpgradeCostRevertData.json"); string totalUpgradeRevertFileName = Path.Combine(Application.persistentDataPath, "TotalUpgradeRevertData.json"); if (File.Exists(upgradeCostRevertFileName)) { File.Delete(upgradeCostRevertFileName); } if (File.Exists(totalUpgradeRevertFileName)) { File.Delete(totalUpgradeRevertFileName); } LevelEndData LevelEndData = new LevelEndData(); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); LevelEndData.playerMaxHealth = playerCont.maxHealth; LevelEndData.playerAP = playerCont.maxActionPoints; LevelEndData.playerDamage = playerCont.damage; LevelEndData.playerVisibility = playerCont.visibilityMultiplier; LevelEndData.isRepelAvailable = playerCont.isRepelAvailable; LevelEndData.isRevealAvailable = playerCont.isRevealAvailable; LevelEndData.isConvertAvailable = playerCont.isConvertAvailable; //save if key has been collected in level if (key == null) { if (SceneManager.GetActiveScene().buildIndex == 2) { if (!key1Collected) { key1Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 3) { if (!key2Collected) { key2Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 4) { if (!key3Collected) { key3Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 5) { if (!key4Collected) { key4Collected = true; numKeys++; } } } string json = JsonUtility.ToJson(LevelEndData); if (File.Exists(levelEndFileName)) { File.Delete(levelEndFileName); } File.WriteAllText(levelEndFileName, json); }
public static void SendLevelEnd(LevelEndData data) { CheckResult(UnityEngine.Analytics.Analytics.CustomEvent("Level End", data.ToDictionary())); }