Misc

← Back Custom fields implementation guide
  1. 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.
  2. 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
  3. 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\*).
  4. To create a custom field you need to create two C# classes:
    1. Class for the field (in runtime assembly)
    2. Class for the field's manager (in Editor assembly)
  5. [Important] Do not try to create your classes from scratch, extend them from existing classes.
    For your field class:
    1. If your field value is a class extend your field class from BGFieldCachedClassA class
    2. If your field value is a struct extend your field class from BGFieldCachedStructA class
    For your field's manager class:
    1. If your field value can be edited "in place" (like primitive fields: int, float, string)- extend your field's manager class from BGFieldManagerInlinedA class
    2. 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
  6. The methods/properties, which need to be implemented for your field class:
    1. ToBytes/FromBytes- for binary serialization
    2. ToString/FromString- for string serialization
    3. CreateFieldFactory- utility method for creating new fields
    4. Implement ICloneable interface for your value type if it's a class (not struct)
    5. ValueSize property if your value type is a struct
  7. 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.
← Back to Misc