Search Unity

SaveIt - Easy to use but very mighty save&load API [Free/Paid]

Discussion in 'Assets and Asset Store' started by Marrrk, Jul 13, 2012.

  1. Marrrk

    Marrrk

    Joined:
    Mar 21, 2011
    Posts:
    1,032
    SaveIt
    $Fotolia_42293827_S.jpg

    SaveIt is an asset to load and save your data. Imagine savegames. I provide with SaveIt an easy to understand API, just say what you want to do and SaveIt will do it.

    SaveIt Basic
    SaveIt Pro
    Documentation

    Key features:
    1. loads/saves primitive types (int, string, float, bool, eg.)

    Code (csharp):
    1.  
    2. bool myBool;
    3. int myInt;
    4. ...
    5. saveContext.Save(myInt);
    6. saveContext.Save(myBool);
    7. ...
    8. myInt = loadContext.Load<int>();
    9. myBool = loadContext.Load<bool>();
    10.  
    2. loads/saves single, multi dimensional and jagged arrays
    Code (csharp):
    1.  
    2. int[][] myJaggedArray;
    3. int[] myArray;
    4. int[][,,] myComplexArray;
    5. ...
    6. saveContext.Save(myJaggedArray);
    7. saveContext.Save(myArray);
    8. saveContext.Save(myComplexArray);
    9. ...
    10. myJaggedArray = loadContext.Load<int[][]>();
    11. myArray = loadContext.Load<int[]>();
    12. myComplexArray = loadContext.Load<int[][,,]>();
    13.  
    3. loads/saves IEnumerable inheriting classes (Lists for example)
    Code (csharp):
    1.  
    2. List<int> myList;
    3. ...
    4. saveContext.Save(myList);
    5. ...
    6. myList = loadContext.Load<List<int>>();
    7.  
    4. loads/saves KeyValuePairs
    Code (csharp):
    1.  
    2. KeyValuePair<string, int> myPair;
    3. ...
    4. saveContext.Save(myPair);
    5. ...
    6. myPair = loadContext.Load<KeyValuePair<string, int>>();
    7.  
    5. loads/saves UnityEngine.Object instances
    Code (csharp):
    1.  
    2. Material myMaterial;
    3. ...
    4. saveContext.Save(myMaterial);
    5. ...
    6. myMaterial = loadContext.Load<Material>();
    7.  
    6. loads/saves GameObjects
    Code (csharp):
    1.  
    2. GameObject myGameObject;
    3. ...
    4. saveContext.Save(myGameObject);
    5. ...
    6. myGameObject = loadContext.Load<GameObject>();
    7.  
    7. loads/saves most Unity Components
    Code (csharp):
    1.  
    2. GameObject myGameObject;
    3. ...
    4. saveContext.Save(myGameObject.transform);
    5. ...
    6. loadContext.LoadComponent<Transform>(myGameObject);
    7.  
    8. loads/saves most custom Components

    Code (csharp):
    1.  
    2. GameObject myGameObject;
    3. ...
    4. saveContext.Save(myGameObject.GetComponent<MyHealthScript>());
    5. ...
    6. loadContext.LoadComponent<MyHealthScript>(myGameObject);
    7.  
    9. uses reference sharing (an instance is only stored one time and loaded one time, even when referenced multiple times)
    Code (csharp):
    1.  
    2. GameObject myGameObject;
    3. ...
    4. GameObject myGameObject1 = myGameObject;
    5. GameObject myGameObject2 = myGameObject;
    6. ...
    7. saveContext.Save(myGameObject1, "FirstGameObject");
    8. saveContext.Save(myGameObject2, "SecondGameObject");
    9. ...
    10. myGameObject1 = loadContext.Load<GameObject>("FirstGameObject");
    11. myGameObject2 = loadContext.Load<GameObject>("SecondGameObject");
    12.  
    13. var areBothEqual = myGameObject1 == myGameObject2; // returns true
    14.  
    10. allows loading and saving of a whole scene
    Code (csharp):
    1.  
    2. Scene.ToFile("mySaveGame.dat"); // saves the current scene
    3. ...
    4. Scene.FromFile("mySaveGame.dat"); // loads the scene
    5.  
    11. memory preserving mechanics (when its already in the scene when loaded you do not need to save it again)
    Code (csharp):
    1.  
    2. No sample available, SaveIt will manage this automatically
    3.  
    12. load/save assistance (to reduce the amount of data needed to save)
    Code (csharp):
    1.  
    2. No sample available, SaveIt will manage this automatically
    3.  
    13. save/load data by name into and from a single file
    Code (csharp):
    1.  
    2. int myInt;
    3. bool myBool;
    4. int myOtherInt;
    5. ...
    6. saveContext.Save(myInt, "HealthPoints");
    7. saveContext.Save(myOtherInt, "Score");
    8. saveContext.Save(myBool, "HasRedKey");
    9. ...
    10. myOtherInt = loadContext.Load<int>("Score");
    11. myBool = loadContext.Load<bool>("HasRedKey");
    12. myInt = loadContext.Load<int>("HealthPoints");
    13.  
    14. JavaScript and C# support (Boo should work too, but its not documented)
    Code (csharp):
    1.  
    2. No sample available
    3.  
    15. batched save data to file
    Code (csharp):
    1.  
    2. int myInt;
    3. bool myBool;
    4. int myOtherInt;
    5. ...
    6. SaveContext saveContext = SaveContext.ToFile("MySaveGame.dat")
    7. saveContext.Save(myInt, "HealthPoints");
    8. saveContext.Save(myOtherInt, "Score");
    9. saveContext.Save(myBool, "HasRedKey");
    10. saveContext.Flush();
    11.  
    16. customized serialization
    17. unbatched save data to file without the need to completely rewrite the entire file (Pro feature)
    Code (csharp):
    1.  
    2. int myInt;
    3. bool myBool;
    4. int myOtherInt;
    5. ...
    6. VFSSaveContext saveContext = SaveContext.ToUnbufferedFile("MySaveGame.dat")
    7. saveContext.Save(myInt, "HealthPoints");
    8. saveContext.Save(myOtherInt, "Score");
    9. saveContext.Save(myBool, "HasRedKey");
    10.  
    18. allows data compression (Pro feature)
    Code (csharp):
    1.  
    2. int myInt;
    3. bool myBool;
    4. int myOtherInt;
    5. ...
    6. SaveContext saveContext = SaveContext.ToFile("MySaveGame.dat")
    7. saveContext.TableSerializer.UseCompression = true;
    8. saveContext.Save(myInt, "HealthPoints");
    9. saveContext.Save(myOtherInt, "Score");
    10. saveContext.Save(myBool, "HasRedKey");
    11. saveContext.Flush();
    12.  
    19. data encryption by password (Pro feature)
    Code (csharp):
    1.  
    2. int myInt;
    3. bool myBool;
    4. int myOtherInt;
    5. ...
    6. SaveContext saveContext = SaveContext.ToFile("MySaveGame.dat")
    7. saveContext.TableSerializer.Password = "Banana";
    8. saveContext.Save(myInt, "HealthPoints");
    9. saveContext.Save(myOtherInt, "Score");
    10. saveContext.Save(myBool, "HasRedKey");
    11. saveContext.Flush();
    12. ...
    13. LoadContext loadContext = LoadContext.FromFile("MySaveGame.dat")
    14. loadContext.TableSerializer.Password = "Banana";
    15. myOtherInt = loadContext.Load<int>("Score");
    16. myBool = loadContext.Load<bool>("HasRedKey");
    17. myInt = loadContext.Load<int>("HealthPoints");
    18.  
    and more

    Usage example (C#):

    Save data:
    Code (csharp):
    1.  
    2. using SaveIt;
    3. ...
    4. int myNumber = 42;
    5. float myFloat = 3.141f;
    6. string name = "Victoria";
    7. MyCustomClass customClass = new MyCustomClass();
    8. ...
    9. // Create the save context, the object which handles saving data.
    10. var context = new SaveContext("SaveGame01");
    11. // Save the numbers without a name
    12. context.Save(myNumber);
    13. // save the float with a name
    14. context.Save(myFloat, "PI");
    15. // Save the string with a name too
    16. context.Save(name, "PlayerName");
    17. // Save our custom class without a name
    18. context.Save(customClass);
    19. // Finalize the save process, this creates the file or playerprefs
    20. // from the data we want to save.
    21. context.Flush();
    22.  
    Load data:
    Code (csharp):
    1.  
    2. using SaveIt;
    3. ...
    4. // Create the load context, the object which handles loading data.
    5. var context = new LoadContext("SaveGame01");
    6. // Loads the saved number without using a name
    7. var myNumber = context.Load<int>();
    8. // Loads the float with the name "PI"
    9. var myFloat = context.Load<float>("PI");
    10. // Loads the "PlayerName" string
    11. var name = context.Load<string>("PlayerName");
    12. // Loads the nameless custom class
    13. var customClass = context.Load<MyCustomClass>();
    14.  
    Usage example (JavaScript):

    Save data:
    Code (csharp):
    1.  
    2. import SaveIt;
    3. ...
    4. var myNumber : int = 42;
    5. var myFloat : float = 3.141f;
    6. var name : String = "Victoria";
    7. var customClass : MyCustomClass = MyCustomClass();
    8. ...
    9. // Create the save context, the object which handles saving data.
    10. var context : SaveContext = SaveContext("SaveGame01");
    11. // Save the numbers without a name
    12. context.Save(myNumber);
    13. // save the float with a name
    14. context.Save(myFloat, "PI");
    15. // Save the string with a name too
    16. context.Save(name, "PlayerName");
    17. // Save our custom class without a name
    18. context.Save(customClass);
    19. // Finalize the save process, this creates the file or playerprefs
    20. // from the data we want to save.
    21. context.Flush();
    22.  
    Load data:
    Code (csharp):
    1.  
    2. import SaveIt;
    3. ...
    4. // Create the load context, the object which handles loading data.
    5. var context : LoadContext = new LoadContext("SaveGame01");
    6. // Loads the saved number without using a name
    7. var myNumber : int= context.Load.<int>();
    8. // Loads the float with the name "PI"
    9. var myFloat : float = context.Load.<float>("PI");
    10. // Loads the "PlayerName" string
    11. var name : String = context.Load.<string>("PlayerName");
    12. // Loads the nameless custom class
    13. var customClass : MyCustomClass = context.Load.<MyCustomClass>();
    14.  
    Saving the whole scene:

    Well, whole scene is a little bit far fetched, you need to activate the save/load assistent from SaveIt, you can use by activating the fitting menu entry in the UnityEditor. After that you can mark the GameObjects you want to be able to keep track of with the Saveable Component. All objects without the Saveable component will not be saved, but will be recreated when loading the scene.

    Sample (C#):

    Code (csharp):
    1.  
    2. using SaveIt;
    3. ...
    4. public void SaveScene(string saveName)
    5. {
    6.     var context = new SaveContext(saveName);
    7.     Scene.Save(context);
    8.     context.Flush();
    9. }
    10.  
    11. public void LoadScene(string saveName)
    12. {
    13.     var context = new LoadContext(saveName);
    14.     Scene.Load(context);
    15. }
    16.  
    Sample (JavaScript):

    Code (csharp):
    1.  
    2. import SaveIt;
    3. ...
    4. function SaveScene(saveName : String)
    5. {
    6.     var context : SaveContext = SaveContext(saveName);
    7.     Scene.Save(context);
    8.     context.Flush();
    9. }
    10.  
    11. function LoadScene(saveName : String)
    12. {
    13.     var context : LoadContext = LoadContext(saveName);
    14.     Scene.Load(context);
    15. }
    16.  
    SaveIt Basic
    SaveIt Pro
    Documentation
     
    Last edited: Jul 13, 2012
  2. LucasDaltro

    LucasDaltro

    Joined:
    Oct 31, 2010
    Posts:
    236
    Cool!:D
    Does it works on ios?
     
  3. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    .
     
  4. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    ya does it work on iOS?

    has anyone used this ? How is it?
     
  5. 10yaseen1

    10yaseen1

    Joined:
    Oct 27, 2012
    Posts:
    14
    Hello Guys! well I liked the save it too much, everything
    worked fine but when I tried to save one of my rigged character and

    all of his components and loaded then it just made a black screen

    and deleted and detached many of my players child objects

    any one can tell that how to solve that!
     
  6. Javier-Cabrera

    Javier-Cabrera

    Joined:
    Sep 30, 2013
    Posts:
    15
    Something's not working on the free version examples. When I try the ExampleScene2 it gives me the following error when clicking any ball.

    SaveItInvalidOperationException: Not supported in this version.
    SaveIt.SaveContext.ToUnbufferedFile (System.String path)
    SaveSpherePoints.OnMouseDown () (at Assets/SaveIt/Examples/Unbatched saving and loading/SaveSpherePoints.cs:56)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

    This is the line:

    var saveContext = SaveContext.ToUnbufferedFile(FileName);
     
  7. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Sounds very cool by description. Will try it asap :)

    Thanks a bunch
     
  8. Rutger

    Rutger

    Joined:
    Sep 17, 2013
    Posts:
    34
    In my code but also in ExampleScene2 I get an error when loading before there is a savefile. (shift clicking a red ball in scene2):
    Code (csharp):
    1.  
    2. InvalidOperationException: Operation is not valid due to the current state of the object
    3. System.Linq.Enumerable.First[FileTableEntry] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback)
    4. System.Linq.Enumerable.First[FileTableEntry] (IEnumerable`1 source, System.Func`2 predicate)
    5. SaveIt.SingleFileVFS.SingleFileVFS.Read (System.String identifier)
    6. SaveIt.SingleFileVFS.VFSTableSerializer.LoadFromVFS (Int32 id)
    7. SaveIt.SingleFileVFS.VFSTableSerializer.Deserialize ()
    8. SaveIt.LoadContext..ctor (ITableSerializer tableSerializer, SaveIt.ResourceEntry[] resourceEntries)
    9. SaveIt.SingleFileVFS.VFSLoadContext..ctor (System.String fileName, SaveIt.ResourceEntry[] resourceEntries)
    10. SaveIt.LoadContext.FromUnbufferedFile (System.String path)
    11.  
    Is this a bug or is there a way of checking for the existance of a savefile? I.E. am I missing something?
    Or is this something I need to write myself (try/catch or litterally check for the files existance)?

    Also are you planning on updating the documentation? It seems deprecated in places (TableSerializer comes to mind).
    Releasing the source code would help a lot as well (if only for people like me who bought the Pro version).

    Thanks in advance for a quick response.
     
  9. Kald

    Kald

    Joined:
    Apr 20, 2013
    Posts:
    16
    Is it possible to save the file to web server using WWWForm using EasyIt basic?
     
  10. samusam

    samusam

    Joined:
    Mar 29, 2014
    Posts:
    48
    Hi, the system save the objects istantiate?