Dras.biz Just another WordPress site

May 14, 2012

SaveContext Class

Filed under: SaveIt,SaveIT API Reference — mark @ 08:07

Namespace: SaveIt
C#:

using SaveIt;

JS:

import SaveIt;

static VFSSaveContext ToUnbufferedFile(string path, ResourceEntry[] resourceEntries = null)
Parameters:

    path – the filepath to write to
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new VFSSaveContext instance which writes to the given file specified through the path variable.

C#:

VFSSaveContext context = SaveContext.ToUnbufferedFile("SaveItData");
VFSSaveContext context = SaveContext.ToUnbufferedFile("SaveItData", myResourceEntries);

JS:

var context : VFSSaveContext = SaveContext.ToUnbufferedFile("SaveItData");
var context : VFSSaveContext = SaveContext.ToUnbufferedFile("SaveItData", myResourceEntries);

static SaveContext ToFile(string path, ResourceEntry[] resourceEntries = null)
Parameters:

    path – the filepath to write to
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance which writes to the given file specified through the path variable.

C#:

SaveContextcontext = SaveContext.ToFile("SaveItData");
SaveContextcontext = SaveContext.ToFile("SaveItData", myResourceEntries);

JS:

var context : SaveContext = SaveContext.ToFile("SaveItData");
var context : SaveContext = SaveContext.ToFile("SaveItData", myResourceEntries);

static SaveContext ToPlayerPrefs(string name, ResourceEntry[] resourceEntries = null)
Parameters:

    name- the playerprefs entry name
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance which writes to the given playerprefs key specified through the name variable.

C#:

SaveContext context = SaveContext.ToPlayerPrefs("SaveItData");
SaveContext context = SaveContext.ToPlayerPrefs("SaveItData", myResourceEntries);

JS:

var context : SaveContext = SaveContext.ToPlayerPrefs("SaveItData");
var context : SaveContext = SaveContext.ToPlayerPrefs("SaveItData", myResourceEntries);

static SaveContext ToWeb(string url, ResourceEntry[] resourceEntries = null)
static SaveContext ToWeb(WWW www, ResourceEntry[] resourceEntries = null)
Parameters:

    url- the URL to the saved file data
    www- the WWW class to use for saving the data
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance which writes to the given URL or WWW class.

C#:

SaveContext context = SaveContext.ToWeb("http://yourdomain/savegames/MySaveGame");
SaveContext context = SaveContext.ToWeb("http://yourdomain/savegames/MySaveGame", myResourceEntries);

JS:

var context : SaveContext = SaveContext.ToWeb("http://yourdomain/savegames/MySaveGame");
var context : SaveContext = SaveContext.ToWeb("http://yourdomain/savegames/MySaveGame", myResourceEntries);

static SaveContext ToStream(MemoryStream stream, ResourceEntry[] resourceEntries = null)
Parameters:

    stream- the Stream to write to
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance which writes to the given Stream.

C#:

SaveContext context = SaveContext.ToStream(memoryStream);
SaveContext context = SaveContext.ToStream(memoryStream, myResourceEntries);

JS:

var context : SaveContext = LoadContext.ToStream(memoryStream);
var context : SaveContext = LoadContext.ToStream(memoryStream, myResourceEntries);

SaveContext(ITableSerializer tableSerializer = null, ResourceEntry[] resourceEntries = null)
Parameters:

    tableSerializer [optional] – the TableSerializer which loads and saves from/to a stream
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance. When no TableSerializer is provided a default one will be used, which saves to the file: “default.saveIt”.

C#:

1
SaveContext context = new SaveContext();
1
SaveContext context = new SaveContext(new TableSerializer.File("SaveItData"));
1
SaveContext context = new SaveContext(new TableSerializer.File("SaveItData"), myResourceEntries);

JS:

1
var context : SaveContext = SaveContext();
1
var context : SaveContext = SaveContext(TableSerializer.File("SaveItData"));
1
var context : SaveContext = SaveContext(TableSerializer.File("SaveItData"), myResourceEntries);

SaveContext(string dataName, ResourceEntry[] resourceEntries = null)
Parameters:

    dataName[optional] – the dataName to save to
    resourceEntries [optional] – array of precreated resources to use instead to create it on demand

Creates a new SaveContext instance. The given dataName will be used to specify the filename, playerprefs key or web request URL used to save the data to

C#:

SaveContext context = new SaveContext ("MySaveGame");
SaveContext context = new SaveContext ("http://yourdomain/savegames/MySaveGame");

JS:

var context : SaveContext = SaveContext ("MySaveGame");
var context : SaveContext = SaveContext ("http://yourdomain/savegames/MySaveGame");

void SaveMember(string memberName, string name = null)
Parameters:

    memberName- the name of the member of the current serializing object
    name [optional]- the name to store the member

Stores the value of the given member memberName of the currently serializing object at the given name, when no name is provided
a name will be generated: “[member:" + memberName + "]“.
You can only use this method when serializing an object (Custom serializer or Load/Save methods inside the objects class layout).

C#:

1
context.SaveMember("localPosition");
1
context.SaveMember("localPosition", "myPosition");

JS:

1
context.SaveMember("localPosition");
1
context.SaveMember("localPosition", "myPosition");

void Save(T what, string name = null)
Parameters:

    what – the object to save
    name [optional] – the name to store the value what

Stores the given object what with with the given name. When no name is given a name is generated: “[Slot." + currentSlot + "]”
This enables the ability to write Save and Load calls which mirrors themself without worrying about the names.

C#:

1
2
3
context.Save(name); // Name is: [Slot.0]
context.Save(active, "isActive"); // Name is: isActive
context.Save(healthPoints); // Name is: [Slot.1]

JS:

1
2
3
context.Save(name); // Name is: [Slot.0]
context.Save(active, "isActive"); // Name is: isActive
context.Save(healthPoints); // Name is: [Slot.1]

void Flush()
Parameters:

    none

Saves all stored objects to the TableSerializer (for example to a File).
You must call this after you stored all your objects!

C#:

1
2
3
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");
context.Flush();

JS:

1
2
3
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");
context.Flush();

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress