Game.Prefabs.RadioEvent
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component used on prefab definitions to represent a radio event (a radio segment) that can be emitted by the game's radio system as part of triggers. This prefab component declares the runtime component archetype and writes RadioEventData into the prefab entity during LateInitialize. It exposes the segment type (e.g., News, Music, Emergency) and an emergency-specific frame delay that is only relevant when the segment type is an emergency.
Fields
-
public Radio.SegmentType m_SegmentType = Radio.SegmentType.News
Specifies which radio segment this prefab will request at runtime (e.g., News, Music, Emergency). Default is News. This value is copied into the prefab's RadioEventData during LateInitialize. -
public int m_EmergencyFrameDelay
Only used when m_SegmentType denotes an emergency segment. Configures a frame delay for emergency events. Marked with a Tooltip and shown conditionally in the editor via ShowIf("m_SegmentType", 6, false).
Properties
- This class does not declare any public properties.
Constructors
public RadioEvent()
Implicit default constructor. As a Unity/authoring ComponentBase-derived class this is typically instantiated/attached via the editor or prefab creation workflows; no custom constructor logic is defined.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types required on the prefab entity that represent authoring data used by this prefab at runtime. Implementation adds ComponentType.ReadWrite() so the prefab entity stores RadioEventData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Collects component types that should be present on runtime archetypes created from this prefab. This implementation adds: - ComponentType.ReadWrite
() — the runtime trigger component representing a radio event. - ComponentType.ReadWrite
() — reference back to the prefab.
Note: other components may be added by other ComponentBase-derived components attached to the same prefab; callers typically merge all components from sibling components.
public override void LateInitialize(EntityManager entityManager, Entity entity)
Finalizes prefab initialization by:- Collecting archetype component types from all sibling ComponentBase instances on the prefab.
- Adding Created and Updated marker components.
- Creating an EntityArchetype using the gathered components via PrefabUtils.ToArray.
- Building a RadioEventData struct instance, filling m_Archetype (the created archetype), m_SegmentType and m_EmergencyFrameDelay from this authoring component's fields.
- Writing that RadioEventData into the prefab entity using EntityManager.SetComponentData.
This method ensures that when runtime instances are spawned from the prefab they will use the correct archetype and metadata to produce the configured radio event.
Usage Example
// Example: configure the authoring component on a prefab (typical usage is through the editor).
// If creating via script for a prefab builder:
var radioEvent = gameObject.AddComponent<Game.Prefabs.RadioEvent>();
radioEvent.m_SegmentType = Radio.SegmentType.Emergency;
radioEvent.m_EmergencyFrameDelay = 120; // only relevant for emergency segments
// During prefab build, LateInitialize will be called to write RadioEventData into the prefab entity.
Additional notes: - The class is decorated with [ComponentMenu("Triggers/", ...)] so it appears under Triggers in the component menu. - Runtime types referenced: RadioEventData (authoring -> runtime data), Game.Triggers.RadioEvent (runtime trigger component), PrefabRef, Created, Updated markers. Ensure those types are available when creating or reading prefabs that use this component.