5 using RyleRadio.Tracks;
16 public class StationRadioTrackEditor : PropertyDrawer
19 private int lastTrackWSize = -1;
22 private bool isShowingThreshold =
false;
25 private bool showTrackInParent =
true;
30 public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label)
32 SerializedProperty trackWs = _property.FindPropertyRelative(
"stationTrackWs");
34 SerializedProperty isRandom = _property.FindPropertyRelative(
"randomSequence");
35 SerializedProperty threshold = _property.FindPropertyRelative(
"thresholdBeforeRepeats");
37 _position.position +=
new Vector2(24, 0);
38 _position.width -= 24;
41 Rect dropdownRect =
new(_position.position -
new Vector2(24, 0),
new Vector2(0, 20));
42 Rect isRandomRect = dropdownRect;
47 Rect thresholdSliderRect = isRandomRect;
49 isRandomRect.width = _position.width;
53 thresholdSliderRect.y += 20 + isRandomRect.height;
54 thresholdSliderRect.width = _position.width;
57 if (lastTrackWSize < 0)
58 lastTrackWSize = trackWs.arraySize;
60 showTrackInParent = EditorGUI.Foldout(dropdownRect, showTrackInParent, _label);
62 if (showTrackInParent)
65 if (EditorGUI.Toggle(isRandomRect,
new GUIContent(
"Random Sequence"), isRandom.boolValue))
67 isRandom.boolValue =
true;
68 isShowingThreshold =
true;
71 EditorGUI.Slider(thresholdSliderRect, threshold, 0, 1,
new GUIContent(
"Threshold Before Repeats"));
75 isRandom.boolValue =
false;
76 isShowingThreshold =
false;
80 _position.position =
new Vector2(
82 _position.position.y + dropdownRect.height + isRandomRect.height + (
84 ? thresholdSliderRect.height + 4
90 EditorGUI.PropertyField(_position, trackWs,
new GUIContent(
"Station Tracks"),
true);
96 if (trackWs.arraySize > lastTrackWSize)
99 SerializedProperty newElement = trackWs.GetArrayElementAtIndex(trackWs.arraySize - 1);
102 SerializedProperty track = newElement.FindPropertyRelative(
"track");
103 SerializedProperty trackType = newElement.FindPropertyRelative(
"trackType");
106 SerializedProperty gain = newElement.FindPropertyRelative(
"gain");
109 track.managedReferenceValue = StationRadioTrackWrapper.CreateTrackEditor(trackType.stringValue);
112 gain.floatValue = 100;
118 else if (trackWs.arraySize < lastTrackWSize)
129 _position.position =
new Vector2(
130 _position.position.x,
131 _position.position.y + dropdownRect.height
136 _property.serializedObject.ApplyModifiedProperties();
143 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
145 if (showTrackInParent)
148 float randomOptionsHeight = 48 + (isShowingThreshold ? 20 : 0);
151 float listHeight = EditorGUI.GetPropertyHeight(property.FindPropertyRelative(
"stationTrackWs"));
154 return randomOptionsHeight + listHeight;
A eventType of RadioTrack that contains other tracks. Has a custom editor in StationRadioTrackEditor ...
Editor scripts for classes and attributes, notably excluding MultiselectAttribute.