Game.Prefabs.CraneObject
Assembly:
Assembly-CSharp (game assembly / modding runtime)
Namespace:
Game.Prefabs
Type:
public class
Base:
ComponentBase
Summary:
CraneObject is a prefab component that defines configuration for crane static objects and wires that configuration into the Unity.Entities ECS world. It exposes a serializable Bounds1 field (m_DistanceRange) used to initialize the CraneData component on the prefab entity. The class also declares which components belong to the prefab and which components should be present in the runtime archetype (Crane and PointOfInterest). It is decorated with a ComponentMenu attribute so it appears under "Objects/" in the editor as a StaticObjectPrefab type.
Fields
public Colossal.Mathematics.Bounds1 m_DistanceRange = new Bounds1(0f, float.MaxValue);
This field defines the operational distance range for the crane and is serialized on the prefab. Default is [0, +∞). During initialization the value is copied into the entity's CraneData component (component data struct used by runtime systems).
Properties
- This type does not declare any public properties.
Constructors
public CraneObject()
Default parameterless constructor. No additional initialization is performed beyond the field initializer for m_DistanceRange.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components that should exist on the prefab entity. Implementation addsComponentType.ReadWrite<CraneData>()
. This ensures the prefab entity will contain CraneData so serialized prefab values (like m_DistanceRange) can be stored. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components that the runtime archetype for placed instances should include. Implementation addsComponentType.ReadWrite<Crane>()
andComponentType.ReadWrite<PointOfInterest>()
. In short: CraneData is a prefab/configuration component, while Crane and PointOfInterest are runtime components added to the entity archetype. -
public override void Initialize(EntityManager entityManager, Entity entity)
Copies the prefab configuration into ECS component data. Implementation: - Calls
base.Initialize(entityManager, entity)
- Creates a
CraneData
struct, sets itsm_DistanceRange
from the prefab field, thenentityManager.SetComponentData(entity, componentData)
This transfers the serialized m_DistanceRange value from the prefab object to the actual ECS component present on the entity.
Notes: - The class relies on Unity.Entities (ECS) and Colossal.Mathematics.Bounds1. - The ComponentMenu attribute registers this prefab type in the editor UI under "Objects/" and identifies it as a StaticObjectPrefab.
Usage Example
// Example: override Initialize to customize range before applying to entity
public class CustomCrane : CraneObject
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
// change prefab value programmatically before it's written to CraneData
m_DistanceRange = new Bounds1(5f, 100f);
base.Initialize(entityManager, entity);
}
}
// Reading the data later from an entity:
CraneData data = entityManager.GetComponentData<CraneData>(entity);
// Access the range values (field names depend on CraneData definition)
var range = data.m_DistanceRange;
float min = range.min; // or appropriate accessor on Bounds1
float max = range.max;
{{ This prefab component connects authorable crane configuration (m_DistanceRange) to the ECS world by declaring the prefab component CraneData and the runtime components Crane and PointOfInterest. Use the prefab in the editor or subclass it to provide custom initialization behavior before the component data is written to the entity. }}