Use Unreal-like DataTable workflow in Unity.
Implement IDataTableRow
and add [Serializable]
attribute.
using System;
using Chris.DataDriven;
using Chris.Resource;
using Chris.Serialization;
using UnityEngine;
// Must add this attribute
[Serializable]
public class MyDataRow : IDataTableRow
{
public int id;
public SoftAssetReference reference;
public string name;
}
Recommend to implement DataTableManager<T>
for managing DataTable.
Use await DataTableManager.InitializeAsync()
to initialize managers at start of your game.
Or enable Initialize Managers
in AkiFrameworkSettings
to initialize managers before scene load automatically.
public class MyDataTableManager : DataTableManager<MyDataTableManager>
{
public MyDataTableManager(object _) : base(_)
{
}
private const string TableKey = "MyDataTable";
protected sealed override async UniTask Initialize(bool sync)
{
try
{
if (sync)
{
ResourceSystem.LoadAssetAsync<DataTable>(TableKey, (x) =>
{
RegisterDataTable(TableKey, x);
}).WaitForCompletion();
return;
}
await ResourceSystem.LoadAssetAsync<DataTable>(TableKey, (x) =>
{
RegisterDataTable(TableKey, x);
});
}
catch (InvalidResourceRequestException)
{
}
}
public DataTable GetDataTable()
{
return GetDataTable(TableKey);
}
}
Support two kinds of editing mode.
Edit DataTable in Inspector.
Edit DataTable in an EditorWindow (opened by double-left clicked).