- Do not use custom fields unless all other alternatives are much worse. For example, if your custom field has two properties (int and float) there is no need to create a custom field, you can use two basic fields instead (int and float) to store the values.
- Do not try to create your custom field in your actual project. Create and test your custom field using a new, empty project. Make sure it works correctly before transferring this field to your project. A bug in your implementation can break the whole database
- Use existing fields implementations as examples. Fields implementation sources can be found in Assets\BansheeGz\BGDatabase\Scripts\BGDatabaseSourceCode.unitypackage package (Database\Field\*). Fields managers implementation sources can be found in Assets\BansheeGz\BGDatabase\Editor\Scripts\BGDatabaseEditorSourceCode.unitypackage package (Database\Field\*).
-
To create a custom field you need to create two C# classes:
- Class for the field (in runtime assembly)
- Class for the field's manager (in Editor assembly)
-
[Important] Do not try to create your classes from scratch, extend them from existing classes.
For your field class:- If your field value is a class extend your field class from BGFieldCachedClassA class
- If your field value is a struct extend your field class from BGFieldCachedStructA class
- If your field value can be edited "in place" (like primitive fields: int, float, string)- extend your field's manager class from BGFieldManagerInlinedA class
- If your field value can be edited in popup window, which can be opened by clicking on cell button (like complex fields: bounds, assets)- extend your field's manager class from BGFieldManagerWithButtonA class
-
The methods/properties, which need to be implemented for your field class:
- ToBytes/FromBytes- for binary serialization
- ToString/FromString- for string serialization
- CreateFieldFactory- utility method for creating new fields
- Implement ICloneable interface for your value type if it's a class (not struct)
- ValueSize property if your value type is a struct
- If you have difficulties implementing your own custom field - contact us and send us full source code for your value type (class/struct). You can skip its methods but all fields which needs to be saved inside database need to be included.