Game.Prefabs.PostServiceConfigurationPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that provides configuration data for the game's postal/post service. Holds a reference to the ServicePrefab used for post service and several mail-related tuning values (maximum accumulation, tolerance, percentage of outgoing mail). At initialization it converts the referenced ServicePrefab into an ECS entity and writes a PostConfigurationData component on the prefab entity so runtime systems can read the configuration. The class is registered in the Unity editor menu via a ComponentMenu attribute ("Settings/").
Fields
-
public ServicePrefab m_PostServicePrefab
Reference to the ServicePrefab used for the post service. This prefab is converted to an Entity in LateInitialize and stored in the PostConfigurationData. -
public int m_MaxMailAccumulation
Maximum amount of mail that can accumulate (default 2000). -
public int m_MailAccumulationTolerance
Tolerance value used by mail accumulation logic (default 10). -
public int m_OutgoingMailPercentage
Percentage of mail that will be sent out as outgoing mail (default 15).
Properties
public override bool ignoreUnlockDependencies { get; }
Always returns true in this prefab. This indicates the prefab ignores unlock dependencies (likely meaning it is available irrespective of other unlock conditions).
Constructors
public PostServiceConfigurationPrefab()
No explicit constructor is declared in the source; the default constructor is used. Initialization of default field values is done inline on the fields.
Methods
-
public override void GetDependencies(System.Collections.Generic.List<PrefabBase> prefabs)
Adds dependent prefabs to the provided list. This implementation calls the base GetDependencies and then adds m_PostServicePrefab so the post service prefab is ensured to be available/loaded as a dependency. -
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds the PostConfigurationData component type to the prefab's component set via ComponentType.ReadWrite(). This declares that the prefab entity will have (read/write) the PostConfigurationData component at creation. -
public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Converts the referenced service prefab to an Entity and writes a PostConfigurationData component to the given entity. It retrieves the PrefabSystem from the world to map the ServicePrefab asset to its corresponding entity, then sets PostConfigurationData with m_PostServicePrefab (entity), m_MaxMailAccumulation, m_MailAccumulationTolerance, and m_OutgoingMailPercentage so runtime systems can access these values.
Implementation details:
- Uses entityManager.World.GetOrCreateSystemManaged
Usage Example
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
PrefabSystem prefabSystem = entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
entityManager.SetComponentData(entity, new PostConfigurationData
{
m_PostServicePrefab = prefabSystem.GetEntity(m_PostServicePrefab),
m_MaxMailAccumulation = m_MaxMailAccumulation,
m_MailAccumulationTolerance = m_MailAccumulationTolerance,
m_OutgoingMailPercentage = m_OutgoingMailPercentage
});
}