Personal - Tools - Datablock 2.0
By Johanne Vandorpe
Datablock 2.0
asset: download link
Table of Contents
How to?
Development
This tool has been made based on the following original opensource datablock asset: https://github.com/petesimard/datablocks, van Peter Simard.
As allowed by the license upon this asset I made some changes to it to allow some extra functions to work.
Setup and use
Add to project
Download asset then import it into the project it will appear in the asset folder under Datablock.
Setup a datablock
Setup script:
- Create an empty script. It should look like this:
public class TemplateDataBlock { // empty } - Give it the datablock parent like this:
public class TemplateDataBlock : Datablock - Give it a category of choice:
[DatablockCategory("templateCategory")] public class TemplateDataBlock : Datablock { //data fields }
Different datafields setup
Once the script is done you can add any datafield that you would need for this datablock of the folowing types:
- string:
public string templateString; // will give you a simple field to put in a string - int:
public int templateInt; // will give you a simple field to put in an int value - char:
public char templateChar; //will give you a simple field to put in 1 character - double:
public double templateDouble; // will give you a simple field to put in an double value - float:
public float templateFloat; // will give you a simple field to put in an float value - bool:
public float templateBool; // will give you checkbox, true or false - enum:
public enum TemplateEnum { templateValue1; templateValue2; templateVAlue3 } public TemplateEnum templateEnum; // will appear as a dropdown menu. - list:
public List<var> templateList; // shows as a list in which you can add items of the defined type.
Datablock layout fields
There are also ways to organize the way the unity editor displays the datafield.
- Foldout, lets you organize the fields in different categories:
[DatablockFoldout("foldout message that when clicked on it shows underlying fields")]
public int field1;
public string field2;
public int field3;
[DatablockFoldout("second foldout wil appear under it")]
[DatablockFoldout("sub foldout should appear in it")]
- bool, the following fields wil only appear if the bool value is set to true or false:
public bool templateBool;
[DatablockBool("templateBool")] // underlying var appear when true
public int field1;
public int field2;
[DatablockBool("templateBool", true)] // underlying var appear when false
public int field3;
public int field4;
- enum, the following fields only appear if the enum has a certain value:
public enum TemplateEnum
{
templateValue1,
templateValue2,
templateValue3
}
public TemplateEnum templateEnum;
[DatablockEnum("templateEnum", TemplateEnum.templateValue1)]
public int value1;
[DatablockEnum("templateEnum", TemplateEnum.templateValue2)]
public int value2;
[DatablockEnum("templateEnum", TemplateEnum.templateValue3)]
public int value3;