Game.UI.Editor.BuildingLotFieldBase
Assembly: Game
Namespace: Game.UI.Editor
Type: abstract class
Base: IFieldBuilderFactory
Summary:
BuildingLotFieldBase is an abstract helper class for creating UI field builders that edit building lot dimensions (width/depth) in the editor UI. It provides a protected TryCreate overload that constructs an IntInputField for lot sizes and optional paired expand/shrink buttons that adjust the underlying BuildingPrefab's lot size and translate all mesh/subobject/subarea/sub-lane/sub-net/effect data to keep the prefab geometry coherent. It enforces min/max lot sizes and notifies the editor UI after modification.
Fields
private static readonly int kMaxSize
-
The maximum allowed lot size (applies to width or depth). Used to disable expand buttons when reached.
-
private static readonly int kMinSize
- The minimum allowed lot size. Used to disable shrink buttons when reached.
Properties
- (none)
Constructors
protected BuildingLotFieldBase()
Implicit parameterless constructor (compiler-generated). Derived classes implement the abstract TryCreate to provide concrete FieldBuilder factories.
Methods
-
public abstract FieldBuilder TryCreate(Type memberType, object[] attributes)
Abstract method required by IFieldBuilderFactory. Implementers should return a FieldBuilder for the given member type/attributes (or null) — typical implementations will call the protected overload to produce a width or depth field. -
protected FieldBuilder TryCreate(Type memberType, object[] attributes, bool horizontal)
Creates and returns a FieldBuilder delegate that builds an IntInputField bound to an integer accessor (lot dimension). The resulting widget: -
Is an IntInputField with display name "Lot Width" when horizontal is true, otherwise "Lot Depth".
- Limits values between kMinSize and kMaxSize.
- Uses a CastAccessor
to convert accessor values. - If the accessor's parent object is a BuildingPrefab, the builder also creates four buttons:
- Expand Left / Expand Front (depending on horizontal)
- Expand Right / Expand Back
- Shrink Left / Shrink Front
- Shrink Right / Shrink Back
- Each expand/shrink button calls AddCells(prefab, button, dir, count) with appropriate dir (int2) and count (default 1 or -1 for shrinking), and buttons are disabled when min/max bounds are reached.
- If no BuildingPrefab can be resolved from the accessor, the builder returns only the IntInputField.
Notes: - horizontal true indicates the field controls lot width and creates left/right labels/buttons; false controls lot depth with front/back labels. - The FieldBuilder returns a Column containing the input and two ButtonRow entries (if prefab found), or the input field only.
private static void AddCells(BuildingPrefab prefab, IWidget widget, int2 dir, int count = 1)
Adjusts the given BuildingPrefab's lot size and translates all related geometry/sub-data by a computed offset so the prefab remains consistent after increasing or decreasing lot size.
Behavior details:
- Computes old size = (m_LotWidth, m_LotDepth) and new size = old + abs(dir) * count.
- Computes translation offset = 4f * dir * (newSize - old) and converts to float3 (x,0,z).
- The 4f multiplier matches tile/cell spacing used by the game.
- Updates prefab.m_LotWidth and prefab.m_LotDepth to the new sizes.
- Retrieves the prefab Entity via PrefabSystem and the game's EntityManager.
- Offsets all prefab.m_Meshes[].m_Position by the translation.
- Offsets the SubMesh buffer (DynamicBuffer
Safety/notes: - The method mutates prefab data in place and updates ECS buffers/components; it assumes this is done on the main thread in the editor context. - The logic applies an integer cell delta (count) and absolute dir components to change one axis at a time depending on the button pressed.
private static bool TryGetBuildingPrefab(IValueAccessor accessor, out BuildingPrefab prefab)
Attempts to extract a BuildingPrefab instance from the provided IValueAccessor. The method succeeds if the accessor is a FieldAccessor whose parent is an ObjectAccessor
Usage Example
// Example implementation that creates a width field (horizontal = true)
public class LotWidthFieldFactory : BuildingLotFieldBase
{
public override FieldBuilder TryCreate(Type memberType, object[] attributes)
{
// Delegate to the protected helper to create the width field UI (with expand/shrink buttons)
return TryCreate(memberType, attributes, horizontal: true);
}
}
// Example implementation that creates a depth field (horizontal = false)
public class LotDepthFieldFactory : BuildingLotFieldBase
{
public override FieldBuilder TryCreate(Type memberType, object[] attributes)
{
return TryCreate(memberType, attributes, horizontal: false);
}
}
Additional remarks: - Use these factories when building custom editor panels for BuildingPrefab instances; they provide consistent UI and prefab geometry updates for lot resizing. - The translation uses a fixed 4-unit-per-cell scale; if tile size changes elsewhere in the game, adjustments may be required.