Doloro GDK 22 .1.0 Beta
by Tauri Interactive
Properties Aggregator

About

PropertiesAggregator is a component that composites hierarchy of IPropertiesProvider instances over a game object and allows to treat them like a wholesome collection of properties.

The main purpose of the component is providing public interface of asset properties shared all around an object's hierarchy. This is very handful for following cases:

  • An object is compatible with Merge Tool provided with the Dynamic Resource Tools. In that case the object part loading at runtime can contain its own properties that will be accessible via the aggregator instance.
  • Game object has a wide in-depth hierarchy where different branches related to different sub-systems. In such case it's very useful to use separated AssetPorpertiesCollection instances for an each sub-system dividing its properties from each other from more clear view.

See also:


How does it work

During the Start the component scans child hierarchy for instance that implements IPropertiesProvider interface.
Entire found providers assigning to the collection and treating as virtual hierarchy during request to the component's API.

The component forwards its API operation toward children any goes with a role of Proxy.


Interaction

PropertieseAggrecator works very similar to AssetPropertiesCollection for developer due to implementations of almost the same interfaces.

For developer there is no difference between components because they are following ideas of Composite design pattern.

But the difference here that the PropertiesAggregator not cares about which aggregated child component it works so the methods like Add just forwarding to the first found child and can't be sent toward precise component by using the default API.

The second important difference is that the component does not guaranty that the hierarchy has no conflicts with domains and properties due to:

  • trust to the AssetPropertiesCollection logic.
  • duplicates of virtual hierarchy members hides automatically because the search in properties aggregator not goes further than first entry has been collided.

Custom Aggregator

During your development you may face a case when you'll need to extend default logic or create some intermediate filtering properties provider.

To do this you just need to create a new class by following pattern with adding of your custom logic within.

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System.Collections;
using Doloro.DataManagement.AssetPropertiesSystem;
public class CustomPropertiesAggregator :
MonoBehaviour,
ICollection<IPropertiesProvider>,
IPropertiesProvider
{
public AssetProperty this[string path] =>
\\ return aggregated property by its path.
public int Count =>
\\return count of aggregated providers
public bool IsReadOnly =>
\\ normally `false` for the system but depends on your implementation.
public event Action<AssetProperty> onPropertyAdded;
public event Action<AssetProperty> onPropertyRemoved;
public void Add(IPropertiesProvider item)
{
// Handle provider adding to internal collection.
}
public void Add(AssetProperty item)
{
// Handle property adding to the hierarchy.
}
public void Clear()
{
// Release entire aggregated collections.
// Properties of the providers should not be removed by the action.
}
public bool Contains(IPropertiesProvider item)
{
// Check is the collection has been aggregated.
}
public bool Contains(string propertyPath)
{
// Check is the property by the path aggregated along with some collection.
}
public bool Contains(AssetProperty item)
{
// Check is the property by the path aggregated along with some collection.
}
public void CopyTo(IPropertiesProvider[] array, int arrayIndex)
{
// Share aggregated providers to destination array.
}
public void CopyTo(AssetProperty[] array, int arrayIndex)
{
// Share aggregated properties to destination array.
}
public IEnumerator<IPropertiesProvider> GetEnumerator()
{
// Return providers aggregated within the component.
}
public bool Remove(IPropertiesProvider item)
{
// Release provider from internal collection.
// Properties of the provider should not be removed by the action.
}
public bool Remove(AssetProperty item)
{
// Find and remove requested property.
}
IEnumerator IEnumerable.GetEnumerator()
{
// Handles default enumeration process.
}
IEnumerator<AssetProperty> IEnumerable<AssetProperty>.GetEnumerator()
{
// Provide enumerator for aggregated properties.
}
}