Game.MoveableBridge
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: public class MoveableBridge
Base: ComponentBase
Summary:
MoveableBridge is a prefab component class used to define a movable bridge prefab in the ECS-based game. It exposes configuration data (lift offsets and moving time) that are written into the entity as a MoveableBridgeData component during prefab initialization. The class also declares which components the prefab requires (MoveableBridgeData) and which components its archetype should include (PointOfInterest). It is annotated with a ComponentMenu attribute so it can be placed under Objects/ in authoring tools.
Fields
-
public Unity.Mathematics.float3 m_LiftOffsets
Used to specify the lift offset(s) for the bridge when it moves. This vector is copied into the MoveableBridgeData component during Initialize, and drives the bridge movement offsets in-game. -
public float m_MovingTime
Duration (in seconds) for the bridge to complete its move. This value is copied into MoveableBridgeData during Initialize and used by runtime systems to control animation/timing of the bridge movement.
Properties
- (none)
This class defines no public properties; it exposes configuration via public fields that are serialized on the prefab.
Constructors
public MoveableBridge()
Default constructor (implicit). The class relies on field initialization and the overridden Initialize method; no custom construction logic is present.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component type required by the prefab to the provided set. Implementation addsComponentType.ReadWrite<MoveableBridgeData>()
, indicating the prefab writes MoveableBridgeData to the entity created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds archetype-level component requirements for entities created from this prefab. Implementation addsComponentType.ReadWrite<PointOfInterest>()
, marking the entity as a point of interest in the world archetype. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into an Entity. Creates a default MoveableBridgeData struct, copies the m_LiftOffsets and m_MovingTime field values into it, and callsentityManager.SetComponentData(entity, componentData)
, thereby applying the prefab-configured data to the created entity.
Notes and considerations: - This class integrates prefab authoring with Unity.Entities — the authoring fields are plain serializable fields that get converted to ECS component data at entity creation time. - The code references MoveableBridgeData and PointOfInterest types; ensure these runtime component types exist and are compatible with the data written here. - The class is attributed with [ComponentMenu("Objects/", new Type[] { typeof(StaticObjectPrefab) })], placing it in the editor menu under Objects/ and indicating it is a static object prefab variant.
Usage Example
// Example: configuring a MoveableBridge prefab in code (or in inspector)
// Assign values on the prefab authoring component before the prefab is converted/instantiated.
MoveableBridge bridgePrefab = /* obtain prefab reference (authoring) */;
bridgePrefab.m_LiftOffsets = new Unity.Mathematics.float3(0f, 4f, 0f);
bridgePrefab.m_MovingTime = 3.5f;
// When the prefab is instantiated into an entity, the engine calls Initialize:
EntityManager entityManager = /* get EntityManager */;
Entity entity = /* entity created for this prefab */;
bridgePrefab.Initialize(entityManager, entity);
// After initialization, the entity has MoveableBridgeData with the configured values:
var data = entityManager.GetComponentData<MoveableBridgeData>(entity);
// data.m_LiftOffsets == bridgePrefab.m_LiftOffsets
// data.m_MovingTime == bridgePrefab.m_MovingTime
Additional tips: - Configure m_LiftOffsets and m_MovingTime in the prefab authoring inspector for designers; systems should read MoveableBridgeData at runtime to perform movement logic. - If you add new runtime fields to MoveableBridgeData, remember to copy them in Initialize so the entity receives the updated values.