Skip to content

Game.UI.Widgets.CustomFieldBuilders

Assembly:
Assembly-CSharp (inferred)

Namespace:
Game.UI.Widgets

Type:
public class CustomFieldBuilders

Base:
System.Object, implements IFieldBuilderFactory

Summary:
CustomFieldBuilders is an IFieldBuilderFactory implementation that looks for a custom field factory type declared via widget attributes (resolved using WidgetAttributeUtils.GetCustomFieldFactory). If a custom factory type is found it caches an instance (or null on failure) in a static dictionary (kFactoryCache) and delegates creation to that factory's TryCreate method. Errors and exceptions during factory resolution/creation are logged to UnityEngine.Debug.


Fields

  • public static readonly System.Collections.Generic.Dictionary<System.Type, IFieldBuilderFactory> kFactoryCache
    A static cache that maps a custom factory Type to an instantiated IFieldBuilderFactory (the value may be null if instantiation failed). Caching prevents repeated reflection/activation for the same factory type. Note: the cache is accessed without explicit synchronization; concurrent access may need attention in multithreaded scenarios.

Properties

  • None.

Constructors

  • public CustomFieldBuilders()
    The default constructor (implicit). The class has no explicit constructor defined in source.

Methods

  • public FieldBuilder TryCreate(System.Type memberType, object[] attributes)
    Tries to create a FieldBuilder by:
  • Calling WidgetAttributeUtils.GetCustomFieldFactory(attributes) to get a Type representing a custom factory.
  • If a custom factory type is present:
    • Looks up the type in kFactoryCache.
    • If not cached, checks whether the type is assignable to IFieldBuilderFactory.
    • If assignable, tries to instantiate an instance using Activator.CreateInstance.
    • On exception during instantiation the exception is logged with UnityEngine.Debug.LogException and the cache stores null for that type.
    • If the type is not assignable, logs an error via UnityEngine.Debug.LogError.
    • If a non-null factory instance is available (from cache or newly created), delegates to that factory's TryCreate(memberType, attributes) and returns its result.
  • If no custom factory type is found or creation/delegation fails, returns null.

Behavior notes: - The method caches factory instances (including null) to avoid repeated instantiation attempts. - Logs errors and exceptions to Unity's console for easier debugging. - Returns null when no custom factory is specified, when the factory type is invalid, or when the factory returns null.

Usage Example

// Example custom factory implementing IFieldBuilderFactory
public class MyCustomFieldFactory : IFieldBuilderFactory
{
    public FieldBuilder TryCreate(Type memberType, object[] attributes)
    {
        // create and return a FieldBuilder for supported memberType, or return null
        return null;
    }
}

// Example usage of CustomFieldBuilders:
// Assume attributes contains an attribute recognized by WidgetAttributeUtils that specifies MyCustomFieldFactory.
var builderFactory = new Game.UI.Widgets.CustomFieldBuilders();
object[] attributes = /* attributes array that includes the custom factory spec */;
FieldBuilder builder = builderFactory.TryCreate(typeof(int), attributes);

// builder will be the result from MyCustomFieldFactory.TryCreate if a custom factory was provided and instantiated successfully,
// or null otherwise.