Dras.biz Just another WordPress site

May 14, 2012

LoadContext Class

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

Namespace: SaveIt
C#:

using SaveIt;

JS:

import SaveIt;

static VFSLoadContext FromUnbufferedFile(string path, ResourceEntry[] resourceEntries = null)
Parameters:

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

Creates a new VFSLoadContext instance which reads from the given file specified through the path variable.

C#:

VFSLoadContext context = LoadContext.FromUnbufferedFile("SaveItData");
VFSLoadContext context = LoadContext.FromUnbufferedFile("SaveItData", myResourceEntries);

JS:

var context : VFSLoadContext = LoadContext.FromUnbufferedFile("SaveItData");
var context : VFSLoadContext = LoadContext.FromUnbufferedFile("SaveItData", myResourceEntries);

static LoadContext FromFile(string path, ResourceEntry[] resourceEntries = null)
Parameters:

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

Creates a new LoadContext instance which reads from the given file specified through the path variable.

C#:

LoadContext context = LoadContext.FromFile("SaveItData");
LoadContext context = LoadContext.FromFile("SaveItData", myResourceEntries);

JS:

var context : LoadContext = LoadContext.FromFile("SaveItData");
var context : LoadContext = LoadContext.FromFile("SaveItData", myResourceEntries);

static LoadContext FromPlayerPrefs(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 LoadContext instance which reads from the given playerprefs key specified through the name variable.

C#:

LoadContext context = LoadContext.FromPlayerPrefs("SaveItData");
LoadContext context = LoadContext.FromPlayerPrefs("SaveItData", myResourceEntries);

JS:

var context : LoadContext = LoadContext.FromPlayerPrefs("SaveItData");
var context : LoadContext = LoadContext.FromPlayerPrefs("SaveItData", myResourceEntries);

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

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

Creates a new LoadContext instance which reads from the given URL or WWW class.

C#:

LoadContext context = LoadContext.FromWeb("http://yourdomain/savegames/MySaveGame");
LoadContext context = LoadContext.FromWeb("http://yourdomain/savegames/MySaveGame", myResourceEntries);

JS:

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

static LoadContext FromStream(MemoryStream stream, ResourceEntry[] resourceEntries = null)
Parameters:

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

Creates a new LoadContext instance which reads from the given Stream.

C#:

LoadContext context = LoadContext.FromStream(memoryStream);
LoadContext context = LoadContext.FromStream(memoryStream, myResourceEntries);

JS:

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

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

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

Creates a new LoadContext instance. When no TableSerializer is provided a default one will be used, which loads from the file: “default.saveIt”.

C#:

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

JS:

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

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

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

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

C#:

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

JS:

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

bool IsDeferredType(Type type)
Parameters:

    type – the Type to test for

Returns:

    true when the object is a deferred type, false otherwise

Returns wether the given type is a type which needs to be loaded with special means, for example all Components are deferred types. these types need
to be loaded with the Load methods who are providing a callbackMethod or with the WaitForLoad methods.
In most cases you know that without using this method.

C#:

if (context.IsDeferredType(typeof(Foo)))
{
	context.WaitForLoad<Foo>("myFooValue", loadedFoo => myFooValue = loadedFoo);
}
else
{
	myFooValue = context.Load<Foo>("myFooValue");
}

JS:

if (context.IsDeferredType(Foo))
{
	context.WaitForLoad.<Foo>("myFooValue", function (loadedFoo) { myFooValue = loadedFoo; });
}
else
{
	myFooValue = context.Load.<Foo>("myFooValue");
}

bool IsDeferredValue(string name)
Parameters:

    name – the name of the value in the currrently deserializing object to test for

Returns:

    true when the value is a deferred type, false otherwise

Returns wether the value stored at the given name in the currently serializing object is a type which needs to be loaded with special means, for example all Components are deferred types. these types need
to be loaded with the Load methods who are providing a callbackMethod or with the WaitForLoad methods.
In most cases you know that without using this method.

C#:

if (context.IsDeferredValue("myFooValue"))
{
	context.WaitForLoad<Foo>("myFooValue", loadedFoo => myFooValue = loadedFoo);
}
else
{
	myFooValue = context.Load<Foo>("myFooValue");
}

JS:

if (context.IsDeferredValue("myFooValue"))
{
	context.WaitForLoad.<Foo>("myFooValue", function (loadedFoo) { myFooValue = loadedFoo; });
}
else
{
	myFooValue = context.Load.<Foo>("myFooValue");
}

void Load(Action<object> onLoaded)
void Load<T>(Action<T> onLoaded)
Parameters:

    onLoaded – a callBack to call when the value has been loaded

This loads the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” and calls the callBack onLoaded when finished.
This method is usefull when loading values you know not if these types are deferred or not and you didnt provide any name when you stored it with the SaveContext.

C#:

context.Load(loadedObject =>
{
	myComponent = (MyComponent)loadedObject;
});
context.Load<MyComponent>(loadedComponent =>
{
	myComponent = loadedComponent;
});

JS:

context.Load(function (loadedObject)
{
	myComponent = (MyComponent)loadedObject;
});
context.Load.<MyComponent>(function (loadedComponent)
{
	myComponent = loadedComponent;
});

Load(string name, Action<object> onLoaded)
Load<T>(string name, Action<T> onLoaded)
Parameters:

    name – the name of the value to load
    onLoaded – a callBack to call when the value has been loaded

This loads value stored at the given name and calls the callBack onLoaded when finished.
This method is usefull when loading values you know not if these types are deferred or not.

C#:

context.Load("healthPoints", loadedValue =>
{
	healthPoints = (int)loadedValue;
});
context.Load<int>("healthPoints", loadedInteger =>
{
	healthPoints = loadedInteger;
});

JS:

context.Load("healthPoints", function (loadedValue)
{
	healthPoints = (int)loadedValue;
});
context.Load.<int>("healthPoints", function (loadedInteger)
{
	healthPoints = loadedInteger;
});

object Load()
T Load()
Parameters:

    none

Returns:

    the loaded value

This loads the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” and returns the loaded result.

C#:

int healtPoints = (int)context.Load();
int healtPoints = context.Load<int>();

JS:

var healtPoints : int = (int)context.Load();
var healtPoints : int = context.Load.<int>();

object Load(string name)
T Load(string name)
Parameters:

    name – the name of the value to load

Returns:

    the loaded value

This loads value stored at the given name and returns the loaded result.

C#:

int healtPoints = (int)context.Load("healthPoints");
int healtPoints = context.Load<int>("healthPoints");

JS:

var healtPoints : int = (int)context.Load("healthPoints");
var healtPoints : int = context.Load.<int>("healthPoints");

void Load(out T target)
Parameters:

    target – the target to which the loaded value should be assigned to

This loads the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” and puts the result into the given target.

C#:

int healtPoints;
context.Load(out healthPoints);

void Load(string name, out T target)
Parameters:

    name – the name of the value to load
    target – the target to which the loaded value should be assigned to

This loads value stored at the given name and puts the result into the given target.

C#:

int healtPoints;
context.Load("healthPoints", out healthPoints);

void WaitForLoad(string name, Action<object> onLoaded)
void WaitForLoad(string name, Action< T > onLoaded)
Parameters:

    name – the name of the value to wait for
    onLoaded – a callBack to call when the value has been loaded

This waits unto the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” has been loaded and calls the callBack onLoaded when finished.
This method is usefull when somwhere else is a Load call and you only want to know when this call has been finished. You want to use it for all deferred types which cant be constructed with a normal new call.

C#:

context.WaitForLoad("someComponent", loadedObject =>
{
	myComponent = (MyComponent)loadedObject;
});
context.WaitForLoad<MyComponent>("someComponent", myBehaviour =>
{
	myComponent = myBehaviour;
});

JS:

context.WaitForLoad("someComponent", function(loadedObject)
{
	myComponent = (MyComponent)loadedObject;
});
context.WaitForLoad.<MyComponent>("someComponent", function(myBehaviour)
{
	myComponent = myBehaviour;
});

object LoadToInstance(object instance)
T LoadToInstance(T instance)
Parameters:

    instance – the target instance to load the data to

Returns:

    the instance provided in the parameters

This loads the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” into the given instance. Use this when you already created an instance and want it to be filled with stored data. This is usefull when loading componants, as these are not creatable without using a GameObject.

C#:

context.LoadToInstance(gameObject.transform);

JS:

context.LoadToInstance(gameObject.transform);

object LoadToInstance(string name, object instance)
T LoadToInstance(string name, T instance)
Parameters:

    name – the name of the value to load
    instance – the target instance to load the data to

Returns:

    the instance provided in the parameters

This loads the value with the given name into the given instance. Use this when you already created an instance and want it to be filled with stored data. This is usefull when loading componants, as these are not creatable without using a GameObject.

C#:

context.LoadToInstance("myTransform", gameObject.transform);

JS:

context.LoadToInstance("myTransform", gameObject.transform);

T LoadComponent(string name, GameObject gameObject)
T LoadComponent(UnityEngine.GameObject gameObject)
Component LoadComponent(GameObject gameObject, Type componentType)
Component LoadComponent(string name, GameObject gameObject, Type componentType)
Parameters:

    name – the name to load the component from
    gameObject – the GameObject to which the component to load will be attached
    Type – the type of the component to load

Returns:

    the loaded component

This loads a component for the given name (when no name is provided the next available slot with the generated name: “Slot.” + nextSlotIndex + “]” will be used), for the given gameObject.

