Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RadioBroadcasterEditor.cs
1using UnityEngine;
2
4{
6
7#if UNITY_EDITOR
8 using UnityEditor;
9
10 /// <summary>
11 /// Custom inspector for a \ref RadioBroadcaster
12 /// <br><br>This is mainly so that we can use `Handles` (draggable gizmos).
13 ///
14 /// <b>See: </b> \ref RadioBroadcaster
15 /// </summary>
16 [CustomEditor(typeof(RadioBroadcaster))]
17 public class RadioBroadcasterEditor : Editor
18 {
19 /// <summary>
20 /// The broadcaster this is linked to
21 /// </summary>
22 private RadioBroadcaster broadcaster;
23
24 /// The colour of the gizmo for the x/inner value of \ref RadioBroadcaster.broadcastRadius
25 private Color innerColor;
26 /// The colour of the gizmo for the y/outer value of \ref RadioBroadcaster.broadcastRadius
27 private Color outerColor;
28
29
30 /// <summary>
31 /// Initializes the broadcaster's editor
32 /// </summary>
33 private void OnEnable()
34 {
35 // if the broadcaster's not set, set it
36 if (broadcaster == null)
37 broadcaster = (RadioBroadcaster) target;
38
39 // if the broadcaster has a RadioData assigned, get gizmo colours from it
40 if (broadcaster.Data != null)
41 {
42 innerColor = broadcaster.Data.GizmoColorSecondary;
43 outerColor = broadcaster.Data.GizmoColor;
44 }
45 // otherwise make them white
46 else
47 {
48 innerColor = Color.white;
49 outerColor = Color.white;
50 }
51 }
52
53 /// <summary>
54 /// Displays the handles for \ref RadioBroadcaster.broadcastRadius in the scene
55 /// </summary>
56 private void OnSceneGUI()
57 {
58 // get the radii
59 Vector2 o = broadcaster.broadcastRadius;
60
61 // display the inner radius
62 Handles.color = innerColor;
63 o.x = Mathf.Min(o.y, Handles.RadiusHandle(Quaternion.identity, broadcaster.transform.position, o.x));
64
65 // display the outer radius
66 Handles.color = outerColor;
67 o.y = Mathf.Max(o.x, Handles.RadiusHandle(Quaternion.identity, broadcaster.transform.position, o.y));
68
69 // set the radii
70 broadcaster.broadcastRadius = o;
71 }
72
73 /// <summary>
74 /// Draw the actual inspector as default
75 /// </summary>
76 public override void OnInspectorGUI()
77 {
78 DrawDefaultInspector();
79 }
80 }
81#endif
82
83}
RadioData Data
Read-only accessor for data.
A "broadcaster" for a RadioTrackWrapper - the closer the RadioOutput that's playing the track is to a...
Vector2 broadcastRadius
The inner and outer radii of this broadcaster.
Color GizmoColor
Alias for gizmoColor for safety.
Definition RadioData.cs:42
Color GizmoColorSecondary
Alias for gizmoColorSecondary for safety.
Definition RadioData.cs:44
Components to be placed on scene objects, e.g: Outputs, Broadcasters, Observers.
Editor scripts for classes and attributes, notably excluding MultiselectAttribute.