Example #1
0
        public void Save()
        {
            var serializer      = new WorldSerializer();
            var serializedWorld = serializer.Serialize(World.DefaultGameObjectInjectionWorld);

            var gameSaveData = new GameSaveData
            {
                SerializedWorld  = serializedWorld,
                SimulationTime   = _time,
                GameAreaSettings = _barrier.Settings,
                TimeStamp        = DateTime.Now.Ticks
            };

            var json = JsonUtility.ToJson(gameSaveData);

            _storage.Save(json);
        }
Example #2
0
        private static void RestoreWorld(string saveDataSerializedWorld)
        {
            var worldSerializer = new WorldSerializer();

            var loadedWorld = worldSerializer.DeserializeWorld(saveDataSerializedWorld);

            var manager = World.DefaultGameObjectInjectionWorld.EntityManager;

            var query = manager.CreateEntityQuery(new EntityQueryDesc
            {
                None = new[]
                {
                    EntitiesUtils.GetWorldTimeType()
                }
            });

            manager.DestroyEntity(query);
            manager.MoveEntitiesFrom(loadedWorld.EntityManager);

            loadedWorld.Dispose();
        }