Skip to content

Game.UI.InGame.RadioUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: UISystemBase

Summary:
RadioUISystem is the UI system responsible for exposing and synchronizing the in-game radio state with the UI layer. It wires up bindings and triggers for radio settings (volume, paused, muted, skip ads), exposes available networks and stations, provides the current clip metadata to the UI, and reacts to radio events (reload, program change, clip change). It also supports emergency messages and provides logic to focus the camera on an emergency target. The system integrates with AudioManager, SharedSettings, PrefabSystem and the game's camera systems to implement the UI behavior.


Fields

  • private const string kGroup = "radio"
    Radio UI binding group name used for registering bindings and triggers.

  • private PrefabSystem m_PrefabSystem
    Reference to the game's PrefabSystem used to resolve prefabs (used when writing emergency messages).

  • private Radio m_Radio
    Cached reference to the runtime Radio instance (AudioManager.instance.radio). Used to read/update radio state and subscribe to radio events.

  • private GamePanelUISystem m_GamePanelUISystem
    Reference to the game-panel UI system; used to register the radio panel as the default UI arguments.

  • private CameraUpdateSystem m_CameraUpdateSystem
    Reference to the camera update system used to focus the camera on emergency targets.

  • private ValueBinding<bool> m_PausedBinding
    Value binding that reflects whether the radio is paused.

  • private ValueBinding<bool> m_MutedBinding
    Value binding that reflects whether the radio is muted.

  • private ValueBinding<bool> m_SkipAds
    Value binding that reflects whether ad skipping is enabled.

  • private GetterValueBinding<Radio.RadioNetwork[]> m_NetworksBinding
    Getter binding exposing the available radio networks to the UI.

  • private GetterValueBinding<Radio.RuntimeRadioChannel[]> m_StationsBinding
    Getter binding exposing the available runtime radio channels (stations) to the UI.

  • private ValueBinding<ClipInfo> m_CurrentSegmentBinding
    Value binding holding the current clip/segment metadata (title, info) for the UI.

  • private EventBinding m_SegmentChangedBinding
    Event binding used to notify the UI when the current segment/clip changes.

  • private Dictionary<string, string> m_LastSelectedStations
    Keeps the last selected station name per network (keyed by network name). Used to restore a previously-selected station when switching networks.

  • private CachedLocalizedStringBuilder<string> m_EmergencyMessages
    Cached localized string builder for emergency messages keyed by prefab name. Used when exposing emergency message text to the UI.

Properties

  • This class does not expose public properties.

Constructors

  • public RadioUISystem()
    Default constructor. Marked with [Preserve] in code; the system is created/managed by the ECS world.

Methods

  • protected override void OnCreate()
    Initializes the system. Obtains references to PrefabSystem, Radio, GamePanelUISystem and CameraUpdateSystem. Registers UI bindings and triggers for radio state (enabled, volume, paused, muted, skipAds, emergency info, selected network/station, networks, stations and current segment). Caches emergency message localization and subscribes to radio events (Reloaded, ProgramChanged, ClipChanged). Also sets the default UI args (RadioPanel) for the game panel.

  • protected override void OnDestroy()
    Unsubscribes from radio events (Reloaded, ProgramChanged, ClipChanged) and calls base.OnDestroy.

  • private void WriteEmergencyMessage(IJsonWriter writer, Entity entity)
    JSON writer helper used by a GetterValueBinding to write the emergency message text. If an emergency entity is set, resolves the prefab and writes a localized emergency message string; otherwise writes null.

  • private AudioAsset.Metatag GetMetaType(Radio.SegmentType type)
    Returns the appropriate AudioAsset.Metatag for a segment type (Playlist => Artist, Commercial => Brand, default => Artist). Used when interpreting metadata types.

  • private ClipInfo GetClipInfo(Radio radio, AudioAsset asset)
    Builds and returns a ClipInfo instance for the provided AudioAsset and radio state. If the asset is music (meta Type == "Music"), title/artist metadata are used. Otherwise, falls back to channel/program names. Returns null when no asset is available.

  • private ClipInfo GetCurrentClipInfo()
    Convenience wrapper that returns clip info for the system's current radio clip.

  • private void OnClipChanged(Radio radio, AudioAsset asset)
    Event handler invoked when the current clip changes. Triggers station updates and updates the current segment binding with new clip info.

  • private void OnRadioReloaded(Radio radio)
    Event handler invoked when radio data is reloaded (e.g., assets or descriptors changed). Updates network and station bindings and syncs the skip-ads binding.

  • private void OnProgramChanged(Radio radio)
    Event handler invoked when a radio program changes. Triggers station updates so UI reflects latest program info.

  • private void SetVolume(float volume)
    Trigger method to set the shared radio volume setting and apply audio settings (writes to SharedSettings.instance.audio.radioVolume and calls Apply()).

  • private void SetPaused(bool paused)
    Trigger method to set the radio paused state and update the m_PausedBinding.

  • private void SetMuted(bool muted)
    Trigger method to set the radio muted state and update the m_MutedBinding.

  • private void SetSkipAds(bool skipAds)
    Trigger method to set the radio skip-ads setting and update the m_SkipAds binding.

  • private void PlayPrevious()
    Trigger method that instructs the radio to play the previous song (AudioManager.instance.radio.PreviousSong()).

  • private void PlayNext()
    Trigger method that instructs the radio to play the next song (AudioManager.instance.radio.NextSong()).

  • private void FocusEmergency()
    Trigger method to focus the camera on the current radio emergency target. If the orbit camera controller and an emergency target exist, sets the orbit camera to follow that entity and makes it the active camera controller.

  • private void SelectNetwork(string name)
    Trigger method to select a network by name. If a last selected station for that network exists in m_LastSelectedStations, it restores that station. Otherwise, it selects the first station found for the requested network.

  • private void SelectStation(string name)
    Trigger method to switch the radio to the station identified by name. Saves the previously-selected station name for the previous channel's network so it can be restored later.

  • public class ClipInfo : IJsonWritable
    Nested data class used to represent a clip/segment for JSON output and UI consumption. Contains:

  • public string title — title of the clip or channel/program name fallback.
  • public string info — additional info such as artist or program name (nullable).
  • public void Write(IJsonWriter writer) — implements IJsonWritable to write this object as a JSON object with keys "title" and "info".

Usage Example

// From a mod or other system you can control the radio via AudioManager and SharedSettings.
// Example: select a station, set volume, and advance to the next track.

var radio = AudioManager.instance.radio;

// select a station by name (must exist in radio.radioChannelDescriptors)
var channel = radio.GetRadioChannel("Smooth Jazz FM");
if (channel != null)
{
    radio.currentChannel = channel;
}

// set volume to 50% and apply
SharedSettings.instance.audio.radioVolume = 0.5f;
SharedSettings.instance.audio.Apply();

// play next song
AudioManager.instance.radio.NextSong();