Game.Prefabs.SpectatorEvent
Assembly: Game
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component prefab used by the event system to configure a "spectator" style event. Declares default durations for the event phases (preparation, active, termination) and a target site selection type. Marked with the ComponentMenu attribute so it can be added as an event prefab (ComponentMenu("Events/", new Type[] { typeof(EventPrefab) })). At initialization this prefab writes a SpectatorEventData component onto the entity so the runtime event systems can use the configured values.
Fields
-
public EventTargetType m_RandomSiteType
Specifies which type of location to pick for the event when a random site is required. Default in the source is EventTargetType.TransportDepot. -
public float m_PreparationDuration
Duration (in seconds) of the event's preparation phase. Default value in the source is 0.1f. -
public float m_ActiveDuration
Duration (in seconds) of the event's active phase. Default value in the source is 0.1f. -
public float m_TerminationDuration
Duration (in seconds) of the event's termination/cleanup phase. Default value in the source is 0.1f.
Properties
This class exposes no public properties.
Constructors
public SpectatorEvent()
Default parameterless constructor (uses the field defaults defined on the component). Typically the component is configured via inspector on a prefab rather than constructed in code directly.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component type that should be present on the prefab entity instance. Implementation adds ComponentType.ReadWrite() so the data blob representing this event configuration will be present on created entities. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the component types required for the entity archetype. In the source it adds: - ComponentType.ReadWrite
() - ComponentType.ReadWrite
() - ComponentType.ReadWrite
()
These indicate which runtime components the event system expects to exist on the entity.
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is converted/initialized to an ECS entity. This method copies the prefab's inspector-configured fields into a SpectatorEventData instance and writes it to the entity using entityManager.SetComponentData. Concretely it sets m_RandomSiteType, m_PreparationDuration, m_ActiveDuration and m_TerminationDuration into the SpectatorEventData component on the entity.
Usage Example
// Example: configure the prefab component (e.g. in editor or prefab setup)
SpectatorEvent spect = prefabGameObject.AddComponent<SpectatorEvent>();
spect.m_RandomSiteType = EventTargetType.TransportDepot;
spect.m_PreparationDuration = 2.0f;
spect.m_ActiveDuration = 10.0f;
spect.m_TerminationDuration = 1.0f;
// When the prefab is converted to an ECS entity, SpectatorEvent.Initialize(...)
// will copy those values into the entity's SpectatorEventData component:
// (this is effectively what the prefab's Initialize implementation does)
protected override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
SpectatorEventData data = new SpectatorEventData
{
m_RandomSiteType = m_RandomSiteType,
m_PreparationDuration = m_PreparationDuration,
m_ActiveDuration = m_ActiveDuration,
m_TerminationDuration = m_TerminationDuration
};
entityManager.SetComponentData(entity, data);
}
Notes: - SpectatorEventData and the runtime Game.Events.SpectatorEvent component are the ECS-side representations used by event systems; the prefab component merely supplies the initial values. - Adjust durations and target type on the prefab (inspector or code) to control how the event behaves at runtime.