Game.Prefabs.XPParametersPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that exposes XP-related tuning values (XP per population and XP per happiness) and applies them to an entity by writing an XPParameterData component during LateInitialize. The class is annotated with ComponentMenu("Settings/") so it can be placed in Unity's component menu for configuration in the editor.
Fields
-
public float m_XPPerPopulation
Holds the XP-per-population value configured on the prefab. During LateInitialize this value is copied into the XPParameterData.m_XPPerPopulation field on the runtime entity. -
public float m_XPPerHappiness
Holds the XP-per-happiness value configured on the prefab. During LateInitialize this value is copied into the XPParameterData.m_XPPerHappiness field on the runtime entity.
Properties
- This class does not expose any public properties.
Constructors
public XPParametersPrefab()
Default constructor (implicit). No special runtime construction logic in the class itself.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Ensures the prefab declares the runtime components required for entities created from this prefab. This override calls base.GetPrefabComponents(components) and then addsComponentType.ReadWrite<XPParameterData>()
so the entity has an XPParameterData component available for SetComponentData during initialization. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Override present but only calls the base implementation. No additional components are added to the archetype here. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Copies the prefab field values into the runtime component on the provided entity. Specifically it performs: entityManager.SetComponentData(entity, new XPParameterData { m_XPPerHappiness = m_XPPerHappiness, m_XPPerPopulation = m_XPPerPopulation }); Because GetPrefabComponents adds XPParameterData, this SetComponentData call is safe (the component is present on the entity).
Usage Example
// Example: prefab configured in inspector (m_XPPerPopulation = 0.5f, m_XPPerHappiness = 1.2f)
// During prefab -> entity conversion the engine will call LateInitialize and write the data:
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// After this call the entity will contain an XPParameterData component with values from the prefab.
// No additional code required here beyond what the prefab already implements.
}
Notes: - The prefab class is annotated with [ComponentMenu("Settings/", new Type[] { })], making it available under Settings in Unity's Add Component menu. - The runtime-side component type expected is XPParameterData (must exist in the project). This prefab initializes that component with the two float values.