Misc

← Back Referencing tables, fields, rows and cells

This section described methods for creating a serializable references to tables, fields, rows and cells. For regular database access use CodeGen addon generated classes or basic API

How to reference a Method Screenshot
Table Use BGMetaReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGMetaReference table;

    private void Start()
    {
        BGMetaEntity meta = table.Meta;
    }
}
Field Option #1. Use BGFieldReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGFieldReference field;

    private void Start()
    {
        BGField dbField = field.Field;
    }
}
Option #2. Use field reference class, generated by CodeGen addon
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    //D_Weapon_FieldRef class is generated by CodeGen addon
    public D_Weapon_FieldRef field;

    private void Start()
    {
        BGField dbField = field.Field;
    }
}
Row Option #1. Use MonoBehaviour generated components
Code example
using UnityEngine;

public class Temp : MonoBehaviour
{
    private void Start()
    {
        // M_Weapon is a generated class
        M_Weapon weapon = GetComponent<M_Weapon>();
        print($"Weapon {weapon.name}");
    }
}
Option #2. Use BGEntityGo component (can reference a row from any table but no generated properties/methods)
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    private void Start()
    {
        BGEntityGo weapon = GetComponent<BGEntityGo>();
        BGEntity entity = weapon.Entity;
    }
}
Option #3. Use classes, generated by CodeGen addon
Code example
using UnityEngine;

public class Temp : MonoBehaviour
{
    public D_Weapon_RowRef row;

    private void Start()
    {
        // D_Weapon class is also generated by CodeGen addon
        D_Weapon dbRow = row.Entity;
    }
}
Option #4. Use BGEntityReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGEntityReference row;

    private void Start()
    {
        BGEntity dbRow = row.GetEntity();
    }
}
Cell Cell includes table, field and row. Use BGCellReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGCellReference cell;

    private void Start()
    {
        BGEntity dbRow = cell.GetEntity();
        BGField dbField = cell.Field;
        print(cell.Value);
    }
}
← Back to Misc