public QualityController(VisionSDK sdk) { physicalMemory = new NativeSettings().GetPhysicalMemory() / 1000000; Log.Debug("QualityController availableMemroy = " + physicalMemory); storage = new PersistentDataStorage(Game.ForceVision); this.sdk = sdk; }
/// <summary> /// Sets the "beaten" flag for a level. /// </summary> /// <param name="pillarConfig">Pillar config.</param> /// <param name="difficulty">Difficulty.</param> /// <param name="hitsTaken">Hits taken.</param> public static void SetLevelBeaten(PillarConfig pillarConfig, int difficulty = 1, int hitsTaken = 0) { PersistentDataStorage data = new PersistentDataStorage(Game.ForceVision); ProgressionData progressionData = GetProgressionData(data); progressionData.LevelsBeat.Add(new ProgressionLevel(pillarConfig, difficulty, hitsTaken)); data.SaveSerialized(ProgressionFile, progressionData); }
/// <summary> /// Writes the manifest version. /// </summary> /// <param name="version">Version.</param> public static void WriteManifestVersion(string version) { version = version.Replace("\"", ""); version = version.TrimStart('0'); PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None); persistentDataStorage.SaveText(ManifestVersionFile, version, false); }
public void ClearProgression() { PersistentDataStorage vision = new PersistentDataStorage(Game.None); vision.DeleteFolder(vision.GetPersistentDataPath("")); PlayerPrefs.DeleteAll(); ProxyReload.SceneToLoad = SceneManager.GetActiveScene().name; SceneManager.LoadScene("ReloadProxyScene"); }
public void Init() { if (IsLoading == true || isCancel == true) { Cancel(); return; } IsLoading = true; persistentStore = new PersistentDataStorage(Game.None); cacheDirectory = persistentStore.GetPersistentDataPath(""); cache = new Dictionary <string, double>(); if (persistentStore.FileExists(CacheName)) { string tempOldCache = persistentStore.LoadText(CacheName); Log.Debug("old cache text = " + tempOldCache, Log.LogChannel.Download); string[] tempOldCacheLines = tempOldCache.Split('\n'); for (int i = 0; i < tempOldCacheLines.Length; i++) { if (!string.IsNullOrEmpty(tempOldCacheLines[i])) { string rawLine = tempOldCacheLines[i]; string[] rawLineComponents = rawLine.Split(':'); cache[rawLineComponents[0]] = double.Parse(rawLineComponents[1]); } } } downloads = new List <string>(); cloudStorageAPI = new CloudStorageAPI(monoBehaviour); progress = new Progress(); progress.StartingFileCount = 1; progress.FileRemainingCount = 1; #if RC_BUILD progress.Sections = 2; progress.CurrentSection = 1; UpdateProgress(); cloudStorageAPI.GetContentList(OnContentList, ""); #else progress.Sections = 3; progress.CurrentSection = 1; UpdateProgress(); cloudStorageAPI.AuthenticateWithGAE(OnAuthResponse, (downloadPercent) => { progress.PercentOfCurrentLoadingFileDownloaded = downloadPercent; UpdateProgress(); }); #endif }
/// <summary> /// Gets the manifest verison. /// If multiple entries appear in the string[], then each manifest file has been loaded but its contents not completely downlaoded, in the order that they were downloaded. /// </summary> /// <returns>The manifest verison.</returns> public static string[] GetManifestVersion() { PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None); if (persistentDataStorage.FileExists(ManifestVersionFile)) { string existingVersion = persistentDataStorage.LoadText(ManifestVersionFile); return(existingVersion.Split(',')); } return(new string[1] { "1" }); }
public static ProgressionData GetProgressionData(PersistentDataStorage data) { ProgressionData progressionData; if (data.FileExists(ProgressionFile)) { progressionData = data.LoadSerialized <ProgressionData>(ProgressionFile); } else { progressionData = new ProgressionData(); } return(progressionData); }
/// <summary> /// Initializes a new instance of the <see cref="Disney.ForceVision.ContainerAPI"/> class. /// </summary> /// <param name="game">Game.</param> public ContainerAPI(Game game) { // We need a MonoBehaviour for Native to call into as well for Streaming Asset loading. GameObject bridge = GameObject.Find("ForceVisionNativeBridge") ?? new GameObject("ForceVisionNativeBridge", typeof(NativeBridge)); NativeBridge = bridge.GetComponent <NativeBridge>(); // Data Storage / Loading StreamingAssets = new StreamingAssetsStorage(game, NativeBridge); PersistentData = new PersistentDataStorage(game); PlayerPrefs = new PlayerPrefsStorage(game); cdnAssetLoaderApi = new Disney.ForceVision.Internal.CdnAssetLoaderApi(NativeBridge); // Native Settings NativeSettings = new NativeSettings(); #if UNITY_ANDROID && !UNITY_EDITOR NativeBridge.StartLowMemoryPoll(NativeSettings); #endif }
/// <summary> /// Appends the manifest version. /// </summary> /// <param name="version">Version.</param> public static void AppendManifestVersion(string version) { PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None); if (persistentDataStorage.FileExists(ManifestVersionFile)) { version = version.Replace("\"", ""); version = version.TrimStart('0'); string existingVersion = persistentDataStorage.LoadText(ManifestVersionFile); if (existingVersion != version) { string[] parts = existingVersion.Split(','); existingVersion = parts[0]; persistentDataStorage.SaveText(ManifestVersionFile, existingVersion + "," + version, false); } } else { WriteManifestVersion(version); } }
/// <summary> /// Find the proper settings for the given device. /// </summary> /// <param name="logger">The logger.</param> /// <param name="deviceConfigFile">allow using a custom devices for testing.</param> public void Init(VisionLogger logger, string deviceConfigFile) { Logger = logger; persistentDataStorage = new PersistentDataStorage(Game.ForceVision); // Hardware TextAsset headsets = Resources.Load <TextAsset>("Profiles/headset_list"); if (headsets == null) { Log.Error("Error: Fail to load hardware list"); return; } HeadsetList = JsonUtility.FromJson <HeadsetList>(headsets.text); HeadsetSettings = GetRecomendedSettingsForHeadset(); // Devices string devices = LoadFromCdnOrSdkResources(deviceConfigFile); if (devices == null) { Log.Error("Error: Fail to load device list " + deviceConfigFile); return; } DeviceList = JsonUtility.FromJson <Devices>(devices); PlatformName = (Application.platform == RuntimePlatform.IPhonePlayer) ? "iOS" : "Android"; #if UNITY_EDITOR PlatformName = EditorPlatform; #endif DeviceSettings = GetRecomendedSettingsForDevice(); Log.Debug("JCSettingsManager inited with " + CurrentDevice.Name + " supported " + HasDeviceProfile); }
/// <summary> /// Plays the trailer /// </summary> /// <param name="showVideoControls">If set to <c>true</c> show video controls.</param> public IEnumerator PlayTrailer(bool showVideoControls = false) { StreamingAssetsStorage storage = new StreamingAssetsStorage(Game.ForceVision, null); string introVideoPath = ""; //copying to persistent data may work, you can also try prefixing the path with "jar://" #if UNITY_ANDROID PersistentDataStorage persistentStorage = new PersistentDataStorage(Game.ForceVision); if (persistentStorage.FileExists(StarWarsIntroVideo) == false) { storage.LoadStreamingAssetsFile(StarWarsIntroVideo, (string error, byte[] bytes) => { if (string.IsNullOrEmpty(error)) { //save file in persistentdata bool writeSuccess = persistentStorage.SaveBytes(StarWarsIntroVideo, bytes); if (writeSuccess) { introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo); } else { //handle error Log.Error("Error! Unable to save the video file to persistent data."); } } else { //handle error Log.Error("Error! Unable to load from streaming assets."); } }, true); } else { introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo); } #else introVideoPath = storage.GetStreamingAssetPath(StarWarsIntroVideo); #endif // checking that path is valid string if (!string.IsNullOrEmpty(introVideoPath)) { if (PlayCount > 0) { // setting button state if (TrailerPlayButton) { TrailerPlayButton.interactable = false; } // stopping background music AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicPause, gameObject); } if (Application.isEditor) { Debug.Log("Playing Trailer (Trailer cannot play in Editor)"); } else { // playing intro video Handheld.PlayFullScreenMovie(introVideoPath, Color.black, showVideoControls ? FullScreenMovieControlMode.CancelOnInput : FullScreenMovieControlMode.Hidden); } // adding pause yield return(new WaitForSeconds(1.5f)); if (PlayCount > 0) { // setting button state if (TrailerPlayButton) { TrailerPlayButton.interactable = true; } // starting background music AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicResume, gameObject); } // setting new play count StereoStorage.SetPrefInt(IntroPlayedCountKey, PlayCount + 1); } }
public void FinishLevel(bool victory) { // Clear Triggers ArchivistInterstitialController.Triggers.Clear(); MenuAudioController.Triggers.Clear(); // If this is the first time you won this level bool firstTimeBeat = false; bool earnedInsight = false; bool earnedLeadership = false; bool earnedAdvancedCombat = false; // Level we just played PillarConfig lastPlayedLevel = MenuController.ConfigToLoad; Difficulty lastPlayedDifficulty = MenuController.DifficultyToLoad; PersistentDataStorage data = new PersistentDataStorage(Game.ForceVision); ProgressionData progressionData = GetProgressionData(data); // Did not come from a game if (lastPlayedLevel == null || progressionData == null) { LoadNextScene(false, false); return; } // Just earned a medal if (!progressionData.InsightMedalUnlocked && IsMedalUnlocked(MedalType.Insight)) { earnedInsight = true; progressionData.InsightMedalUnlocked = true; } if (!progressionData.LeadershipMedalUnlocked && IsMedalUnlocked(MedalType.Leadership)) { earnedLeadership = true; progressionData.LeadershipMedalUnlocked = true; } if (!progressionData.CombatUnlocked && IsMedalUnlocked(MedalType.Combat)) { progressionData.CombatUnlocked = true; } if (!progressionData.AdvancedCombatUnlocked && IsMedalUnlocked(MedalType.AdvancedCombat)) { earnedAdvancedCombat = true; progressionData.AdvancedCombatUnlocked = true; } if (!progressionData.MasteryUnlocked && IsMedalUnlocked(MedalType.Mastery)) { progressionData.MasteryUnlocked = true; } data.SaveSerialized(ProgressionFile, progressionData); // Check for first time. if (victory) { ProgressionLevel level = progressionData.LevelsBeat.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); int hitsTaken = 0; if (lastPlayedLevel.Game == Game.Duel && GetDuelApi().LastResult != null) { hitsTaken = GetDuelApi().LastResult.HitsTaken; Log.Debug("LastResult found. Setting hitsTaken to " + hitsTaken.ToString()); } else { Log.Debug("LastResult NOT found. Setting hitsTaken to zero"); } if (level == null) { SetLevelBeaten(lastPlayedLevel, (int)lastPlayedDifficulty, hitsTaken); firstTimeBeat = true; if (lastPlayedLevel.IsBonusPlanet) { PlanetLineController.BeatFirstTime = false; MenuController.UnlockedPillar = true; } else { PlanetLineController.BeatFirstTime = true; } } // You did better this time (DUEL only) else if (level.HitsTaken > hitsTaken) { progressionData.LevelsBeat.First(item => item == level).HitsTaken = hitsTaken; data.SaveSerialized(ProgressionFile, progressionData); } } #region LOSS TRIGGERS // Defeat Archivist and strike down (loss) if (lastPlayedDifficulty == Difficulty.Hard && lastPlayedLevel.Duelist == DuelAPI.Duelist.Archivist && !victory) { ProgressionLevel level = progressionData.LevelsLost.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); if (GetDuelApi().LastResult != null && GetDuelApi().LastResult.DuelEnd == DuelAPI.DuelEndCondition.ObjectiveFail && level == null) { progressionData.LevelsLost.Add(new ProgressionLevel(lastPlayedLevel, (int)lastPlayedDifficulty)); data.SaveSerialized(ProgressionFile, progressionData); // Animation Trigger: Defeat Archivist on hard and strike down MenuAudioController.Triggers.Add(Constants.LoseCoreDuelHard); LoadNextScene(true, victory); return; } } // First Loss based on Config Values if (!victory && !string.IsNullOrEmpty(lastPlayedLevel.LostVOTrigger[(int)lastPlayedDifficulty - 1])) { ProgressionLevel level = progressionData.LevelsLost.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); // First Time Loss if (level == null) { // Save it progressionData.LevelsLost.Add(new ProgressionLevel(lastPlayedLevel, (int)lastPlayedDifficulty)); data.SaveSerialized(ProgressionFile, progressionData); // Audio Trigger: /* * Config: first loss on pillar 1 of assault (easy, medium, and hard), chess, tower for all planets * Config: First Time win first Strategy battle on Naboo * Config: First time win first Holochess match on Naboo * Config: First time defeat last assault mode on each planet (easy and medium) */ MenuAudioController.Triggers.Add(lastPlayedLevel.LostVOTrigger[(int)lastPlayedDifficulty - 1]); LoadNextScene(true, victory); return; } } #endregion // Always go back to where you came if you lose if (!victory) { LoadNextScene(true, victory); return; } // Not first time, either go back to where you came, or the next planet if (!firstTimeBeat) { LoadNextScene(true, victory); return; } // Error.. if (lastPlayedLevel.Interstitial.Length < (int)lastPlayedDifficulty) { LoadNextScene(false, victory); return; } // They unlocked green for the first time if (lastPlayedLevel.Game == Game.Duel && lastPlayedDifficulty == Difficulty.Easy && lastPlayedLevel.Duelist == DuelAPI.Duelist.KyloRen) { SetSavedSaberColorID((int)ColorID.GREEN); } // Hard Archivist Let Live if (lastPlayedDifficulty == Difficulty.Hard && lastPlayedLevel.Duelist == DuelAPI.Duelist.Archivist) { SetSavedSaberColorID((int)ColorID.PURPLE); // Animation Trigger: Defeat Archivist on hard and let live ArchivistInterstitialController.Triggers.Add(Constants.WinCoreDuelHard); LoadNextScene(false, victory); return; } bool earnAllTrailMedals = false; // Beat the LAST duelist on Hard if (earnedAdvancedCombat) { // Animation Trigger: Config: Defeat Naboo, Garal, Lothel, Hoth, Takodana Duelist on hard string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; ArchivistInterstitialController.Triggers.Add(audioEvent); // Animation Trigger: Earn Advanced Combat Medal ArchivistInterstitialController.Triggers.Add(Constants.EarnAdvancedCombat); // This will always stack 2, 3 if 2 other medals are unlocked already if (IsMedalUnlocked(MedalType.Insight) && IsMedalUnlocked(MedalType.Leadership)) { // Animation Trigger: Earned advanced combat, leadership, Insight medals ArchivistInterstitialController.Triggers.Add(Constants.EarnAllTrailMedals); // Stack 3 animations, Duelist Beat, Medal Earned, Dark Archivist Unlocked progressionData.DarkArchivistUnlocked = true; data.SaveSerialized(ProgressionFile, progressionData); } LoadNextScene(false, victory); return; } // Unlocked Dark Archivist if ((earnedLeadership || earnedInsight) && !progressionData.DarkArchivistUnlocked) { if (IsMedalUnlocked(MedalType.Insight) && IsMedalUnlocked(MedalType.Leadership) && IsMedalUnlocked(MedalType.AdvancedCombat)) { // Animation Trigger: Earned advanced combat, leadership, Insight medals earnAllTrailMedals = true; progressionData.DarkArchivistUnlocked = true; data.SaveSerialized(ProgressionFile, progressionData); } } // Animation Trigger /* * Config: Defeat Ren on easy * Config: Defeat Archivist on med * Config: Defeat Core Holochess * Config: Defeat Core Tower Defense * Config: Defeat Naboo, Garal, Lothel, Hoth, Takodana Duelist on hard */ if (lastPlayedLevel.Interstitial[(int)lastPlayedDifficulty - 1]) { string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; ArchivistInterstitialController.Triggers.Add(audioEvent); } // Audio Trigger /* * Config: Defeat Maul Easy * Config: Win Naboo Holochess Trial * Config: Win Naboo Strategy Trial * Config: Defeat Sister on easy * Config: Win Garel Holochess Trial * Config: Win Garel Strategy Trial * Config: Defeat Inquisitor on easy * Config: Win Lothal Holochess Trial * Config: Win Lothal Strategy Trial * Config: Defeat Vader on easy * Config: Win Hoth Holochess Trial * Config: Win Hoth Strategy Trial * Config: Win Takodana Holochess * Config: Win Takodana Strategy * Config: Defeat Maul on Med * Config: Defeat Sister on Med * Config: Defeat Inquisitor on med * Config: Defeat Vader on med * Config: Defeat Ren on med */ else if (!string.IsNullOrEmpty(lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1])) { // checking for duel games on bonus planet if (lastPlayedLevel.IsBonusPlanet) { bool hasWonStrategy = towerApi.HasWonBattle(TDAPI.Battles.Crait_3); if (lastPlayedLevel.Game == Game.Duel) { // player has not completed strategy if (!hasWonStrategy) { if (lastPlayedDifficulty == Difficulty.Easy) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndNotCompleteStrategy); } else if (lastPlayedDifficulty == Difficulty.Medium) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistMedium); } else if (lastPlayedDifficulty == Difficulty.Hard) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistHard); } } // player has completed strategy else { if (lastPlayedDifficulty == Difficulty.Easy) { ArchivistInterstitialController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndCompleteStrategy); } } } else if (lastPlayedLevel.Game == Game.TowerDefense) { // checking if duelist complete (easy) bool hasWonDuelist = duelApi.Progress.HasCompleted(DuelAPI.Duelist.PraetorianGuards, 1); if (hasWonStrategy && !hasWonDuelist) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitStrategyAndNotCompleteDuelist); } else if (hasWonStrategy && hasWonDuelist) { ArchivistInterstitialController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndCompleteStrategy); } } else if (lastPlayedLevel.Game == Game.Assault && lastPlayedLevel.PillarNumber == 2) { MenuAudioController.Triggers.Add(lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]); } } else { string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; MenuAudioController.Triggers.Add(audioEvent); } } // Make it last if (earnAllTrailMedals) { ArchivistInterstitialController.Triggers.Add(Constants.EarnAllTrailMedals); } if (lastPlayedLevel.IsBonusPlanet && lastPlayedLevel.Game == Game.Duel) { LoadNextScene(true, victory); } else { LoadNextScene((lastPlayedLevel.PillarNumber < 3), victory); } }
/// <summary> /// Purges the cpipe cache. /// Called when app starts and runs if the app version on disk is older then the app verison. /// The purge will delete any english or non loc specific files and update the cache with all of the latest version from the embedded manifest. /// </summary> public static void PurgeCpipeCache() { bool doPurge = false; Dictionary <string, string> cache = new Dictionary <string, string>(); PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None); StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null); //if app version has increased, do purge AppVersion appVersion = new AppVersion(Application.version); if (persistentDataStorage.FileExists(appVerisonFile)) { AppVersion storedVersion = new AppVersion(persistentDataStorage.LoadText(appVerisonFile)); if (storedVersion.Major > appVersion.Major) { doPurge = true; } else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor > appVersion.Minor) { doPurge = true; } else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor >= appVersion.Minor && storedVersion.Revision > appVersion.Revision) { doPurge = true; } } else { doPurge = true; } Log.Debug("dopurge " + doPurge, Log.LogChannel.General); if (doPurge == false) { return; } string oldCache = ""; if (persistentDataStorage.FileExists(CacheName)) { oldCache = persistentDataStorage.LoadText(CacheName); string[] tempOldCacheLines = oldCache.Split('\n'); for (int i = 0; i < tempOldCacheLines.Length; i++) { if (!string.IsNullOrEmpty(tempOldCacheLines[i])) { string rawLine = tempOldCacheLines[i]; string[] rawLineComponents = rawLine.Split(':'); cache[rawLineComponents[0]] = rawLineComponents[1]; } } } Log.Debug("load manifest from streaming at " + Application.streamingAssetsPath + "/" + Game.ForceVision + "/" + EmbeddedCpipeManifestFile, Log.LogChannel.General); //load streaming assets manifest and write cache file of embedded content streamingAssetsStorage.LoadStreamingAssetsText(Game.ForceVision + "/" + EmbeddedCpipeManifestFile, (error, text) => { if (string.IsNullOrEmpty(error)) { try { JSONObject manifest = new JSONObject(text); WriteManifestVersion(manifest["version"].ToString()); JSONObject paths = manifest["paths"]; string newCacheString = ""; for (int i = 0; i < paths.keys.Count; i++) { string folder = paths.keys[i]; string v = paths[i]["v"].ToString(); //update english only bool isEnglishFile = true; foreach (string languageFolder in Localizer.LanguageFolders) { if (folder.Contains("GeneratedSoundBanks") && folder.Contains("/" + languageFolder + "/") && languageFolder != Localizer.LanguageFolders[0]) { isEnglishFile = false; Log.Debug("non english file found. path = " + folder, Log.LogChannel.Download); } } if (isEnglishFile) { if (cache.ContainsKey(folder)) { //if in cache already then update to local version and delete local file if (persistentDataStorage.FileExists(folder)) { persistentDataStorage.DeleteFile(folder); Log.Debug("deleteing file in " + folder, Log.LogChannel.Download); } } newCacheString += folder + ":" + v + "\n"; } else { if (cache.ContainsKey(folder)) { newCacheString += folder + ":" + v + "\n"; } } } persistentDataStorage.SaveText(CacheName, newCacheString, false); persistentDataStorage.SaveText(appVerisonFile, Application.version, false); } catch (System.Exception e) { Log.Exception(e); } } else { #if !UNITY_EDITOR Log.Error("error loading manifest from streamingassets. " + error); #endif } }, true); }