Game.Prefabs.WaterTower
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component class used to describe and initialize the ECS components for the Water Tower building. This MonoBehaviour (prefab) registers the runtime ECS components required for the water tower: it declares which ComponentType entries belong to the prefab and archetype, and it adds the WaterTowerData component to the created entity when the prefab is initialized. The class is decorated with a ComponentMenu attribute to place it under "Buildings/CityServices/" in the editor and to indicate it is associated with BuildingPrefab and BuildingExtensionPrefab types.
Fields
- This class declares no instance or static fields.
Properties
- This class exposes no properties.
Constructors
public WaterTower()
Creates a new instance of the WaterTower prefab class. The default parameterless constructor is used by Unity when the prefab is instantiated.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds ComponentType entries that should be present on any entity instantiated from this prefab. Implementation details:-
Adds
ComponentType.ReadWrite<WaterTowerData>()
to the provided HashSet, indicating the runtime entity should contain the WaterTowerData component (read/write). -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds ComponentType entries that define the archetype for this prefab's entity. Implementation details: -
Adds
ComponentType.ReadWrite<Game.Buildings.WaterTower>()
— the building archetype component used by the game systems to identify this entity as a water tower building. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called to perform initialization on the newly created entity instance. Implementation details: - Calls
entityManager.AddComponent<WaterTowerData>(entity)
to attach the WaterTowerData component instance to the created entity. This sets up the component storage so game systems can operate on the entity as a water tower.
Additional notes: - WaterTowerData and Game.Buildings.WaterTower are ECS component types (likely struct IComponentData) used by the game's systems. WaterTowerData typically contains runtime state specific to an individual water tower (e.g., capacity, current storage, operational state), while Game.Buildings.WaterTower is used to mark the entity as belonging to the water tower building archetype. - The class itself only declares which components are required and performs a single-component addition during initialization; any further setup of the component data (setting fields) is done elsewhere by game initialization code or systems after the component has been added.
Usage Example
// Example: Initializing an entity using the WaterTower prefab script
var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
// Suppose 'waterTowerPrefab' is a reference to the WaterTower component on a prefab GameObject:
var waterTowerPrefab = someGameObject.GetComponent<Game.Prefabs.WaterTower>();
waterTowerPrefab.Initialize(entityManager, entity);
// After Initialize, the entity will have a WaterTowerData component:
bool hasData = entityManager.HasComponent<WaterTowerData>(entity); // true