Skip to content

Game.Prefabs.ExtractorFacility

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a building prefab for an extractor facility (resource extraction building). Exposes authoring fields for placement rotation range, height offset and whether route/network connections are required. When the prefab is instantiated into an ECS entity the class populates component sets required for runtime (ExtractorFacilityData and UpdateFrameData), converts configured rotation limits to radians, copies the height offset, and sets extractor requirement flags (route/net). The class is annotated with ComponentMenu("Buildings/", typeof(BuildingPrefab)) so it appears in the building prefab menu.


Fields

  • public Bounds1 m_RotationRange
    Stores minimum/maximum rotation for the placed building in degrees (authoring). During initialization these values are converted to radians and stored in the ExtractorFacilityData component.

  • public Bounds1 m_HeightOffset
    Height offset bounds applied to the building placement; copied directly into ExtractorFacilityData.m_HeightOffset.

  • public bool m_RouteNeeded
    Authoring flag indicating whether the extractor requires a route connection. If true, Initialize sets the ExtractorRequirementFlags.RouteConnect bit.

  • public bool m_NetNeeded
    Authoring flag indicating whether the extractor requires a network connection. If true, Initialize sets the ExtractorRequirementFlags.NetConnect bit.

Properties

  • None

Constructors

  • public ExtractorFacility()
    Default parameterless constructor (implicit). No custom construction logic in the source.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime component types required on the prefab entity representation:
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype component types required on instantiated building entities:

  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Populates component data for the entity:

  • Creates an ExtractorFacilityData instance.
  • Converts m_RotationRange.min/max from degrees to radians using math.radians and stores into componentData.m_RotationRange.
  • Copies m_HeightOffset into componentData.m_HeightOffset.
  • Initializes componentData.m_Requirements to ExtractorRequirementFlags.None and sets RouteConnect / NetConnect flags depending on m_RouteNeeded and m_NetNeeded.
  • Writes componentData to the entity (entityManager.SetComponentData).
  • Writes a new UpdateFrameData(14) to the entity to set the update scheduling frame (index 14).

Notes: - The implementation depends on Unity.Mathematics.math for radians conversion. - Uses Unity.Entities EntityManager/Entity to set component data. - ExtractorRequirementFlags and ExtractorFacilityData are expected runtime types that encode runtime behavior and requirements.

Usage Example

// Authoring: configure in inspector
// m_RotationRange = new Bounds1 { min = -45f, max = 45f };
// m_HeightOffset = new Bounds1 { min = 0f, max = 2f };
// m_RouteNeeded = true;
// m_NetNeeded = false;

// At runtime the game calls Initialize(entityManager, entity) for the prefab.
// Example of calling it manually (normally done by the prefab system):

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity prefabEntity = /* entity representing this prefab */;
ExtractorFacility authoring = /* reference to the ExtractorFacility authoring component */;

authoring.Initialize(em, prefabEntity);

// After Initialize:
// - prefabEntity has ExtractorFacilityData with rotation in radians and height offset copied.
// - ExtractorFacilityData.m_Requirements has RouteConnect bit set (because m_RouteNeeded was true).
// - prefabEntity has UpdateFrameData with value 14 for update scheduling.