Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RyleRadio.Tracks.RadioTrackWrapper Class Reference

A wrapper class for RadioTrack so that track types can be switched between in the inspector! Also contains various values that are track-agnostic. More...

Public Member Functions

 RadioTrackWrapper ()
 Creates an empty wrapper.
void Init ()
 Initialize this wrapper and its track.
override string ToString ()
 Changes the name of this class from "RadioTrackWrapper" to "Wrapper for `track.Name`".
void CreateTrackLocal ()
 Set track to a new track with eventType defined by trackType
See also: CreateTrackEditor()
void AddToPlayerEndCallback (ref Action< RadioTrackPlayer > _callback)
 Used if track needs to access a RadioTrackPlayer that it's linked to when that player ends, this method adds an event for it. Really only needed for a StationRadioTrack.
float GetTunePower (float _tune, float _otherVolume)
 Calculates the power of this track when an Output is at a specific Tune value. It does this by finding where the Tune is over the track's range, where that point lies on the rangeCurve, and applies attenuation.
float GetSample (int _sampleIndex)
 Get a sample from the contained track.

Static Public Member Functions

static string GetTrackType (string _typeName)
 Converts the typename (NOT display name) of a track eventType to the actual eventType.
static IRadioTrack CreateTrackEditor (string _name)
 Static; creates a new track for a wrapper using the given track eventType's display name.

Public Attributes

string id
 The ID of this track- used to find and manipulate it in custom code.
string name
 The name of this track for use (and easy identification) in the inspector. This is usually in the format of {ID}, {range.x} - {range.y}
Vector2 range
 The range of tunes in which this track can be heard. If a RadioOutput.Tune value is within this range, the tune power of this track will be > 0, and it will be audible (not counting spatial components+gain+etc)
AnimationCurve rangeCurve = new(DefaultRangeCurve.keys)
 The curve defining the loudness of the track over its range. The progress between range.x and range.y the RadioOutput.Tune value is, is the progress along this curve the tune power is.
