Custom data type

Every supported data type in Databox is derived from DataboxType. Follow these instructions to create a custom databox type class.

You can also have a look at the ExampleCustomDataType.cs script, located at: Databox / Types, to see how you can create your own data types with custom editor ui.

  1. Create a new C# class and name it like you wish. (In this example: CustomDataClass)

  2. Add the namespace Databox to the class.

using Databox;
  1. Derive from DataboxType

public class CustomDataClass : DataboxType 
{
  ...
}
  1. While deriving from DataboxType you will get access to several overrideable methods.

public override void DrawEditor(){}
public override void DrawInitValueEditor(){}
public override void Reset(){}
public override string Equal(DataboxType _changedValue){}
  1. Let's add a simple int value called health to our class.

    [SerializeField]
    private int _health;
    [SerializeField]
    public int InitHealth; // The initial health value
    // Public property of health. By using get and set we can add an OnValueChanged callback
    public int Health
    {
        get {return _health;}
        set
        {
            if (value == _health){return;}
            _health = value;
            if (OnValueChanged != null){OnValueChanged(this);}
        }
    }
  1. Several things we need to consider.

To make sure the values are being serialized add a [SerializeField] attribute to the variable InitHealth stores the initial default value of our health variable. We will use the Reset() override method to set health back to InitHealth.

  1. Next we will create a custom editor for our custom class. This will be drawn in the Databox editor.

Note you can make use of the GUILayout or EditorGUILayout(not working at runtime) API to create your custom editor gui for your data class. Also check out the example class EnemyType in the project folder.

  1. Let's add the additional GUI code to draw the initial value.

  1. To make sure our reset to initial value functionality works we need to add the Reset() method.

  1. To make sure the cloud sync comparison works we need to add following method. We basically compare each value and if they're different we return a string with the changes.

  1. Finally we have to add the convert method to make sure the CSV import works. The convert method simply converts the string which comes from the CSV file to the appropriate data type. In this example we simply parse the string to a integer value.

  1. Here's the complete custom class. After saving the file you can add data entries of type "YourCustomDataClass"

Last updated