Ejemplo n.º 1
0
 public void Save(PersistableObject o, int version)
 {
     using (BinaryWriter writer = new BinaryWriter(File.Open(savePath, FileMode.Create)))
     {
         writer.Write(-version);
         o.Save(new GameDataWriter(writer));
     }
 }
 public void Save(PersistableObject o)
 {
     using (
         var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
         ) {
         o.Save(new GameDataWriter(writer));
     }
 }
 public void Save(PersistableObject o, int version)
 {
     using (
         var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
         ) {
         writer.Write(-version);              // do no confuse count (from a previous save) and version -> save version as negative.
         o.Save(new GameDataWriter(writer));
     }
 }
 public void Save(PersistableObject obj)
 {
     // The using (something) {} format will dispose of the something after the code block even if an exception occurs
     // Basically it's shorthand for a try catch block, only works with IDisposable types
     using (var writer = new BinaryWriter(File.Open(_savePath, FileMode.Create)))
     {
         obj.Save(new GameDataWriter(writer));
     }
 }
Ejemplo n.º 5
0
 public void Save(PersistableObject obj, int version)
 {
     using (var writer = new BinaryWriter
                             (System.IO.File.Open(_savePath, FileMode.Create)))
     {
         writer.Write(-version);
         obj.Save(new GameDataWriter(writer));
     }
 }
Ejemplo n.º 6
0
 public void Save(PersistableObject o)
 {
     using (  //automatically handle exception of closing file
         BinaryWriter writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
         )
     {
         o.Save(new GameDataWriter(writer));
     }
 }
Ejemplo n.º 7
0
    public void Save(PersistableObject o)
    {
        Debug.Log("Saving file: " + this.savePath);

        using (
            var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
            ) {
            o.Save(new GameDataWriter(writer));
        }
    }
 public void Save(PersistableObject o, int version)
 {
     //使用using关键字将变量writer限制仅在using的代码块内可用。
     //这确保在代码执行退出该块后,无论如何都将正确处理所有writer引用。
     using (var writer = new BinaryWriter(File.Open(savePath, FileMode.Create)))
     {
         writer.Write(-version);
         o.Save(new GameDataWrite(writer));
     }
 }
Ejemplo n.º 9
0
 public void Save(PersistableObject o, int version)
 {
     using (BinaryWriter writer = new BinaryWriter(File.Open(savePath, FileMode.Create)))
     {
         //Переворачиваем и записываем версию
         //для проверки на совместимость(в скрипте Game проверяем это)
         writer.Write(-version);
         o.Save(new GameDataWriter(writer));
     }
 }
 //Will be used to store the gamestate in a file at the in awake created path
 public void Save(PersistableObject persistableObject, int version)
 {
     //using used from catlikecoding instead of try and catch so there is always a writer available
     using (var writer = new BinaryWriter(File.Open(savePath, FileMode.Create)))
     {
         //write the input verion to the memory negated
         writer.Write(-version);
         //and save the input persiatable object using a new GameDataWriter with the "using" writer
         persistableObject.Save(new GameDataWriter(writer));
     }
 }
Ejemplo n.º 11
0
    public void Save(PersistableObject obj, int version)
    {
        using (
            var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
            )
        {
            writer.Write(-version);
            obj.Save(new GameDataWriter(writer));
        }

        Debug.Log("Saved!");
    }
Ejemplo n.º 12
0
 public void Save(PersistableObject o, int version)
 {
     using (
         var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
         ) {
         /**
          *  这种直接创建的 会有警告 因为这里没有被实例化到一个物体上
          */
         writer.Write(-version);
         o.Save(new GameDataWriter(writer));
         // o.Save(new GameObject().AddComponent<GameDataWriter>().Init(writer));
     }
 }
    private IEnumerator SaveInternal(PersistableObject o, int version, bool singleFrameSave = false)
    {
        using (var writer = new BinaryWriter(File.Open(savePath, FileMode.Create)))
        {
            //! Writing the save file version
            writer.Write(-version);
            o.Save(new DataWriter(writer), singleFrameSave);

            while (o.IsBusy)
            {
                yield return(null);
            }
        }
    }
Ejemplo n.º 14
0
    public void Save(PersistableObject po)
    {
        var writer = new BinaryWriter(File.Open(savePath, FileMode.Create));

        po.Save(new DataWriter(writer));
    }