Game.UI.Editor.UIIconField
Assembly:
Game
Namespace:
Game.UI.Editor
Type:
public class UIIconField
Base:
IFieldBuilderFactory
Summary:
Creates a field builder that produces a small UI group for editing an icon URI: a string input labeled "URI" and an icon button that opens the game's thumbnail picker. The selected image asset (if found) is converted to a global URI and written back to the provided value accessor; the icon button's preview is updated accordingly. The builder uses a CastAccessor
Fields
- None
This class does not declare instance fields.
Properties
- None
No public or private properties are declared on this class.
Constructors
public UIIconField()
Default parameterless constructor. No special initialization is performed.
Methods
-
public FieldBuilder TryCreate(Type memberType, object[] attributes)
Tries to create a FieldBuilder for the given member type and attributes. When called it returns a delegate (FieldBuilder) that, given an IValueAccessor, constructs and returns a Group widget with two children: -
StringInputField:
- displayName = "URI"
- accessor = CastAccessor
(accessor) — adapts the given accessor to a string accessor used to read/write the URI.
-
IconButton:
- icon = current accessor string value (or empty string if null)
- action = opens the InspectorPanelSystem's thumbnail picker via World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged
().ShowThumbnailPicker(...) - When a thumbnail is selected the callback receives a Colossal.Hash128 hash.
- Attempts to resolve an ImageAsset from AssetDatabase.global.TryGetAsset(hash, out ImageAsset asset).
- If resolved, uses asset.ToGlobalUri() as the URI string; otherwise uses an empty string.
- Writes the URI back to the CastAccessor
and updates iconPicker.icon to show the chosen image.
Notes and behavior details: - The method returns a delegate that constructs the UI at the time the inspector/editor needs it (lazy construction). - If accessor.GetValue() returns null, the icon button starts with an empty icon string. - Uses Unity.Entities.World.DefaultGameObjectInjectionWorld to locate or create the InspectorPanelSystem; therefore this action requires the ECS world to be available and should run on the main thread/UI context. - Relies on Colossal.IO.AssetDatabase, ImageAsset, and their ToGlobalUri implementation to compute a usable URI for the selected thumbnail.
Usage Example
// Example: create a field builder for a string property and build the widget for a given accessor
var factory = new UIIconField();
FieldBuilder builder = factory.TryCreate(typeof(string), new object[0]);
// `myAccessor` must implement IValueAccessor; this example assumes it's available at runtime.
IWidget iconGroupWidget = builder.Invoke(myAccessor);
// The returned widget is a Group containing:
// - a StringInputField bound to the accessor (display name "URI")
// - an IconButton that opens the thumbnail picker and writes the chosen asset's global URI back to the accessor