Game.Prefabs.StandingObject
Assembly: Game
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component that configures leg geometry for "standing" objects (objects that have legs/supports). It exposes editable parameters (leg size, gap, circular vs rectangular leg) and, during prefab initialization, writes those values into the ObjectGeometryData component on the entity. The class is annotated with a ComponentMenu attribute so it appears under Objects/ in the prefab component menu.
Fields
-
public Unity.Mathematics.float3 m_LegSize
Initial leg dimensions (x = width in X, y = height, z = width in Z). Default in source: (0.3f, 2.5f, 0.3f). Used to set ObjectGeometryData.m_LegSize. -
public Unity.Mathematics.float2 m_LegGap
Gap between legs on the XZ plane. If non-zero, used to compute leg offset (half of (m_LegGap + leg-size.xz)). If zero, leg offset is left at default (0,0). -
public System.Boolean m_CircularLeg
If true, the prefab will mark legs as circular when writing flags to ObjectGeometryData; otherwise legs are treated as rectangular. Default: true.
Properties
- None (this class does not define properties).
Constructors
public StandingObject()
No explicit constructor is defined in source; the default parameterless constructor is used. Initialization of the public fields uses their inline defaults.
Methods
-
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds required component types to the prefab. Implementation adds ComponentType.ReadWrite() so the prefab will include ObjectGeometryData data on the entity. -
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Empty implementation in source — this prefab component does not add further archetype-only component types. -
public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Called during prefab/entity initialization. Behavior: - Calls base.Initialize(entityManager, entity).
- Reads ObjectGeometryData from the entity.
- Writes m_LegSize into ObjectGeometryData.m_LegSize.
- Computes ObjectGeometryData.m_LegOffset as:
- default(float2) when m_LegGap == 0
- otherwise (m_LegGap + m_LegSize.xz) * 0.5f (This centers legs around the object using the gap plus leg size.)
- Updates ObjectGeometryData.m_Flags by OR-ing in a GeometryFlags value depending on m_CircularLeg:
- if m_CircularLeg is true: OR with 384
- otherwise: OR with 128 (These numeric values correspond to specific bits in the GeometryFlags enum used by the engine to indicate leg shape/geometry options.)
- Writes the modified ObjectGeometryData back to the entity via entityManager.SetComponentData.
Notes: - The code uses math.select(default(float2), (m_LegGap + m_LegSize.xz) * 0.5f, m_LegGap != 0f) to conditionally compute the offset only when a gap is provided. - The numeric flag values (384 and 128) are bitmask values; consult the GeometryFlags enum in the game's codebase to determine their exact meanings.
Usage Example
// Example showing how a derived prefab component might set parameters
// before the prefab's Initialize runs. This pattern can be used to
// change leg parameters at edit-time or via another script.
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
public class MyStandingObjectPrefab : Game.Prefabs.StandingObject
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
// tweak defaults before base.Initialize applies them to ObjectGeometryData
m_LegSize = new float3(0.5f, 3f, 0.5f);
m_LegGap = new float2(1.0f, 1.0f);
m_CircularLeg = false;
base.Initialize(entityManager, entity);
}
}
Additional tips: - The component is intended for prefab configuration (typically edited in the Unity inspector for the prefab). When creating or modifying prefabs, ensure ObjectGeometryData exists on the entity (GetPrefabComponents ensures it will be added). - If you need different flag values or new geometry behavior, update the GeometryFlags usage in Initialize accordingly and verify contraints with other geometry systems in the game.