Game.Prefabs.GroupAmbience
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase, IZoneBuildingComponent
Summary:
GroupAmbience is a prefab component used to attach a group ambience type to zone and building prefabs. It exposes a single editable field (m_AmbienceType) which is written into the ECS component GroupAmbienceData when a prefab or building entity is initialized. The class is exposed in the editor's component menu under "Zones/" (via the ComponentMenu attribute) and is intended to be used with zone prefabs and building prefabs that need to carry ambience group information into the runtime entity.
Fields
public GroupAmbienceType m_AmbienceType
This enum field defines which ambience group this prefab should use. When the prefab (or its building) is initialized into an entity, m_AmbienceType is copied into the ECS component GroupAmbienceData.m_AmbienceType. Default value is the enum's default unless set in the prefab.
Properties
- (none)
This component does not declare any .NET properties. All data is exposed via the public field and the GroupAmbienceData ECS component.
Constructors
public GroupAmbience()
Default parameterless constructor (compiler-provided). The component relies on the prefab's serialized fields (m_AmbienceType) and the Initialize methods to populate ECS component data.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime ECS component required for prefabs: ComponentType.ReadWrite(). This tells the prefab system that entities created from this prefab should include the GroupAmbienceData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No archetype components are added here (method intentionally empty). The prefab component list is handled in GetPrefabComponents. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into an entity. This implementation calls base.Initialize(...) and then sets the GroupAmbienceData on the entity using the serialized m_AmbienceType: entityManager.SetComponentData(entity, new GroupAmbienceData { m_AmbienceType = m_AmbienceType }); -
public void GetBuildingPrefabComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
Adds ComponentType.ReadWrite() for building prefabs as well, indicating that building entities should include GroupAmbienceData when appropriate. -
public void GetBuildingArchetypeComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
No archetype components are added for building-specific archetypes (method intentionally empty). -
public void InitializeBuilding(EntityManager entityManager, Entity entity, BuildingPrefab buildingPrefab, byte level)
Initializes a building entity with GroupAmbienceData if the building prefab does not already declare a GroupAmbience component. The method checks buildingPrefab.Has() and only writes the GroupAmbienceData if the building prefab itself doesn't contain the GroupAmbience component, avoiding overriding explicitly defined building prefab ambience: if (!buildingPrefab.Has<GroupAmbience()) { entityManager.SetComponentData(entity, new GroupAmbienceData { m_AmbienceType = m_AmbienceType }); }
Notes: - The class bridges prefab serialization (m_AmbienceType) and runtime ECS component data (GroupAmbienceData). - The ComponentMenu attribute places this component under "Zones/" in the editor and references ZonePrefab in the attribute.
Usage Example
// The component itself already writes into GroupAmbienceData in Initialize.
// Example: reading the ambience type from an instantiated entity in a system:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
if (entityManager.HasComponent<GroupAmbienceData>(entity))
{
var ambienceData = entityManager.GetComponentData<GroupAmbienceData>(entity);
GroupAmbienceType ambience = ambienceData.m_AmbienceType;
// Use ambience...
}
// Example: the prefab's Initialize already does this - shown here for clarity:
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
entityManager.SetComponentData(entity, new GroupAmbienceData {
m_AmbienceType = this.m_AmbienceType
});
}
See also: GroupAmbienceData, GroupAmbienceType, BuildingPrefab, ComponentBase, IZoneBuildingComponent.