Skip to content

Game.UI.Widgets.CustomFieldAttribute

Assembly: Assembly-CSharp
Namespace: Game.UI.Widgets

Type: class

Base: UnityEngine.PropertyAttribute

Summary:
An attribute you can place on a field or property to indicate that a specific factory type should be used to create a custom UI field/editor for that member. The attribute stores a Type reference to the factory and enforces that the factory value is not null. This is intended for the game's UI/widget system to locate and instantiate a custom field implementation for use in inspectors/widgets.


Fields

  • This class declares no private fields.
    The attribute only exposes a publicly accessible property to hold the factory Type.

Properties

  • public System.Type Factory { get; set; }
    Holds the Type of the factory that will be used to create the custom field/editor for the attributed member. The property is annotated with Colossal.Annotations.NotNull, indicating the factory Type must not be null. The attribute enforces this by throwing an ArgumentNullException in its constructor if a null Type is passed.

Constructors

  • public CustomFieldAttribute([NotNull] System.Type factory)
    Creates a new CustomFieldAttribute and sets the Factory property. Throws ArgumentNullException if factory is null.

Usage notes: - The attribute is restricted to properties and fields (see AttributeUsage on the class). - The supplied factory Type is typically a class the UI/widget system knows how to instantiate and use (for example, a factory implementing some internal "field factory" interface). The attribute merely stores the Type — actual instantiation/usage is performed by the UI/widget code that reads the attribute.

Methods

  • This class declares no methods beyond what it inherits from System.Attribute and UnityEngine.PropertyAttribute. All behavior is provided by the constructor and by the surrounding UI system that consumes the attribute.

Usage Example

// Mark a field or property to use a custom field factory type
[CustomField(typeof(MyCustomFieldFactory))]
public int MyValue;

// Example factory skeleton the UI system might expect:
public class MyCustomFieldFactory
{
    // Typical responsibilities (example only — actual expected API depends on the UI system):
    // - Create the UI element for the field
    // - Bind it to the target object/field
    // - Handle value changes and validation

    public object CreateField(object target, string memberName)
    {
        // Create and return a UI control for the given target/member.
        // The real implementation depends on the widget framework used by the game.
        return null;
    }
}

Additional notes: - The attribute target is limited to properties and fields via [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]. - The NotNull annotation (Colossal.Annotations.NotNull) documents that Factory should not be null and the constructor enforces this. - When authoring a factory type, consult the game's UI/widget framework documentation or existing factories in the game code to implement the required creation/binding API expected by the system that consumes this attribute.