Unity integration

Drop the Jaina C# SDK into Unity. Fetch schemas, populate game objects.

Install

Heads up: Jaina.Client is publishing soon and is not yet on NuGet. Until it ships, use the REST API directly. The steps below are correct for when the package is live.

dotnet add package Jaina.Client

Or drop the DLL into Assets/Plugins/.

Generate models

jaina codegen my-game --lang csharp --output ./Assets/Scripts/Models/

You'll get one .cs file per schema.

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);
        }
    }

    void OnDestroy()
    {
        client?.Dispose();
    }

    private void SpawnEnemy(Record<Enemy> r)
    {
        var go = new GameObject(r.Data.Name);
        var enemy = go.AddComponent<EnemyBehaviour>();
        enemy.Configure(r.Data);
    }
}

Loading sprites

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) return null;
    return DownloadHandlerTexture.GetContent(req);
}

Build-time export (offline games)

jaina export my-game --format json --output ./Assets/StreamingAssets/

Read in Unity:

var path = System.IO.Path.Combine(Application.streamingAssetsPath, "my-game/level-1/model.json");
var json = System.IO.File.ReadAllText(path);
var package = Jaina.Client.Package.FromJson(json);

Update strategies

  • Periodic refresh — fetch on game start, cache in PlayerPrefs. Updates apply on next launch.
  • Webhook + push notification — backend listens for Jaina webhooks and pushes a "new content" notification to the game client.

Caveats

  • JainaClient is IDisposable. Dispose in OnDestroy.
  • WebGL builds: CORS applies — configure your Jaina API origin allowlist.
  • The SDK targets netstandard2.0 so it works in Unity 2020+ without IL2CPP issues.