Skip to main content

Data Table

Data Table is a centralized game data management system. It allows you to manage various game content data in a spreadsheet format and automatically deploy it via CDN.

Key Features

  • Centralized management of game content data
  • Edit data in spreadsheet format
  • Automatic distribution through CDN
  • Powerful query functionality with LINQ-style syntax

Component Setup

Inspector

Data Table Inspector

  • Refresh Data Tables: Update to latest data

Component References

public class GameDataManager : MonoBehaviour
{
private BACKND.DataTable _dataTable;

void Awake()
{
_dataTable = GetComponent<BACKND.DataTable>();
if (_dataTable == null)
{
_dataTable = gameObject.AddComponent<BACKND.DataTable>();
}
}
}

Data Definition and Use

Item Data Example

id,name,type,grade,price,attack,defense
1001,Ancient Sword,Weapon,Legendary,5000,150,0
1002,Steel Armor,Armor,Rare,2000,0,80
1003,Health Potion,Consumable,Common,100,0,0

Class Definition

public class ItemData
{
public int id;
public string name;
public string type;
public string grade;
public int price;
public int attack;
public int defense;
}

Data Lookup

public class ItemManager : MonoBehaviour
{
private BACKND.DataTable _dataTable;

void Awake()
{
_dataTable = GetComponent<BACKND.DataTable>();
}

// Lookup single item
public ItemData GetItem(int itemId)
{
return _dataTable.From<ItemData>()
.Where(x => x.id == itemId)
.FirstOrDefault();
}

// Item list of certain grade
public List<ItemData> GetItemsByGrade(string grade)
{
return _dataTable.From<ItemData>()
.Where(x => x.grade == grade)
.ToList();
}
}

Practical Example: Monster Data

Data Structure

id,name,level,health,attack,defense
1,Goblin,1,100,10,5
2,Wolf,3,150,15,8
3,Dragon,10,1000,100,50

Implmentation Example

public class MonsterData
{
public int id;
public string name;
public int level;
public int health;
public int attack;
public int defense;
}

public class MonsterManager : MonoBehaviour
{
private BACKND.DataTable _dataTable;

void Awake()
{
_dataTable = GetComponent<BACKND.DataTable>();
}

// Search monster in level range
public List<MonsterData> GetMonstersByLevel(int minLevel, int maxLevel)
{
return _dataTable.From<MonsterData>()
.Where(x => x.level >= minLevel && x.level <= maxLevel)
.OrderBy(x => x.level)
.ToList();
}

// Search the strongest monster
public MonsterData GetStrongestMonster()
{
return _dataTable.From<MonsterData>()
.OrderByDescending(x => x.attack)
.FirstOrDefault();
}
}
Use Tips
  1. Component setup

    • The DataTable component must be referenced using GetComponent.
    • If it's not present, you can add it using AddComponent.
  2. Data management

    • After modifying data in the console, use the Refresh button to update.
    • Related data should be managed in a single table.
  3. Use of Query

    • Filter required data using Where.
    • Sort data using OrderBy.
    • Retrieve a single data entry using FirstOrDefault. :::
  • The column names in the table must match the property names in the class
  • Use the Refresh Data Tables button to load the latest data.
  • Since it is automatically deployed via CDN, no separate deployment process is needed. :::