Game.Prefabs.ServiceChirpPrefab
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ChirpPrefab
Summary:
A prefab class used for service "chirp" triggers that reference an account prefab. Extends ChirpPrefab and ensures the prefab declares and initializes the runtime ServiceChirpData component with a reference to the account entity (when one is assigned). Also exposes the account prefab as a dependency so it is loaded/created alongside this prefab.
Fields
public PrefabBase m_Account
Holds a reference to another PrefabBase (the "account" prefab). If assigned in the editor, this prefab is added to the dependency list and its runtime Entity is stored into the ServiceChirpData component during LateInitialize.
Properties
- None
Constructors
public ServiceChirpPrefab()
No explicit constructor is defined in the source — the class uses the default parameterless constructor inherited/auto-generated.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Overrides ChirpPrefab.GetDependencies. Calls the base implementation and, if m_Account is not null, adds it to the provided prefabs list so the prefab system knows this prefab depends on the account prefab. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Overrides ChirpPrefab.GetPrefabComponents. Calls the base and adds ComponentType.ReadWrite() to the component set, indicating that instances of this prefab include the ServiceChirpData component at runtime. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Overrides ChirpPrefab.LateInitialize. Calls base.LateInitialize, then obtains the PrefabSystem from the world. If m_Account is assigned, resolves the PrefabBase to its runtime Entity via PrefabSystem.GetEntity(m_Account) and writes that Entity into the ServiceChirpData component on the given entity (entityManager.SetComponentData).
Additional notes: - The class is annotated with [ComponentMenu("Triggers/", new Type[] { })], exposing it in the editor's component/prefab menus under "Triggers/". - ServiceChirpData is expected to be a struct component with at least a field named m_Account of type Entity.
Usage Example
// Example: how the prefab initializes the ServiceChirpData (mirror of LateInitialize behavior)
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
var prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();
if (m_Account != null)
{
Entity accountEntity = prefabSystem.GetEntity(m_Account);
entityManager.SetComponentData(entity, new ServiceChirpData { m_Account = accountEntity });
}
}
// Example: how a system or other code can read the ServiceChirpData at runtime
public void UseServiceChirp(EntityManager entityManager, Entity chirpEntity)
{
if (entityManager.HasComponent<ServiceChirpData>(chirpEntity))
{
ServiceChirpData data = entityManager.GetComponentData<ServiceChirpData>(chirpEntity);
Entity accountEntity = data.m_Account;
// Use accountEntity as needed (e.g., query further components, send messages, etc.)
}
}