This guide will help you quickly set up and use the MathsEngine in your Unity project.
Installation
- Open your Unity project.
- Open Window → Package Manager.
- Click the + button in the top-left corner.
- Select Add package from git URL.
- Enter:
https://github.com/arijeetbaruah/DataSmith.git?path=Packages/com.arijeet.DataSmith/DataSmith
Unity will download and install the package automatically.
How it works
Creating a Data Model
First create a new C# class and mark it with the GameModel attribute.
public class InventoryItem
{
[PrimaryKey]
public string Id;
public string Name;
public int Value;
}
Definition GameModel.cs:8
Definition DataSmithGenerator.cs:13
Key Points
- Models are plain C# classes
- No inheritance required
- Fields define stored data
- Attributes control behavior
Generate Model Code
Open the generator window:
Tools → Game Model Generator
Then Click Generate All
DataSmith will create:
These files appear in the configured output folder.
Initialize DataContext
Before using any models, initialize the system.
void Awake()
{
DataContext.Initialize();
}
This registers all generated models and prepares them for use.
Access your model through the DataContext:
var model = DataContext.Get<InventoryItemModel>();
model.Add(new InventoryItem
{
Id = "sword_01",
Name = "Iron Sword",
Value = 100
});
Query Data
If you are using ModelValueType.List then you can use the generated query system to filter data.
var expensiveItems =
DataContext.Get<InventoryItemModel>()
.Query()
.ValueGreaterThan(50)
.Execute();
Queries use a fluent builder pattern and execute only when enumerated.
Save and Load Data
Serialize all models:
string json = DataContext.SerializeAll();
Restore data later:
DataContext.DeserializeAll(json);
DataSmith uses Newtonsoft.Json for serialization.
See Also