If you need to create DataConfig assets automatically, you can use this tool. Here are few steps to set up workspace:
- Create Google SpreadSheet document like at the link below: https://docs.google.com/spreadsheets/d/1L77AUU-SmKj3dVjPl7hEbnWeGkr6HcT5tt0Rxgxswoo/edit#gid=0. First row and column would be your document version. You can automatically increase version by the following code: (Copy-paste it in your google-docs scripts in your document)
function onEdit(cell) {
incrementCell(SpreadsheetApp.getActive().getActiveSheet().getName(), "A1:A1");
}
function incrementCell(sheet, cell) {
var sheet = SpreadsheetApp.getActive().getSheetByName(sheet);
var range = sheet.getRange(cell);
range.setValue(range.getValue() + 1);
}
- Publish your document to get CSV link.
- Create "Create/ME.ECS/Addons/Data Config Generator Settings" asset and fill up the form with the target directory, caption and csv link to your google-spreadsheet.
- Press "Update All" and wait while operation has been complete. Pressing "Force Update All" runs an update ignoring current loaded version (Use this only if you understand that google-docs could return older file versions).
- Your data configs should automatically created at your destination directory.
First row - component names.
Second row - component fields.
First column - comment or custom type of DataConfig.
Second column - template(s) to be use.
Third column - config name.
Note, if you leave spreadsheet cell empty, there are no component would be created for this data config.
Primitive types like int, float, etc. have their built-in parsers.
Array types could be added with json-format: [1, 2, 3] or ["s1", "s2", "s3"]
Note, if no parser found for your cell - json format will be used as a fallback and target field type will be the container type of this json.
You can use custom links to the few UnityEngine.Object types: ECS View, UnityEngine.GameObject, UnityEngine.Component and DataConfig. To use them, define it by the following code:
config://YOUR_GENERATED_CONFIG_NAME
so://Assets/path/to/your/scriptableobject.asset
view://Assets/path/to/your/view.prefab
go://Assets/path/to/your/gameObject.prefab
component://Assets/path/to/your/gameObject/with/component.prefab
sprite://Assets/path/to/your/sprite.png
tex://Assets/path/to/your/texture.png
If you need to parse some custom data, you can write your own implementation, just define struct with IParser
interface:
public struct Vector2IntParser : IParser {
public bool IsValid(System.Type fieldType) {
return typeof(Vector2Int) == fieldType;
}
public bool Parse(string data, System.Type componentType, string fieldName, System.Type fieldType, out object result) {
var prs = data.Split(';');
result = new Vector2Int(int.Parse(prs[0]), int.Parse(prs[1]));
return true;
}
}
if you need custom behaviour for some aspects of DataConfig Generator, you can use IGeneratorBehaviour
to override default behaviour for these methods:
CreateConfigInstance
DeleteConfigAsset
Follow the steps below to override default behaviour:
- Create new class and inherit it from
GeneratorBehaviour
. - Tag your class with
CreateAssetMenu
attribute. - In Unity create your custom behaviour asset.
- Drag'n'drop your behaviour asset to the settings file.