Game.Prefabs.AirplanePrefab
Assembly:
Namespace: Game.Prefabs
Type: class AirplanePrefab
Base: AircraftPrefab
Summary:
Prefab class that defines flight-related configuration for airplane vehicles. Exposes tunable parameters (speeds, accelerations, turning and angle limits) which are converted and written into ECS component data (AirplaneData) when the prefab is initialized. The prefab also declares the runtime components required for airplane entities (Airplane and AirplaneData).
Fields
-
public float2 m_FlyingSpeed = new float2(200f, 1000f);
Defines the min/max flying speed used by the airplane in the prefab in km/h. During initialization this speed range is converted from km/h to m/s (divided by 3.6) and stored in the AirplaneData component. -
public float m_FlyingAcceleration = 20f;
Linear acceleration (in m/s²) used for accelerating the airplane. -
public float m_FlyingBraking = 20f;
Linear braking deceleration (in m/s²) used for slowing the airplane. -
public float m_FlyingTurning = 10f;
Turning rate in degrees/sec as specified on the prefab. Converted to radians/sec when stored in AirplaneData (math.radians is applied). -
public float m_FlyingAngularAcceleration = 20f;
Angular acceleration in degrees/sec² as specified on the prefab. Converted to radians/sec² in AirplaneData. -
public float m_ClimbAngle = 20f;
Maximum climb angle in degrees on the prefab. Converted to radians and stored in AirplaneData. -
public float m_SlowPitchAngle = 20f;
Pitch angle limit (degrees) used for slow flight behavior. Converted to radians in AirplaneData. -
public float m_TurningRollFactor = 0.5f;
Factor (unitless) that scales how much the aircraft rolls when turning.
Properties
- This class does not declare public properties. (All configuration is exposed as public fields and applied to ECS components during Initialize.)
Constructors
public AirplanePrefab()
Default parameterless constructor (implicit). The class relies on field initializers for default values and overrides Initialize for ECS setup.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds runtime components required by this prefab instance. Calls base.GetPrefabComponents(components) and then adds the read/write component type AirplaneData to the set. This indicates that entities instantiated from this prefab need an AirplaneData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds archetype components for entity creation. Calls base.GetArchetypeComponents(components) and then adds the read/write component type Airplane. This ensures the created archetype contains the Airplane tag/struct component. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is converted/initialized into an ECS entity. This method: - Calls base.Initialize(entityManager, entity).
- Creates an AirplaneData instance from the prefab fields, performing unit conversions:
- m_FlyingSpeed is converted from km/h to m/s by dividing by 3.6f.
- Angular/angle fields (m_FlyingTurning, m_FlyingAngularAcceleration, m_ClimbAngle, m_SlowPitchAngle) are converted from degrees to radians using math.radians(...).
- Other numeric fields are copied directly.
- Writes the constructed AirplaneData to the entity via entityManager.SetComponentData(entity, new AirplaneData { ... }).
Usage Example
// Example of what AirplanePrefab.Initialize writes to the ECS entity:
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
entityManager.SetComponentData(entity, new AirplaneData
{
// converts km/h -> m/s
m_FlyingSpeed = m_FlyingSpeed / 3.6f,
m_FlyingAcceleration = m_FlyingAcceleration,
m_FlyingBraking = m_FlyingBraking,
// converts degrees -> radians
m_FlyingTurning = math.radians(m_FlyingTurning),
m_FlyingAngularAcceleration = math.radians(m_FlyingAngularAcceleration),
m_ClimbAngle = math.radians(m_ClimbAngle),
m_SlowPitchAngle = math.radians(m_SlowPitchAngle),
m_TurningRollFactor = m_TurningRollFactor
});
}