Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RadioInsulatorEditor.cs
1using UnityEngine;
2
3namespace RyleRadio.Editor
4{
5 using RyleRadio.Components;
6
7#if UNITY_EDITOR
8 using UnityEditor;
9 using UnityEditor.IMGUI.Controls; // we have to use imgui handles rather than unity handles in order to have draggable boxes
10
11 /// <summary>
12 /// Custom inspector for a \ref RadioInsulator
13 /// <br><br>This is mainly so that we can use `Handles` (draggable gizmos).
14 ///
15 /// <b>See: </b> \ref RadioInsulator
16 /// </summary>
17 [CustomEditor(typeof(RadioInsulator))]
18 public class RadioInsulatorEditor : Editor
19 {
20 /// <summary>
21 /// The insulator this is linked to
22 /// </summary>
23 private RadioInsulator insulator = null;
24
25 /// The draggable gizmo for the outer bounds of the insulator
26 private readonly BoxBoundsHandle outerBoundsHandle = new();
27 /// The draggable gizmo for the inner bounds of the insulator
28 private readonly BoxBoundsHandle innerBoundsHandle = new();
29
30
31 /// <summary>
32 /// Initializes the insulator's editor
33 /// </summary>
34 private void OnEnable()
35 {
36 // get the insulator itself
37 if (insulator == null)
38 insulator = (RadioInsulator)target;
39
40 if (insulator.Data != null)
41 {
42 // assign any changed colours from the radio data
43 outerBoundsHandle.SetColor(insulator.Data.GizmoColor);
44 innerBoundsHandle.SetColor(insulator.Data.GizmoColorSecondary);
45 }
46 }
47
48 /// <summary>
49 /// Displays the handles for \ref RadioInsulator.innerBoxSize and \ref RadioInsulator.outerBoxSize in the scene
50 /// </summary>
51 private void OnSceneGUI()
52 {
53 // if this doesn't have the insulator for some reason, get it
54 if (insulator == null)
55 insulator = (RadioInsulator)target;
56
57 // get the boundaries of the insulator
58 Bounds outerBounds = new(insulator.transform.position, insulator.outerBoxSize);
59 Bounds innerBounds = new(insulator.transform.position, insulator.innerBoxSize);
60
61 // apply the outer boundary info to one of the handles
62 outerBoundsHandle.center = outerBounds.center;
63 outerBoundsHandle.size = insulator.transform.localToWorldMatrix * outerBounds.size;
64
65 // apply the inner boundary info to one of the handles
66 innerBoundsHandle.center = innerBounds.center;
67 innerBoundsHandle.size = insulator.transform.localToWorldMatrix * innerBounds.size;
68
69 // capture any changes made to the handle
70 EditorGUI.BeginChangeCheck();
71 outerBoundsHandle.DrawHandle();
72 if (EditorGUI.EndChangeCheck())
73 {
74 // if changes were detected, save them to the undo record and apply the changes
75 Undo.RecordObject(insulator, "Change Outer Bounds");
76 insulator.outerBoxSize = insulator.transform.worldToLocalMatrix * outerBoundsHandle.size;
77 }
78
79 // capture any changes made to the handle
80 EditorGUI.BeginChangeCheck();
81 innerBoundsHandle.DrawHandle();
82 if (EditorGUI.EndChangeCheck())
83 {
84 // if changes were detected, save them to the undo record and apply the changes
85 Undo.RecordObject(insulator, "Change Inner Bounds");
86 insulator.innerBoxSize = insulator.transform.worldToLocalMatrix * innerBoundsHandle.size;
87 }
88 }
89
90 /// <summary>
91 /// Draw the actual inspector as default
92 /// </summary>
93 public override void OnInspectorGUI()
94 {
95 DrawDefaultInspector();
96 }
97 }
98
99#endif
100}
RadioData Data
Read-only accessor for data.
An "insulator" for a RadioTrackWrapper - if a RadioOutput is inside the bounds of this object,...
Vector3 outerBoxSize
The size of the outer box of the insulator- outside of this box, insulation is 0- between this and th...
Vector3 innerBoxSize
The size of the inner box of the insulator- inside of this box, insulation is the highest.
Color GizmoColor
Alias for gizmoColor for safety.
Definition RadioData.cs:42
Color GizmoColorSecondary
Alias for gizmoColorSecondary for safety.
Definition RadioData.cs:44
Editor scripts for classes and attributes, notably excluding MultiselectAttribute.