Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RadioOutputTrackAccessor.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
6{
7
8 /// <summary>
9 /// A sister class to \ref RadioComponent that allows a component to access specific tracks on a \ref RadioOutput in the inspector using an int with a \ref MultiselectAttribute <br><b>See: </b>\ref RadioInsulator
10 /// </summary>
11 public abstract class RadioOutputTrackAccessor : MonoBehaviour
12 {
13 /// <summary>
14 /// The RadioOutput to get tracks from
15 /// </summary>
16 [SerializeField] protected RadioOutput output;
17
18 /// <summary>
19 /// The names of tracks available in the Output
20 /// </summary>
21 protected List<string> TrackNames => output != null
22 ? output.Data.TrackNames
23 : new() { "Output not assigned!" };
24
25 /// <summary>
26 /// Performs an action on any selected tracks using a \ref MultiselectAttribute
27 /// </summary>
28 /// <param name="_trackMask">The int with the \ref MultiselectAttribute that the player uses to select tracks from the Output</param>
29 /// <param name="_action">The action to perform on the tracks</param>
30 protected void DoTrackAction(int _trackMask, Action<string> _action)
31 {
32 // convert the multiselect to a list of track indexes
33 int[] wrapperIndexes = MultiselectAttribute.ToInt(_trackMask);
34
35 // perform the action on each track selected using their indexes
36 foreach (int index in wrapperIndexes)
37 _action.Invoke(output.Data.TrackIDs[index]);
38 }
39 }
40
41}
A sister class to RadioComponent that allows a component to access specific tracks on a RadioOutput i...
List< string > TrackNames
The names of tracks available in the Output.
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.
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,...
static int[] ToInt(int _flags)
Shorthand for MultiselectAttribute.To<int>(_flags, _options). Useful for converting a multiselect to ...
Base interfaces and classes for components, e.g: track accessors, output accessors.