public void CartData() { var mem = new MemoryModule(); mem.InitRam(); var storage = new PersistentDataStorage(mem); mem.AddMemoryListener(storage); Fix writeValNeg = (Fix)(-354.245); Fix writeValPos = (Fix)325.246; storage.CartData("test_slot_0"); storage.Dset(0, writeValNeg); storage.Dset(1, writeValPos); storage.Dset(63, writeValPos); storage.CartData("test_slot_1"); storage.Dset(0, writeValPos); Assert.AreNotEqual(writeValNeg, storage.Dget(0)); storage.CartData("test_slot_0"); Assert.AreEqual(writeValNeg, storage.Dget(0)); Assert.AreEqual(writeValPos, storage.Dget(1)); Assert.AreEqual(writeValPos, storage.Dget(63)); }
public CdnAssetLoaderApi(MonoBehaviour monoBehaviour, Game game = Game.None, bool tryPersistentData = true) { streamingAssetStorage = new StreamingAssetsStorage(game, monoBehaviour); #if !SKU_CHINA && (!UNITY_EDITOR || CDN_ENABLE_IN_UNITY_EDITOR) if (tryPersistentData) { persistentDataStorage = new PersistentDataStorage(game); } #endif }
/// <summary> /// Creates the persistent data storage for testing. /// </summary> /// <param name="game">Game.</param> public void CreatePersistentDataStorageForTesting(Game game = Game.None) { if (!Application.isEditor || Application.isPlaying) { Debug.LogError("CreatePersistentDataStorageForTesting() should only be run by the Unity Test Runner"); return; } persistentDataStorage = new PersistentDataStorage(game); }
public void TestDynamicPoolInitialState([Values(1, 22, 333, 4444)] int total) { // Prepare PersistencySettings settings = CreateTestSettings(); PersistentSceneSystem persistentSceneSystem = World.GetOrCreateSystem <PersistentSceneSystem>(); BeginFramePersistencySystem beginFramePersistencySystem = World.GetExistingSystem <BeginFramePersistencySystem>(); beginFramePersistencySystem.ReplaceSettings(settings); PersistentDataStorage dataStorage = persistentSceneSystem.PersistentDataStorage; Hash128 identifier = Hash128.Compute("DynamicPoolTests"); NativeArray <PersistableTypeHandle> typeHandles = new NativeArray <PersistableTypeHandle>(Archetype.Length, Allocator.Persistent); for (int i = 0; i < typeHandles.Length; i++) { typeHandles[i] = settings.GetPersistableTypeHandleFromFullTypeName(Archetype[i].GetManagedType().FullName); // This is not advised in a game } // Action Entity prefabEntity = m_Manager.CreateEntity(Archetype); m_Manager.SetComponentData(prefabEntity, new EcsTestData(1)); m_Manager.AddComponent <Prefab>(prefabEntity); persistentSceneSystem.InitializePool(prefabEntity, total, identifier, typeHandles); // Verify { Assert.True(dataStorage.IsInitialized(identifier), "PoolContainer is not initialized!"); PersistentDataContainer container = dataStorage.GetInitialStateReadContainer(identifier); int sizePerEntity = container.GetDataLayoutAtIndex(0).SizePerEntity; Assert.AreEqual(sizePerEntity * total, container.GetRawData().Length, "The data container was not of the expected size!"); int amountNonZero = container.GetRawData().Count(dataByte => dataByte != 0); Assert.NotZero(amountNonZero, "The datacontainer didn't have valid initial state."); } // Action 2 total += 31; persistentSceneSystem.InstantChangePoolCapacity(identifier, total); // Verify { Assert.True(dataStorage.IsInitialized(identifier), "PoolContainer is not initialized!"); dataStorage.ToIndex(0); PersistentDataContainer container = dataStorage.GetReadContainerForCurrentIndex(identifier); int sizePerEntity = container.GetDataLayoutAtIndex(0).SizePerEntity; Assert.AreEqual(sizePerEntity * total, container.GetRawData().Length, "The data container was not of the expected size after an InstantResize!"); int amountNonZero = container.GetRawData().Count(dataByte => dataByte != 0); Assert.NotZero(amountNonZero, "The datacontainer grew but didn't have valid initial state."); } // Cleanup m_Manager.DestroyEntity(m_Manager.UniversalQuery); }
public static void Load() { PersistentDataStorage dataStorage = new PersistentDataStorage(); var loadedBooks = dataStorage.Restore<IEnumerable<Book>>(dataStorageKey); if (loadedBooks != null) { foreach (Book book in loadedBooks) { Books.Add(new BookViewModel(book) {IsBookmarked = true }); } } }
public override void _Ready() { PersistentDataStorage.Load(); if (this._iconScrollList == null) { this._iconScrollList = (VBoxContainer)this.GetNode("Bestiary").GetNode("Container").GetNode("MarginContainer").GetNode("ScrollListEnemyIcons").GetNode("ScrollBoxEnemyIcons"); this._bigIcon = (AnimatedSprite)this.GetNode("Bestiary").GetNode("Container2").GetNode("MarginContainer").GetNode("BestiaryLog").GetNode("EnemySprite"); this._lockIcon = (AnimatedSprite)this.GetNode("Bestiary").GetNode("Container2").GetNode("MarginContainer").GetNode("BestiaryLog").GetNode("LockIcon"); this._enemyDescription = (RichTextLabel)this.GetNode("Bestiary").GetNode("Container2").GetNode("MarginContainer").GetNode("BestiaryLog").GetNode("Container").GetNode("MarginContainer").GetNode("EnemyDescription"); this._enemyName = (RichTextLabel)this.GetNode("Bestiary").GetNode("Container2").GetNode("MarginContainer").GetNode("BestiaryLog").GetNode("Container2").GetNode("MarginContainer").GetNode("EnemyName"); this.PopulateBestiary(); this.PrepareBestiary(); ((Button)this.GetNode("Bestiary").GetNode("MarginContainer").GetNode("Container").GetNode("MarginContainer").GetNode("Button")).Connect("pressed", this, "CloseBestiary"); } }
private MapManager() { _map = ConfigReader.GetConfig().GetField("map"); _openedStations = PersistentDataStorage.GetStringDictionary(OpenedStationsKey); _currentWorldId = PlayerPrefs.GetString(CurrentWorldKey, ""); if (_currentWorldId == string.Empty) { SetCurrentWorld(_map.keys[0]); } if (_openedStations.Count == 0) { OpenNextLevel(); } if (_currentStationInfo == null) { SetCurrentStation(GetDebugLevelName()); } }
private void loadFlagImage(string path) { byte[] bytes = null; PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.ForceVision); if (persistentDataStorage.FileExists(path)) { bytes = persistentDataStorage.LoadBytes(path); } else { StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.ForceVision, this); streamingAssetsStorage.LoadStreamingAssetsFile(path, (success, loadedBytes) => { if (string.IsNullOrEmpty(success)) { bytes = loadedBytes; } else { Log.Error("No image flag found for " + path); } }, true); } if (bytes != null && bytes.Length > 0) { Texture2D flagTexture = new Texture2D(4, 4); bool isLoaded = flagTexture.LoadImage(bytes); if (isLoaded) { Flag.sprite = Sprite.Create(flagTexture, new Rect(0, 0, flagTexture.width, flagTexture.height), new Vector2(0, 0)); } } }
public static void Save() { PersistentDataStorage dataStorage = new PersistentDataStorage(); dataStorage.Backup(dataStorageKey, Books.Select(bookViewModel => bookViewModel.Book)); }
private void SaveOpenedStations() { PersistentDataStorage.SaveStringDictionary(OpenedStationsKey, _openedStations); }
public void TestDynamicPoolApplyAndPersist([Values(InstantiationType.Manager, InstantiationType.Command, InstantiationType.ParallelCommand)] InstantiationType instantiationType, [Values(1, 2, 3, 444, 5555)] int total, [Values(false, true)] bool groupedJobs) { // Prepare PersistencySettings settings = CreateTestSettings(); settings.ForceUseGroupedJobsInEditor = groupedJobs; settings.ForceUseNonGroupedJobsInBuild = !groupedJobs; Assert.True(groupedJobs == settings.UseGroupedJobs()); PersistentSceneSystem persistentSceneSystem = World.GetOrCreateSystem <PersistentSceneSystem>(); BeginFramePersistencySystem beginFramePersistencySystem = World.GetExistingSystem <BeginFramePersistencySystem>(); beginFramePersistencySystem.ReplaceSettings(settings); EndFramePersistencySystem endFramePersistencySystem = World.GetOrCreateSystem <EndFramePersistencySystem>(); endFramePersistencySystem.ReplaceSettings(settings); EndInitializationEntityCommandBufferSystem ecbSystem = World.GetOrCreateSystem <EndInitializationEntityCommandBufferSystem>(); PersistentDataStorage dataStorage = persistentSceneSystem.PersistentDataStorage; Hash128 identifier = Hash128.Compute("DynamicPoolTests"); NativeArray <PersistableTypeHandle> typeHandles = new NativeArray <PersistableTypeHandle>(Archetype.Length, Allocator.Persistent); for (int i = 0; i < typeHandles.Length; i++) { typeHandles[i] = settings.GetPersistableTypeHandleFromFullTypeName(Archetype[i].GetManagedType().FullName); // This is not advised in a game } // Action Entity prefabEntity = m_Manager.CreateEntity(Archetype); m_Manager.AddComponent <Prefab>(prefabEntity); persistentSceneSystem.InitializePool(prefabEntity, total, identifier, typeHandles); int amountSpawned = 0; InstantiatePersistent(instantiationType, m_Manager, prefabEntity, ref amountSpawned, total); persistentSceneSystem.InstantChangePoolCapacity(identifier, total * 2); // double amount InstantiatePersistent(instantiationType, m_Manager, prefabEntity, ref amountSpawned, total); m_Manager.RemoveComponent <EmptyEcsTestData>(m_Manager.CreateEntityQuery(typeof(PersistenceState))); Entities.ForEach((Entity e, ref EcsTestData testData, DynamicBuffer <DynamicBufferData1> buffer) => { testData.Value = 1; buffer.Add(new DynamicBufferData1() { Value = 1 }); }); dataStorage.ToIndex(0); endFramePersistencySystem.RequestPersist(dataStorage.GetWriteContainerForCurrentIndex(identifier)); endFramePersistencySystem.Update(); m_Manager.CompleteAllJobs(); beginFramePersistencySystem.RequestApply(dataStorage.GetInitialStateReadContainer(identifier)); beginFramePersistencySystem.Update(); ecbSystem.Update(); // Test int amountSurvivingEntities = m_Manager.CreateEntityQuery(typeof(EcsTestData)).CalculateEntityCount(); Assert.True(amountSurvivingEntities == total * 2, $"{instantiationType} didn't create the expected amount of entities({amountSurvivingEntities}vs{total*2})! (Or they were destroyed by Apply)"); Entities.ForEach((Entity e, ref EcsTestData testData, DynamicBuffer <DynamicBufferData1> buffer) => { Assert.True(testData.Value == 0, "The apply didn't restore the component value!"); Assert.True(buffer.IsEmpty, "The apply didn't restore the buffer!"); Assert.True(m_Manager.HasComponent <EmptyEcsTestData>(e), "The apply didn't restore the component!"); }); // Action dataStorage.ToIndex(0); beginFramePersistencySystem.RequestApply(dataStorage.GetWriteContainerForCurrentIndex(identifier)); beginFramePersistencySystem.Update(); ecbSystem.Update(); // Test amountSurvivingEntities = m_Manager.CreateEntityQuery(typeof(EcsTestData)).CalculateEntityCount(); Assert.True(amountSurvivingEntities == total * 2, $"Some entities were unexpectedly destroyed!"); Entities.ForEach((Entity e, ref EcsTestData testData, DynamicBuffer <DynamicBufferData1> buffer) => { Assert.True(testData.Value == 1, "The second apply didn't restore the component value!"); Assert.True(buffer[0].Value == 1, "The second apply didn't restore the buffer!"); Assert.False(m_Manager.HasComponent <EmptyEcsTestData>(e), "The second apply didn't restore the component!"); }); // Cleanup m_Manager.DestroyEntity(m_Manager.UniversalQuery); }
/// <summary> /// Code to execute when the application is activated (brought to foreground) /// This code will not execute when the application is first launched /// </summary> private void ApplicationActivated(object sender, ActivatedEventArgs e) { RestorePersistentData(); var store = new PersistentDataStorage(); //ViewModelLocator.Restore(store); }
/// <summary> /// Code to execute when the application is deactivated (sent to background) /// This code will not execute when the application is closing /// </summary> private void ApplicationDeactivated(object sender, DeactivatedEventArgs e) { var store = new PersistentDataStorage(); //ViewModelLocator.Backup(store); BackupPersistentData(); }