C#:

context.LoadComponent<Transform>(gameObject);
context.LoadComponent<Transform>("myTransform", gameObject);
context.LoadComponent(gameObject, typeof(Transform));
context.LoadComponent("myTransform", gameObject, typeof(Transform));

JS:

context.LoadComponent.<Transform>(gameObject);
context.LoadComponent.<Transform>("myTransform", gameObject);
context.LoadComponent(gameObject, Transform);
context.LoadComponent("myTransform", gameObject, Transform);

bool Exists(string name)
Parameters:

    name – the name of the value to check for existance

Returns:

    true when the value with the given name exists and false otherwise

This method will check wether a value with the given name exists.

C#:

if (context.Exists("MagicNumber"))
{
	int magicNumber = context.Load("MagicNumber");
}

JS:

if (context.Exists("MagicNumber"))
{
	var magicNumber : int = context.Load("MagicNumber");
}

bool MemberExists(string memberName)
Parameters:

    memberName- the memberName of the value to check for existance

Returns:

    true when the value with the given memberName exists and false otherwise

This method will check wether a value with the given memberName exists.

C#:

if (context.MemberExists("mainTexture"))
{
	context.LoadMember("mainTexture");
}

JS:

if (context.MemberExists("mainTexture"))
{
	context.LoadMember("mainTexture");
}

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress