3using System.Collections.Generic;
19 [AddComponentMenu(
"Ryle Radio/Radio Observer")]
64 [SerializeField, Multiselect(
"TrackNames")]
70 [SerializeField]
private List<ObserverEvent>
events;
90 private List<string> TrackNames =>
output !=
null ? output.Data.TrackNames :
new() {
"Output not assigned!" };
122 output.Observers.Add(
this);
130 output.Observers.Remove(
this);
140 List<Action> locUpdate;
149 foreach (Action a
in locUpdate)
184 _player.OnVolume += (player, volume) => {
ValueEvent(e, volume); };
188 _player.OnGain -= (player, gain) => {
ValueEvent(e, gain); };
192 _player.OnTunePower += (player, tunePower) => {
ValueEvent(e, tunePower); };
196 _player.OnBroadcastPower += (player, power) => {
ValueEvent(e, power); };
200 _player.OnInsulation += (player, insulation) => {
ValueEvent(e, insulation); };
214 output.OnTune += (tune) => {
ValueEvent(e, tune); };
240 Debug.LogWarning($
"Attempting to use the FloatEvent method on trigger event {_event}! To fix, either modify the NeedComparison property in ObserverEvent, or change the method used in AssignEvents to TriggerEvent.");
252 _event.staying =
true;
277 _event.staying =
false;
A singular event inside a RadioObserver, tracking a value or trigger and invoking methods accordingly...
UnityEvent< float > onTrigger
Called when eventType is fulfilled for the first time. Only called once until onEnd is called.
UnityEvent< float > onStay
Called every frame while eventType is fulfilled, including the first. Cannot be called if eventType i...
bool NeedComparison
Does this event need a value or range to compare to?
EventType eventType
The type of event this is looking for.
bool EvaluateComparison(float _cValue)
If this event uses a comparison, check if its fulfilled.
bool staying
Tracks if this event has been called in this or the previous frame.
UnityEvent< float > onEnd
Called when eventType is no longer fulfilled. Only called once until the event is fulfilled again....
A component used to watch for specific happenings on a RadioOutput, e.g: a clip being a certain volum...
List< ObserverEvent > events
The events that this Observer responds uses, containing values/triggers to watch for and events to ca...
void TriggerEvent(ObserverEvent _event)
A generic method tracking if an ObserverEvent's trigger has been called. E.g: a track has just starte...
RadioOutput output
The RadioOutput this observer is attached to.
string[] affectedTrackNames
affectedTracks as a list of names rather than a flag int. Created and cached in AffectedTracks
int affectedTracks
The tracks that this observer is watching for events on. This is a flag int and is translated to a li...
void OnDestroy()
Detaches this Observer from output.
string[] AffectedTracks
The tracks selected on this Observer.
EventType
The event an observer is looking for.
@ TunePower
The tune power of the track: how close the RadioOutput.Tune value is to the range of the track.
@ Gain
The gain of the track: this is currently defined exclusively in the track's gain variable.
@ OutputVolume
The volume of the track: tune power * broadcast power * insulation.
@ None
Empty, mainly to temporarily disable an event without deleting it.
@ TrackEnds
The track ends, or loops- this is a Trigger event.
@ OutputTune
The tune on the RadioOutput is changed.
@ BroadcastPower
The broadcast power of the track: how close to any active RadioBroadcasters the output's transform is...
@ Insulation
The insulation of the track: the higher the value the less insulation- the power of any RadioInsulato...
@ TrackStarts
The track starts, or loops (happens after TrackEnds)- this is a Trigger event.
void AssignEvents(RadioTrackPlayer _player)
Assigns each event to a RadioTrackPlayer for one of our AffectedTracks. This is called when a new Rad...
void Awake()
Attaches the Observer to output.
void ValueEvent(ObserverEvent _event, float _value)
A generic method letting an ObserverEvent tracking a value watch for its change.
ComparisonType
The method of comparisonType used for an event. For example, checking if the volume is greater than a...
@ GreaterThanOrEqual
The value is greater than a number.
@ BetweenExclusive
The value is between numbers x and y, including if it's equal to x or y.
@ LessThanOrEqual
The value is less than a number.
@ LessThan
The value is greater than or equal to a number.
@ BetweenInclusive
The value is less than or equal to a number.
@ GreaterThan
The value is equal to a number.
void Update()
Run the buffered events and reset for the next frame.
List< Action > toDoOnUpdate
A buffer for events to run on Update. We cannot call UnityEvents in the audio thread,...
List< ObserverEvent > stayedEvents
A tracker for which ObserverEvents have been called for this specific frame- prevents us from calling...
The main scene component for a radio that plays it through an AudioSource.
A custom attribute that allows ints to display as a multiselect dropdown for a given collection,...
A class that plays a certain RadioTrack at runtime. It's created newly for each track on each RadioOu...
Components to be placed on scene objects, e.g: Outputs, Broadcasters, Observers.
Tracks to be used on a radio- includes base classes.