float attenuation = 0.1f
 The amount that this track gets quieter when another track is playing on top of it (and that other track is above this one in RadioData.trackWs.
bool forceGlobal = true
 If true, this track ignores any RadioBroadcaster influence and plays everywhere.
bool playOnInit = true
 If true, this track plays on RadioData.Init() - usually on game start.
List< RadioBroadcasterbroadcasters
 The broadcasters in the scene that have this track selected.
List< RadioInsulatorinsulators
 The insulators in the scene that have this track selected.

Protected Attributes

IRadioTrack track
 The actual RadioTrack in this wrapper, its eventType chosen in trackType.

Properties

static AnimationCurve DefaultRangeCurve [get]
 The default rangeCurve to use when an empty wrapper is created. It's a super basic and smooth closed curve from 0 to 0.
Action< RadioTrackWrapperOnInit = new(_ => { }) [get, set]
 An event called when the wrapper is initialised.
Action< RadioTrackWrapperBeforeInit = new(_ => { }) [get, set]
 An event called just before the wrapper is initialised.
Action< RadioBroadcaster, RadioTrackWrapperOnAddBroadcaster = new((_, _) => { }) [get, set]
 An event called when a broadcaster is added to the track.
Action< RadioBroadcaster, RadioTrackWrapperOnRemoveBroadcaster = new((_, _) => { }) [get, set]
 An event called when a broadcaster is removed from this track.
Action< RadioInsulator, RadioTrackWrapperOnAddInsulator = new((_, _) => { }) [get, set]
 An event called when an insulator is added to the track.
Action< RadioInsulator, RadioTrackWrapperOnRemoveInsulator = new((_, _) => { }) [get, set]
 An event called when an insulator is removed from this track.
float Gain [get]
 The gain value scaled down to ones- e.g gain at 200 is Gain at 2.
static Type[] TrackTypes [get]
 A list of each eventType of track that this wrapper can contain- this is anything that inherits from IRadioTrack, and updates dynamically when creating new track types.

See also: RadioUtils.FindDerivedTypes()
static string[] TrackTypesAsStrings [get]
 Static; the list of available track types stored as their typename, NOT as their display names. This is used when reassigning track types in RadioDataEditor when the editor reloads, as we only have the typename of the track.
static string[] TrackNames [get]
 Static; the list of track types stored as their display names. This is shown as a dropdown for trackType and is how types are usually displayed in the inspector.
float SampleRate [get]
 An alias for the track's SampleRate as other classes cannot access track directly.
int SampleCount [get]
 An alias for the track's SampleCount as other classes cannot access track directly.

Private Member Functions

void ScaleRange ()
 Limits the number of decimal points on the range
This is called whenever the range is changed.
See: RANGE_DECIMAL_MULTIPLIER.

Private Attributes

float gain = 100
 An added value to the volume of the track. This is applied before any other volume is calculated.
string trackType
 The eventType of track for this wrapper to contain, selectable in the inspector. This variable is stored as the track name and displays with a dropdown according to TrackNames.

Static Private Attributes

const float RANGE_DECIMAL_MULTIPLIER = 10f
 The number of decimal places used in the range- the number of zeroes is the number of decimal points, e.g: 10 == 1dp, 100 == 2dp, 1 == 0dp (whole numbers)

Detailed Description

A wrapper class for RadioTrack so that track types can be switched between in the inspector! Also contains various values that are track-agnostic.

This is how a RadioTrack is stored and accessed in RadioData.
If we didn't use a wrapper like this, you wouldn't be able to choose trackType in a dropdown and see it change in the inspector- it's not possible (to my knowledge) to do that without some kind of wrapper and [SerializeReference].
Wrappers also contain variables that exist for every track eventType, such as range and gain.

Definition at line 19 of file RadioTrackWrapper.cs.

Constructor & Destructor Documentation

◆ RadioTrackWrapper()

RyleRadio.Tracks.RadioTrackWrapper.RadioTrackWrapper ( )

Creates an empty wrapper.

Definition at line 212 of file RadioTrackWrapper.cs.

Member Function Documentation

◆ AddToPlayerEndCallback()

void RyleRadio.Tracks.RadioTrackWrapper.AddToPlayerEndCallback ( ref Action< RadioTrackPlayer > _callback)

Used if track needs to access a RadioTrackPlayer that it's linked to when that player ends, this method adds an event for it. Really only needed for a StationRadioTrack.

Parameters
_callbackThe event called on RadioTrackPlayer.OnEnd

Definition at line 305 of file RadioTrackWrapper.cs.

◆ CreateTrackEditor()

IRadioTrack RyleRadio.Tracks.RadioTrackWrapper.CreateTrackEditor ( string _name)
static

Static; creates a new track for a wrapper using the given track eventType's display name.

Parameters
_nameDisplay name of a track eventType
Returns
The newly created IRadioTrack

Definition at line 274 of file RadioTrackWrapper.cs.

Referenced by CreateTrackLocal().

◆ CreateTrackLocal()

void RyleRadio.Tracks.RadioTrackWrapper.CreateTrackLocal ( )

Set track to a new track with eventType defined by trackType
See also: CreateTrackEditor()

Definition at line 296 of file RadioTrackWrapper.cs.

Referenced by RadioTrackWrapper().

◆ GetSample()

float RyleRadio.Tracks.RadioTrackWrapper.GetSample ( int _sampleIndex)

Get a sample from the contained track.

Parameters
_sampleIndexThe index of the sample to get
Returns
The sample as given by RadioTrack.GetSample()

Definition at line 346 of file RadioTrackWrapper.cs.

◆ GetTrackType()

string RyleRadio.Tracks.RadioTrackWrapper.GetTrackType ( string _typeName)
static

Converts the typename (NOT display name) of a track eventType to the actual eventType.

Parameters
_typeNameThe name of the eventType
Returns
The eventType with that name

Definition at line 263 of file RadioTrackWrapper.cs.

◆ GetTunePower()

float RyleRadio.Tracks.RadioTrackWrapper.GetTunePower ( float _tune,
float _otherVolume )

Calculates the power of this track when an Output is at a specific Tune value. It does this by finding where the Tune is over the track's range, where that point lies on the rangeCurve, and applies attenuation.

Parameters
_tuneThe tune value to evaluate
_otherVolumeThe volume of any previous tracks, used for attenuation
Returns
The tune power of this track with the provided values

Definition at line 330 of file RadioTrackWrapper.cs.

◆ Init()

void RyleRadio.Tracks.RadioTrackWrapper.Init ( )

Initialize this wrapper and its track.

Definition at line 238 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.RadioData.Init().

◆ ScaleRange()

void RyleRadio.Tracks.RadioTrackWrapper.ScaleRange ( )
private

Limits the number of decimal points on the range
This is called whenever the range is changed.
See: RANGE_DECIMAL_MULTIPLIER.

Definition at line 315 of file RadioTrackWrapper.cs.

Member Data Documentation

◆ attenuation

float RyleRadio.Tracks.RadioTrackWrapper.attenuation = 0.1f

The amount that this track gets quieter when another track is playing on top of it (and that other track is above this one in RadioData.trackWs.

Definition at line 77 of file RadioTrackWrapper.cs.

Referenced by GetTunePower().

◆ broadcasters

List<RadioBroadcaster> RyleRadio.Tracks.RadioTrackWrapper.broadcasters

The broadcasters in the scene that have this track selected.

A RadioBroadcaster is a scene component that allows a track to be heard exclusively or louder in a certain area.
See also: insulators

Definition at line 95 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioBroadcaster.AssignToTrack(), Init(), and RyleRadio.Components.RadioBroadcaster.RemoveFromTrack().

◆ forceGlobal

bool RyleRadio.Tracks.RadioTrackWrapper.forceGlobal = true

If true, this track ignores any RadioBroadcaster influence and plays everywhere.

Definition at line 82 of file RadioTrackWrapper.cs.

◆ gain

float RyleRadio.Tracks.RadioTrackWrapper.gain = 100
private

An added value to the volume of the track. This is applied before any other volume is calculated.

Definition at line 71 of file RadioTrackWrapper.cs.

◆ id

string RyleRadio.Tracks.RadioTrackWrapper.id

The ID of this track- used to find and manipulate it in custom code.

Definition at line 38 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.RadioData.PopulateTrackIDs().

◆ insulators

List<RadioInsulator> RyleRadio.Tracks.RadioTrackWrapper.insulators

The insulators in the scene that have this track selected.

A RadioInsulator is a scene component that makes a track quieter in a certain area.
See also: broadcasters

Definition at line 103 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioInsulator.AssignToTrack(), Init(), and RyleRadio.Components.RadioInsulator.RemoveFromTrack().

◆ name

string RyleRadio.Tracks.RadioTrackWrapper.name

The name of this track for use (and easy identification) in the inspector. This is usually in the format of {ID}, {range.x} - {range.y}

This is assigned in RadioDataEditor.InitNewTrack()

Definition at line 45 of file RadioTrackWrapper.cs.

Referenced by ToString().

◆ playOnInit

bool RyleRadio.Tracks.RadioTrackWrapper.playOnInit = true

If true, this track plays on RadioData.Init() - usually on game start.

Definition at line 87 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioOutput.StartPlayers().

◆ range

Vector2 RyleRadio.Tracks.RadioTrackWrapper.range

The range of tunes in which this track can be heard. If a RadioOutput.Tune value is within this range, the tune power of this track will be > 0, and it will be audible (not counting spatial components+gain+etc)

This range is clamped between RadioData.LOW_TUNE and RadioData.HIGH_TUNE

Definition at line 53 of file RadioTrackWrapper.cs.

Referenced by GetTunePower(), and ScaleRange().

◆ RANGE_DECIMAL_MULTIPLIER

const float RyleRadio.Tracks.RadioTrackWrapper.RANGE_DECIMAL_MULTIPLIER = 10f
staticprivate

The number of decimal places used in the range- the number of zeroes is the number of decimal points, e.g: 10 == 1dp, 100 == 2dp, 1 == 0dp (whole numbers)

Definition at line 33 of file RadioTrackWrapper.cs.

Referenced by ScaleRange().

◆ rangeCurve

AnimationCurve RyleRadio.Tracks.RadioTrackWrapper.rangeCurve = new(DefaultRangeCurve.keys)

The curve defining the loudness of the track over its range. The progress between range.x and range.y the RadioOutput.Tune value is, is the progress along this curve the tune power is.

  • If the curve is the default curve (smooth from 0 to 1 to 0), it will smoothly get louder towards the center of the range, and quieter towards the edge.
  • If the curve is a flat line at y=1, it will be the same volume across the entire range
  • If the curve is a line from 0 - 1, it will be louder the further along the range the tune is, getting loudest at range.y
  • If the curve is goes up and down repeatedly, it will be at various different volumes depending on what you set, moving between them along the range

Definition at line 65 of file RadioTrackWrapper.cs.

Referenced by GetTunePower().

◆ track

IRadioTrack RyleRadio.Tracks.RadioTrackWrapper.track
protected

The actual RadioTrack in this wrapper, its eventType chosen in trackType.

We keep this private so that no other classes can access the track directly- this isn't really necessary but it is very safe for custom code

Definition at line 117 of file RadioTrackWrapper.cs.

Referenced by AddToPlayerEndCallback(), CreateTrackLocal(), GetSample(), Init(), and RadioTrackWrapper().

◆ trackType

string RyleRadio.Tracks.RadioTrackWrapper.trackType
private

The eventType of track for this wrapper to contain, selectable in the inspector. This variable is stored as the track name and displays with a dropdown according to TrackNames.

Definition at line 109 of file RadioTrackWrapper.cs.

Referenced by CreateTrackLocal(), and RadioTrackWrapper().

Property Documentation

◆ BeforeInit

Action<RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.BeforeInit = new(_ => { })
getset

An event called just before the wrapper is initialised.

Definition at line 123 of file RadioTrackWrapper.cs.

Referenced by Init().

◆ DefaultRangeCurve

AnimationCurve RyleRadio.Tracks.RadioTrackWrapper.DefaultRangeCurve
staticget

The default rangeCurve to use when an empty wrapper is created. It's a super basic and smooth closed curve from 0 to 0.

Definition at line 24 of file RadioTrackWrapper.cs.

◆ Gain

float RyleRadio.Tracks.RadioTrackWrapper.Gain
get

The gain value scaled down to ones- e.g gain at 200 is Gain at 2.

Definition at line 139 of file RadioTrackWrapper.cs.

◆ OnAddBroadcaster

Action<RadioBroadcaster, RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.OnAddBroadcaster = new((_, _) => { })
getset

An event called when a broadcaster is added to the track.

Definition at line 126 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioBroadcaster.AssignToTrack().

◆ OnAddInsulator

Action<RadioInsulator, RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.OnAddInsulator = new((_, _) => { })
getset

An event called when an insulator is added to the track.

Definition at line 131 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioInsulator.AssignToTrack().

◆ OnInit

Action<RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.OnInit = new(_ => { })
getset

An event called when the wrapper is initialised.

Definition at line 121 of file RadioTrackWrapper.cs.

Referenced by Init().

◆ OnRemoveBroadcaster

Action<RadioBroadcaster, RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.OnRemoveBroadcaster = new((_, _) => { })
getset

An event called when a broadcaster is removed from this track.

Definition at line 128 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioBroadcaster.RemoveFromTrack().

◆ OnRemoveInsulator

Action<RadioInsulator, RadioTrackWrapper> RyleRadio.Tracks.RadioTrackWrapper.OnRemoveInsulator = new((_, _) => { })
getset

An event called when an insulator is removed from this track.

Definition at line 133 of file RadioTrackWrapper.cs.

Referenced by RyleRadio.Components.RadioInsulator.RemoveFromTrack().

◆ SampleCount

int RyleRadio.Tracks.RadioTrackWrapper.SampleCount
get

An alias for the track's SampleCount as other classes cannot access track directly.

Definition at line 206 of file RadioTrackWrapper.cs.

◆ SampleRate

float RyleRadio.Tracks.RadioTrackWrapper.SampleRate
get

An alias for the track's SampleRate as other classes cannot access track directly.

Definition at line 203 of file RadioTrackWrapper.cs.

◆ TrackNames

string [] RyleRadio.Tracks.RadioTrackWrapper.TrackNames
staticgetprivate

Static; the list of track types stored as their display names. This is shown as a dropdown for trackType and is how types are usually displayed in the inspector.

Definition at line 188 of file RadioTrackWrapper.cs.

Referenced by CreateTrackEditor(), and GetTrackType().

◆ TrackTypes

Type [] RyleRadio.Tracks.RadioTrackWrapper.TrackTypes
staticgetprivate

A list of each eventType of track that this wrapper can contain- this is anything that inherits from IRadioTrack, and updates dynamically when creating new track types.

See also: RadioUtils.FindDerivedTypes()

Definition at line 150 of file RadioTrackWrapper.cs.

Referenced by CreateTrackEditor().

◆ TrackTypesAsStrings

string [] RyleRadio.Tracks.RadioTrackWrapper.TrackTypesAsStrings
staticgetprivate

Static; the list of available track types stored as their typename, NOT as their display names. This is used when reassigning track types in RadioDataEditor when the editor reloads, as we only have the typename of the track.

Definition at line 168 of file RadioTrackWrapper.cs.

Referenced by GetTrackType().


The documentation for this class was generated from the following file: