Game.Prefabs.FlyingAnimal
Assembly:
Assembly-CSharp (typical for game scripts; replace with actual assembly if different)
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
FlyingAnimal is a prefab/component used by the game to configure flying creature prefabs. It exposes editable fields for flight speed and flight height range and, on entity initialization, writes those values into the runtime AnimalData component (converting the speed from km/h to m/s). It is exposed in the prefab editor under the "Creatures/" menu and associated with AnimalPrefab via the ComponentMenu attribute.
Fields
-
public float m_FlySpeed = 100f
Stores the configured flight speed in kilometers per hour (km/h) in the prefab. During Initialize this value is converted to meters per second (m/s) by dividing by 3.6 and saved into the AnimalData component. -
public Bounds1 m_FlyHeight = new Bounds1(20f, 100f)
Defines the flight height range for the animal as a Bounds1 (min, max) in world units (meters). This value is copied directly into the AnimalData component on Initialize.
Properties
- (none)
Constructors
public FlyingAnimal()
Default (compiler-provided) constructor. The default field values are m_FlySpeed = 100f and m_FlyHeight = new Bounds1(20f, 100f).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Intended to add required ECS ComponentType entries for the prefab's entity archetype. In this class the override is empty, so no components are added here. When authoring prefabs that use this component, ensure the corresponding AnimalData component is present in the prefab/archetype elsewhere (otherwise Initialize expects AnimalData to already exist and will throw at runtime). -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Same purpose as GetPrefabComponents but for archetype construction. Also empty here. If your mod needs the prefab to automatically include AnimalData or other ECS components, add the appropriate ComponentType entries here. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into an ECS entity. Implementation: - Calls base.Initialize(entityManager, entity).
- Reads the existing AnimalData component from the entity (entityManager.GetComponentData
(entity)). - Sets componentData.m_FlySpeed = m_FlySpeed / 3.6f (converts km/h to m/s).
- Sets componentData.m_FlyHeight = m_FlyHeight.
- Writes the modified AnimalData back to the entity (entityManager.SetComponentData(entity, componentData)).
Notes: - This method assumes the entity already has an AnimalData component. Ensure your prefab/archetype includes AnimalData. - The conversion (divide by 3.6) converts the designer-facing units (km/h) to simulation units used at runtime (m/s).
Usage Example
// Example: configuring a flying animal prefab in code or inspecting initialization effects.
// (In practice this component is edited in the prefab editor; shown here for modders.)
[ComponentMenu("Creatures/", new Type[] { typeof(AnimalPrefab) })]
public class CustomFlyingAnimal : FlyingAnimal
{
public CustomFlyingAnimal()
{
// set designer-facing values (km/h and meters)
m_FlySpeed = 120f; // 120 km/h shown in editor
m_FlyHeight = new Bounds1(30f, 120f); // min 30m, max 120m
}
// Optionally add required ECS components to archetype/prefab so Initialize won't fail:
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{
base.GetArchetypeComponents(components);
// ensure an AnimalData component exists on the entity
components.Add(ComponentType.Create<AnimalData>(true));
// add other components required by your animal (e.g., position/rotation, movement, etc.)
}
}
// At runtime, when the prefab entity is created, FlyingAnimal.Initialize will run and:
// - store 120f/3.6f (= 33.333... m/s) into AnimalData.m_FlySpeed
// - store the Bounds1(30f, 120f) into AnimalData.m_FlyHeight
Additional notes for modders: - Bounds1 is a simple min/max struct (from Colossal.Mathematics). Use it to express ranges (height bounds here). - Because GetPrefabComponents/GetArchetypeComponents are empty, double-check that the prefab has the required runtime components (AnimalData) before relying on Initialize. - The ComponentMenu attribute determines how this component appears in the in-editor component list (under "Creatures/").