unity
Jaina in Unity: a complete guide
Drop the Jaina C# SDK into Unity, fetch schemas at runtime, populate game objects from records.
The setup
Unity's netstandard2.0 profile is what Jaina.Client targets. Install in your project:
dotnet add package Jaina.Client
If you prefer dropping a DLL: download from NuGet, drop into Assets/Plugins/, set the .meta to Any Platform.
A minimal MonoBehaviour
using System.Threading.Tasks;
using UnityEngine;
using Jaina.Client;
public class JainaManager : MonoBehaviour
{
[SerializeField] private string projectSlug = "my-game";
private JainaClient client;
async void Start()
{
client = new JainaClient(apiKey: System.Environment.GetEnvironmentVariable("JAINA_API_KEY"));
var enemies = await client.Records.ListAsync<Enemy>(projectSlug, "enemy");
foreach (var e in enemies.Items)
{
SpawnEnemy(e);
}
}
private void SpawnEnemy(Enemy data)
{
var go = new GameObject(data.Name);
var enemy = go.AddComponent<EnemyBehaviour>();
enemy.Configure(data);
}
}
Where Enemy is the typed model generated from your schema:
jaina codegen my-game --lang csharp --output ./Assets/Scripts/Models/
Loading sprites
The sprite field on the schema is a file with accept: "image/*". On the C# side it shows up as a string URL. Use Unity's UnityWebRequest to fetch:
using UnityEngine.Networking;
private async Task<Texture2D> LoadSpriteAsync(string url)
{
using var req = UnityWebRequestTexture.GetTexture(url);
var op = req.SendWebRequest();
while (!op.isDone) await Task.Yield();
if (req.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Sprite load failed: {req.error}");
return null;
}
return DownloadHandlerTexture.GetContent(req);
}
Offline / build-time content
For Unity games that ship without network, use the CLI to export at build time:
jaina export my-game --format json --output ./Assets/StreamingAssets/
You'll get model.json files and assets/ per package. In Unity, read with StreamingAssetsLoader and parse with JsonUtility or the SDK's Package.FromJson(...).
What about updates?
Two patterns work:
- Periodic refresh — call
client.Packages.GetAsync(slug)on game start; cache inPlayerPrefsor local file. Players get content updates on next launch. - Webhook + push notification — your backend subscribes to Jaina webhooks (
record.created,record.updated) and pushes a "new content available" notification to the game client.
For most games, option 1 is enough.
Caveats
JainaClientisIDisposable. Wrap it appropriately or use a singleton.CancellationTokenis supported on every async method. Use it when scenes transition.- The C# SDK retries transient errors automatically. You don't need to wrap calls in try/catch unless you want to handle specific failure modes.
That's it. Five-minute integration, full type safety, no glue code.
