Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RadioInteractor.cs
1using NaughtyAttributes;
4using UnityEngine;
5
7{
8 /// <summary>
9 /// A component that performs actions on a radio, such as playing tracks, stopping them, etc
10 /// <br><br>Very useful when writing custom code for a radio, or when using a \ref RadioObserver
11 /// </summary>
12 [AddComponentMenu("Ryle Radio/Radio Interactor")]
14 {
15 /// <summary>
16 /// The tracks that this interactor applies to
17 /// </summary>
18 /// <remarks>Much like in \ref RadioObserver , you need multiple RadioInteractors to perform actions on different track groups</remarks>
19 [Multiselect("TrackNames")]
20 [SerializeField] private int affectedTracks;
21
22 /// <summary>
23 /// The method by which this interactor selects a RadioTrackPlayer when one is needed. For example, if \ref Stop() is called and an affected track has multiple active players, the interactor needs to pick which player to stop- it chooses according to this variable
24 /// </summary>
25 [Foldout("Advanced Settings"), SerializeField]
27
28 /// <summary>
29 /// Whether or not extra debug information should be printed from this component
30 /// </summary>
31 [Foldout("Advanced Settings"), SerializeField]
32 private bool debugAll = false;
33
34
35 /// <summary>
36 /// Plays \ref affectedTracks with looping players
37 /// </summary>
38 public void PlayLoop()
39 {
40 // apply the loop play to all affected tracks
41 DoTrackAction(affectedTracks, id => output.PlayLoop(id));
42 }
43
44 /// <summary>
45 /// Plays \ref affectedTracks with one-shot players
46 /// </summary>
47 public void PlayOneShot()
48 {
49 // apply the oneshot play to all affected tracks
50 DoTrackAction(affectedTracks, id => output.PlayOneShot(id));
51 }
52
53 /// <summary>
54 /// Stops a player on each \ref affectedTracks
55 /// </summary>
56 public void Stop()
57 {
58 // apply the stop to all affected tracks
60 {
61 // if there is a RadioTrackPlayer active for this track,
62 if (output.TryGetPlayer(id, out RadioTrackPlayer player, false, playerSelector))
63 player.Stop(); // stop it
64 else
65 { // otherwise, let us know
66 if (debugAll)
67 Debug.LogWarning($"No players with ID {id} are currently playing, and so none have been stopped!");
68 }
69 });
70 }
71
72 /// <summary>
73 /// Pauses/unpauses a player on each \ref affectedTracks
74 /// </summary>
75 public void FlipPause()
76 {
77 // apply the pause flip to all affected tracks
79 {
80 // if there is a RadioTrackPlayer active for this track,
81 if (output.TryGetPlayer(id, out RadioTrackPlayer player, false, playerSelector))
82 player.Paused = !player.Paused; // pause/unpause it
83 else
84 { // otherwise, let us know
85 if (debugAll)
86 Debug.LogWarning($"No players with ID {id} are currently playing, and so none have been stopped!");
87 }
88 });
89 }
90
91 /// <summary>
92 /// Pauses a player on each \ref affectedTracks
93 /// </summary>
94 public void Pause()
95 {
96 // apply the pause to all affected tracks
98 {
99 // if there is a RadioTrackPlayer active for this track,
100 if (output.TryGetPlayer(id, out RadioTrackPlayer player, false, playerSelector))
101 player.Paused = true; // pause it
102 else
103 { // otherwise, let us know
104 if (debugAll)
105 Debug.LogWarning($"No players with ID {id} are currently playing, and so none have been stopped!");
106 }
107 });
108 }
109
110 /// <summary>
111 /// Unpauses a player on each \ref affectedTracks
112 /// </summary>
113 public void Unpause()
114 {
115 // apply the unpause to all affected tracks
117 {
118 // if there is a RadioTrackPlayer active for this track,
119 if (output.TryGetPlayer(id, out RadioTrackPlayer player, false, playerSelector))
120 player.Paused = false; // unpause it
121 else
122 { // otherwise, let us know
123 if (debugAll)
124 Debug.LogWarning($"No players with ID {id} are currently playing, and so none have been stopped!");
125 }
126 });
127 }
128
129 /// <summary>
130 /// Resets the progress of a player on each \ref affectedTracks
131 /// </summary>
132 public void ResetProgress()
133 {
134 // apply the reset to all affected tracks
136 {
137 // if there is a RadioTrackPlayer active for this track,
138 if (output.TryGetPlayer(id, out RadioTrackPlayer player, false, playerSelector))
139 player.ResetProgress(); // reset its progress (restart the playback)
140 else
141 { // otherwise, let us know
142 if (debugAll)
143 Debug.LogWarning($"No players with ID {id} are currently playing, and so none have been stopped!");
144 }
145 });
146 }
147 }
148
149}
A sister class to RadioComponent that allows a component to access specific tracks on a RadioOutput i...
RadioOutput output
The RadioOutput to get tracks from.
void DoTrackAction(int _trackMask, Action< string > _action)
Performs an action on any selected tracks using a MultiselectAttribute.
A component that performs actions on a radio, such as playing tracks, stopping them,...
void Pause()
Pauses a player on each affectedTracks.
bool debugAll
Whether or not extra debug information should be printed from this component.
void FlipPause()
Pauses/unpauses a player on each affectedTracks.
RadioOutput.MultiplePlayersSelector playerSelector
The method by which this interactor selects a RadioTrackPlayer when one is needed....
void PlayOneShot()
Plays affectedTracks with one-shot players.
int affectedTracks
The tracks that this interactor applies to.
void Unpause()
Unpauses a player on each affectedTracks.
void ResetProgress()
Resets the progress of a player on each affectedTracks.
void PlayLoop()
Plays affectedTracks with looping players.
void Stop()
Stops a player on each affectedTracks.
MultiplePlayersSelector
The method by which a RadioTrackPlayer is chosen from this output. Really only matters when you're pl...
A class that plays a certain RadioTrack at runtime. It's created newly for each track on each RadioOu...
Base interfaces and classes for components, e.g: track accessors, output accessors.
Components to be placed on scene objects, e.g: Outputs, Broadcasters, Observers.
Tracks to be used on a radio- includes base classes.
Definition RadioUtils.cs:20