Game.Prefabs.RouteModifiers
Assembly: Assembly-CSharp (game assembly containing most game/mod code)
Namespace: Game.Prefabs
Type: public class RouteModifiers
Base: ComponentBase
Summary:
RouteModifiers is a prefab component used to configure route modifiers on an entity (for example, policy prefabs). It exposes an array of RouteModifierInfo entries (m_Modifiers) that are converted into a DynamicBuffer
Fields
public RouteModifierInfo[] m_Modifiers
Array of route modifier definitions assigned in the prefab. Each RouteModifierInfo is expected to contain fields such as m_Type, m_Mode and m_Range. During Initialize, each element is converted into a RouteModifierData and added to the entity's RouteModifierData buffer. This array may be null; the code guards against that.
Properties
- None (no public properties are declared by this class)
Constructors
public RouteModifiers()
Default parameterless constructor (compiler-provided). No custom construction logic in the source file.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component type that this prefab supplies to the target prefab/entity. Implementation adds ComponentType.ReadWrite(), indicating that entities instantiated from this prefab will have a RouteModifierData buffer component available. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. No additional archetype-time components are added here beyond what GetPrefabComponents declares. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is initialized on an entity. Calls base.Initialize, then if m_Modifiers is not null it retrieves the DynamicBufferfor the entity and appends a RouteModifierData entry for each RouteModifierInfo in m_Modifiers using routeModifierInfo.m_Type, routeModifierInfo.m_Mode and routeModifierInfo.m_Range.
Notes:
- Because GetPrefabComponents registers RouteModifierData as a prefab component, entityManager.GetBuffer
Usage Example
// RouteModifiers is a prefab component. Typical usage is inside a prefab initialization step.
// When an entity is created from the prefab, Initialize will populate its RouteModifierData buffer.
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// if m_Modifiers was set on the prefab in the editor, add each as RouteModifierData to the entity's buffer
if (m_Modifiers != null)
{
DynamicBuffer<RouteModifierData> buffer = entityManager.GetBuffer<RouteModifierData>(entity);
for (int i = 0; i < m_Modifiers.Length; i++)
{
RouteModifierInfo info = m_Modifiers[i];
buffer.Add(new RouteModifierData(info.m_Type, info.m_Mode, info.m_Range));
}
}
}
Additional remarks: - Place the RouteModifiers component on policy prefabs (or other relevant prefabs) in the editor to have their route modifiers applied to spawned entities. - Ensure that RouteModifierInfo and RouteModifierData types match the expected constructor/field layout used here.