Playmaker

Description

Code Generator for Playmaker creates custom Actions to access BGDatabase data (not all fields are supported though)

Apart from Code Generation, you can use Playmaker's GetProperty and SetProperty actions with Generated MonoBehaviour to get/set any property from GameObject, hooked up to database.

There are 5 custom actions created by CodeGenerator for each table:
  1. GetById- retrieve a row (entity) using unique id and fill the fields values
  2. SetById- set the field values using unique id
  3. GetByIndex -retrieve a row (entity) using index and fill the fields value
  4. SetByIndex - set the field values using index
  5. Count -retrieve the number of rows

Supported fields

  1. int = FsmInt
  2. float = FsmFloat
  3. bool = FsmBool
  4. string = FsmString
  5. color = FsmColor
  6. rect = FsmRect
  7. vector2 = FsmVector2
  8. vector3 = FsmVector3
  9. quaternion = FsmQuaternion

If field type is not supported, it will be omitted

How to generate

Open BGDatabase window Window->BGDatabase

Go to Settings tab, and chose Playmaker

Fill parameters and press Generate button

Example

Here is an example for a meta called MyTable with single intField field of type int
//=============================================================
//||                   Generated by BansheeGz Code Generator ||
//=============================================================
namespace MyPackage
{
    //=============================================================
    //||                   Generated by BansheeGz Code Generator ||
    //=============================================================

    [ActionCategory("BansheeGz")]
    [HutongGames.PlayMaker.Tooltip("Fetch row data for MyTable meta from GameRepo database by id")]
    public partial class MyTableGetById : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity id")]
        [RequiredField]
        public FsmString _Id;
        [UIHint(UIHint.Variable)]
        public FsmString name;
        [UIHint(UIHint.Variable)]
        public FsmInt intField;
        public override void Reset()
        {
            _Id = null;
            name = null;
            intField = null;
        }
        public override void OnEnter()
        {
            if (_Id.IsNone || _Id.Value==null)
            {
                Debug.LogWarning("Required field _Id is not set");
                return;
            }
            var id = BGId.Empty;
            try
            {
                id = new BGId(_Id.Value);
            }
            catch
            {
                Debug.LogWarning("Unable to parse id " + _Id.Value);
                return;
            }
            var meta = BGRepo.I.GetMeta("MyTable");
            if (meta == null)
            {
                Debug.LogWarning("No meta found, name=MyTable");
                return;
            }
            var entity = meta[id];
            if (entity == null)
            {
                Debug.LogWarning("No entity found, id=" + id);
                return;
            }
            if(!name.IsNone)
            {
                name.Value = entity.Get("name");
            }
            if(!intField.IsNone)
            {
                intField.Value = entity.Get("intField");
            }
        }
    }


    //=============================================================
    //||                   Generated by BansheeGz Code Generator ||
    //=============================================================

    [ActionCategory("BansheeGz")]
    [HutongGames.PlayMaker.Tooltip("Set row data for MyTable meta from GameRepo database by id")]
    public partial class MyTableSetById : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity id")]
        [RequiredField]
        public FsmString _Id;
        [UIHint(UIHint.Variable)]
        public FsmString name;
        [UIHint(UIHint.Variable)]
        public FsmInt intField;
        public override void Reset()
        {
            _Id = null;
            name = null;
            intField = null;
        }
        public override void OnEnter()
        {
            if (_Id.IsNone || _Id.Value==null)
            {
                Debug.LogWarning("Required field _Id is not set");
                return;
            }
            var id = BGId.Empty;
            try
            {
                id = new BGId(_Id.Value);
            }
            catch
            {
                Debug.LogWarning("Unable to parse id " + _Id.Value);
                return;
            }
            var meta = BGRepo.I.GetMeta("MyTable");
            if (meta == null)
            {
                Debug.LogWarning("No meta found, name=MyTable");
                return;
            }
            var entity = meta[id];
            if (entity == null)
            {
                Debug.LogWarning("No entity found, id=" + id);
                return;
            }
            if(!name.IsNone)
            {
                entity.Set("name", name.Value);
            }
            if(!intField.IsNone)
            {
                entity.Set("intField", intField.Value);
            }
        }
    }


    //=============================================================
    //||                   Generated by BansheeGz Code Generator ||
    //=============================================================

    [HutongGames.PlayMaker.Tooltip("Get the number of rows for MyTable meta")]
    public class MyTableCount : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity index")]
        public FsmInt Count;
        public override void OnEnter()
        {
            if(Count != null)
            {
                Count.Value = BGRepo.I.GetMeta("MyTable").CountEntities;
            }
        }
    }


    //=============================================================
    //||                   Generated by BansheeGz Code Generator ||
    //=============================================================

    [ActionCategory("BansheeGz")]
    [HutongGames.PlayMaker.Tooltip("Fetch row data for MyTable meta from GameRepo database by index")]
    public partial class MyTableGetByIndex : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity index")]
        public FsmInt _Index;
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity id")]
        public FsmString _Id;
        [UIHint(UIHint.Variable)]
        public FsmString name;
        [UIHint(UIHint.Variable)]
        public FsmInt intField;
        public override void Reset()
        {
            _Id = null;
            _Index=null;
            name = null;
            intField = null;
        }
        public override void OnEnter()
        {
            if (_Index.IsNone)
            {
                Debug.LogWarning("Required field _Index is not set");
                return;
            }
            var meta = BGRepo.I.GetMeta("MyTable");
            if (meta == null)
            {
                Debug.LogWarning("No meta found, name=MyTable");
                return;
            }
            var entity = meta[_Index.Value];
            if(!name.IsNone)
            {
                name.Value = entity.Get("name");
            }
            if(!intField.IsNone)
            {
                intField.Value = entity.Get("intField");
            }
        }
    }


    //=============================================================
    //||                   Generated by BansheeGz Code Generator ||
    //=============================================================

    [ActionCategory("BansheeGz")]
    [HutongGames.PlayMaker.Tooltip("Set row data for MyTable meta from GameRepo database by index")]
    public partial class MyTableSetByIndex : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity index")]
        public FsmInt _Index;
        [UIHint(UIHint.Variable)]
        [HutongGames.PlayMaker.Tooltip("Entity id")]
        public FsmString _Id;
        [UIHint(UIHint.Variable)]
        public FsmString name;
        [UIHint(UIHint.Variable)]
        public FsmInt intField;
        public override void Reset()
        {
            _Id = null;
            _Index=null;
            name = null;
            intField = null;
        }
        public override void OnEnter()
        {
            if (_Index.IsNone)
            {
                Debug.LogWarning("Required field _Index is not set");
                return;
            }
            var meta = BGRepo.I.GetMeta("MyTable");
            if (meta == null)
            {
                Debug.LogWarning("No meta found, name=MyTable");
                return;
            }
            var entity = meta[_Index.Value];
            if(!name.IsNone)
            {
                entity.Set("name", name.Value);
            }
            if(!intField.IsNone)
            {
                entity.Set("intField", intField.Value);
            }
        }
    }
}