Doloro GDK 22 .1.0 Beta
by Tauri Interactive
Asset Property

About

Asset Property is an atomic block of DDM APS module's architecture. It provides an interface to storing and operating of an abstract value for any case:

  • in Editor
  • at Runtime
  • during Cross-session

See also:


Pre-integrated types

DDM ASP supplies you with a lot of frequently using types "from a box".

Operating type Property Type Supported operators
bool Doloro.DataManagement.AssetPropertiesSystem.BoolAssetProperty Not Or And Xor
bool Doloro.DataManagement.AssetPropertiesSystem.FlagAssetProperty
float Single Doloro.DataManagement.AssetPropertiesSystem.FloatAssetProperty + - / * ++ -- == !=
int Int32 Doloro.DataManagement.AssetPropertiesSystem.IntAssetProperty + - / * ++ -- == !=
string Doloro.DataManagement.AssetPropertiesSystem.StringAssetProperty +
Vector2 Doloro.DataManagement.AssetPropertiesSystem.Vector2AssetProperty + - / * == !=
Vector3 Doloro.DataManagement.AssetPropertiesSystem.Vector3AssetProperty + - / * == !=
Vector4 Doloro.DataManagement.AssetPropertiesSystem.Vector4AssetProperty + - / * == !=

Notes:

  • Types implement operators expected for them prototypes where possible. Partially implements the same operators between AssetProperty containers representing the prototype type, where not causes ref issues.
  • FlagAssetProperty is always true value using when you need to store not a dynamic state but a fact that something is on. It's a preferred way to work with binary properties where it possible.

Domains

Domains is the on of the core concepts using in properties.

It works like a namespace concept during regular source development, letting you use the same name several time but in different scopes.

Empty domains

A property with empty domain always locates to the Root domain.
Such a property can be accessed both with empty domain by the property name only, or by addressing it via the root\PROP_NAME path where the PROP_NAME is the name of the property.

Name conflicts

Domain or property can't have the same path.
In case if a property of domain conflicts each other such a set will cause an exception.

Valid pair Exception
Domain path Player.Body Player.Body
Property path Player.Body.health Player.body

Following exception example simulates the situation when you attempt to create body property in Player domain, but there already exits a domain Player\Body those conflicts with the property path. Same goes to other side.


Serialization

Any property must implement serialization compatibility. The entire from-box types have such compatibility, so you can easily serialize \ deserialize any property supplied container manually or by using Serialization Tools solutions.


Custom properties

Development

You can create your own AssetProperty implementations to extend the system with a custom data types required into your development.

Property class divided on two parts:

  • Runtime class
  • Editor class

Following tutorial introduce you into entire development stages.

Runtime part

To create a new runtime property implementation, you need to create a new class derived from the AssetProperty following the pattern provided below.

  1. Create new class.
  2. Derive it from AssetProperty
  3. Define Serializable attribute to it
  4. Define and implement ISerializable interface.
// Declaring using namespaces.
using System;
using System.Runtime.Serialization;
using Doloro.DataManagement.Serialization;
using Doloro.DataManagement.AssetPropertiesSystem
[Serializable] // Marking class the serializable.
public class PROPERTY_NAME :
AssetProperty, // Deriving `AssetProperty` class.
ISerializable // Implementing members demanded to serialization process.
{
// Property that handle the raw `Value` as expected type.
VALUE_TYPE ValueAs_VALUE_TYPE
{
get => Value is VALUE_TYPE v ? (VALUE_TYPE)v : DEFAULT_VALUE;
set => Value = (VALUE_TYPE)value;
}
// Empty constructor
public PROPERTY_NAME() : base()
{
}
// Constructor that allows to initialize property value.
public PROPERTY_NAME(VALUE_TYPE value)
{
ValueAsVector3 = value;
}
// Constructor using during restore of serialized date.
public PROPERTY_NAME(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}
}
Placeholder Meaning
PROPERTY_NAME Name of the new property class. Should be named in format OperatingType+AssetPropety.
VALUE_TYPE Type of the property prototype.
  • Placeholders have to be changed on your values.
  • Class must have Serializable attribute.
  • Class must implement ISerializable interface.

Editor part

After creating the runtime part, you need to create editor part to let the tool know how to display and treat the property in Editor GUI.

Warning
The class created for this part MUST be located at Editor folder.
  1. Create new class.
  2. Derive it from AssetPropertyEditor.
  3. Define PropertyInspector attribute to the class.
    1. Refer the type of the runtime class as argument.
  4. Override OnInpectorGUI(UnityEngine.Rect rect) member with your custom GUI implementation that handles the value supplied by the source property.

See also: Doloro.DataManagement.AssetPropertiesSystem.AssetPropertyEditor

using Doloro.DataManagement.AssetPropertiesSystem
using UnityEditor;
// Bonding the editor to runtime representation.
[PropertyInspector(typeof(PROPERTY_NAME))]
// Decalring class derived from `AssetPropertyEditor`
public class FloatAssetPropertyEditor : AssetPropertyEditor
{
// Constructor that receives property as an argument.
public PROPERTY_NAME_Editor(PROPERTY_NAME property) : base(property) { }
// Implementing editor representation of the property.
public override void OnInpectorGUI(UnityEngine.Rect rect)
{
// Getting casted source property.
var fp = source as PROPERTY_NAME;
// Drawing property prefix.
rect = DrawPropertyPrefixLabel(source, rect);
// Drawing Editor GUI field that will handle the value set.
fp.ValueAs_VALUE_TYPE = /* PLACE YOUR GUI field here */
}
}

Example

the possible option to get an example is exploration of ddm-aps-com-ap-types. Entire classes you may find in project by following directories:

Type Path
Runtime Doloro-GDK \ Doloro-Data-Management \ Runtime \ Asset Properties System \ Properties \
Editor Doloro-GDK \ Doloro-Data-Management \ Editor \ Asset Properties System \ Properties \