Exemplo n.º 1
0
        private void Save(SaveInformation info, WorldManager world)
        {
            info.UpdateProgress(SaveState.SavingWorld, 0.0f);

            var direction = Player.Instance.Mover.MovementDirection;
            var position  = Player.Instance.Mover.CurrentGridPosition;
            var layer     = Player.Instance.Mover.MovementLayer;

            var data = new SaveData();

            data.Game.MainScene             = world.gameObject.scene.path;
            data.Game.StartingZone          = Player.Instance.Zone.Zone.name;
            data.Game.PlayerSpawn.Direction = direction;
            data.Game.PlayerSpawn.Position  = position;
            data.Game.PlayerSpawn.Layer     = layer;

            Player.Instance.Save(data.Player);

            var filename = world.Save(data.World);

            info.UpdateProgress(SaveState.WritingData, 0.2f);
            Write(info, data, filename);

            if (info.State != SaveState.Error)
            {
                info.SetComplete();
            }
        }
Exemplo n.º 2
0
        public static SaveInformation Save(WorldManager world)
        {
            var info = new SaveInformation();

            Instance.Save(info, world);
            return(info);
        }
Exemplo n.º 3
0
 private static void Write(SaveInformation info, SaveData data, string filename)
 {
     try
     {
         var json = JsonUtility.ToJson(data, true);
         File.WriteAllText(filename, json);
     }
     catch (Exception e)
     {
         info.SetError(string.Format(_invalidSaveError, filename, e.Message));
     }
 }