Data Model

Definition

1
public class DataModel<T>: DataModel
Copied!
1
public class DataModel : ScriptableObject
Copied!
It is intended that you use this to create your core save files as Scriptable Objects. This makes it trival to query the Steam Remote Storage interface for records of this file type and to load data into a usable point in memory that can easily be referenced by Unity components.
You would typically start by defaining your underlying data type e.g. a serializable object that represents the data you wish to save
1
[Serializable]
2
public class MyCharacterData
3
{
4
public string characterName;
5
public int level;
6
public float3 position;
7
public quaternion rotation;
8
//... etc.
9
}
Copied!
You would then create your DataModel
1
[CreateAssetMenu(menuName = "My Objects/Character Data Model")]
2
public class CharacterDataModel : DataModel<MyCharacterData>
3
{ }
Copied!
You do not need to write any code in the body of the DataModel, the base class will implament everything you need for you.
Once complete you can use your new ScriptableObject to represent the currently loaded copy of this data type and you can use its member funcitons to list the available files of this type as seen on Steam Remote Storage and to read and write given files.

Fields and Attributes

Type
Name
Comment
string
extension
The extension to be used with this model
RemoteStorageFile[]
availableFiles
List of available files found on Steam Remote Storage
Type
DataType
The underlying data type used by this model
T
data
The data stored by this model

Methods

Refresh

1
public void Refresh();
Copied!
Reads the list of available files from the remote storage interface and stores them in the availabelFiles collection

Load Data

1
public void LoadByteArray(data);
Copied!
1
public void LoadJson(data);
Copied!
1
public void LoadFileAddress(address);
Copied!
Manually loads data into the model's data field

Export Data

1
public byte[] ToByteArray();
Copied!
Outputs the current data as a byte[]
1
public string ToJson();
Copied!
Outputs the current data as a JSON string

Save Data

1
public void Save(fileName);
Copied!
Saves the current data to the Steam Remote Storage system with the indicated file name
Last modified 5mo ago