public override void OnInspectorGUI() { ColorizeDrawer.Reset(); var oldColor = GUI.color; GUI.color = ColorizeDrawer.GetColor(""); serializedObject.Update(); var prop = serializedObject.GetIterator(); var targ = (AudioZone)serializedObject.targetObject; bool disabled = false; if (prop.NextVisible(true)) { do { disabled = !(prop.name != "m_Script" && (prop.name != "radius" || targ.trigger == null) && (prop.name != "layerMask" || targ.trigger != null)); EditorGUI.BeginDisabledGroup(disabled); EditorGUILayout.PropertyField(prop); EditorGUI.EndDisabledGroup(); } while (prop.NextVisible(false)); } serializedObject.ApplyModifiedProperties(); GUI.color = oldColor; }
public override void OnInspectorGUI() { ColorizeDrawer.Reset(); var oldColor = GUI.color; GUI.color = ColorizeDrawer.GetColor(""); DrawDefaultInspector(); GUI.color = oldColor; }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { var mp = prop.FindPropertyRelative("min"); var np = prop.FindPropertyRelative("max"); var mm = attribute as MinMaxAttribute; if (mp != null && np != null && mm != null) { var oldColor = GUI.color; if (mm.colorize) { GUI.color = ColorizeDrawer.GetColor(prop.propertyPath); } int i = EditorGUI.indentLevel; float mv = mp.floatValue; float nv = np.floatValue; float dx1 = EditorGUIUtility.fieldWidth * 2 + Mathf.Clamp01(i) * 9; float dx2 = EditorGUIUtility.fieldWidth * 2 + (i - 1) * 9; var r = pos; r.width = r.width - dx1; EditorGUI.MinMaxSlider( r, new GUIContent(ObjectNames.NicifyVariableName(prop.name)), ref mv, ref nv, mm.min, mm.max); EditorGUI.indentLevel = 0; r.x = pos.width - dx2 + i * 9 + 3; r.width = EditorGUIUtility.fieldWidth; var s = new GUIStyle(EditorStyles.numberField); s.fixedWidth = EditorGUIUtility.fieldWidth; mv = EditorGUI.DelayedFloatField(r, mv, s); r.x += EditorGUIUtility.fieldWidth + 2; nv = EditorGUI.DelayedFloatField(r, nv, s); mp.floatValue = Mathf.Min(Mathf.Max(mv, mm.min), Mathf.Min(nv, mm.max)); np.floatValue = Mathf.Max(Mathf.Max(mv, mm.min), Mathf.Min(nv, mm.max)); EditorGUI.indentLevel = i; if (mm.colorize) { GUI.color = oldColor; } } }
protected void OnGUI() { ColorizeDrawer.Reset(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(110), GUILayout.ExpandHeight(true)); DrawToolbarGUI(); GUILayout.EndVertical(); GUILayout.BeginVertical(); DrawHeader(); bool any = false; if (_showSynthesizer) { any = true; DrawSynthesizerGUI(); } if (any) { any = false; DrawLine(); } if (_showSequencer) { any = true; DrawSequencerGUI(); } if (any) { any = false; DrawLine(); } if (_showOcclusion) { any = true; DrawOcclusionGUI(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { var rootProperty = serializedObject.FindProperty("root"); GUI.color = ColorizeDrawer.GetColor(0); GUI.enabled = Directory.Exists(rootProperty.stringValue); if (GUILayout.Button("Apply")) { IterateOverrides( (overrideProperty, overrideIndex, overrideCount, matchCount) => true, (path, name, overrideIndex) => { overridesTable.Add(path, overrideIndex); }, overrideProperty => { } ); AssetDatabase.ImportAsset( rootProperty.stringValue, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive); overridesTable.Clear(); } GUI.color = Color.white; GUI.enabled = true; DrawLine(); GUI.color = ColorizeDrawer.GetColor(1); EditorGUILayout.PropertyField(rootProperty); const int w = 40; var refreshRect = EditorGUILayout.GetControlRect(); var refreshRect2 = refreshRect; refreshRect2.x += refreshRect2.width - w * 3; refreshRect2.width = w * 3; refreshRect.width -= w * 3; GUI.Label(refreshRect, _refreshText); if (GUI.Button(refreshRect2, "Refresh")) { RefreshAudioClips(); } GUI.color = Color.white; EditorGUI.BeginChangeCheck(); _moveCommand = -1; _deleteCommand = -1; _resetCaches = false; var overridesProperty = IterateOverrides( (overrideProperty, overrideIndex, overrideCount, matchCount) => { DrawLine(); GUI.color = ColorizeDrawer.GetColor(2); var buttonRect = EditorGUILayout.GetControlRect(); buttonRect.x += buttonRect.width - w; buttonRect.width = w; if (GUI.Button(buttonRect, "\u2716")) { _deleteCommand = overrideIndex; } buttonRect.x -= w; GUI.enabled = overrideIndex < overrideCount - 1; if (GUI.Button(buttonRect, "\u25bc")) { _moveCommand = overrideIndex | (1 << 30); } buttonRect.x -= w; GUI.enabled = overrideIndex > 0; if (GUI.Button(buttonRect, "\u25b2")) { _moveCommand = overrideIndex | (3 << 30); } GUI.enabled = true; GUI.color = ColorizeDrawer.GetColor(3); var visibleProperty = overrideProperty.FindPropertyRelative("visible"); var filterProperty = overrideProperty.FindPropertyRelative("filter"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(filterProperty); if (EditorGUI.EndChangeCheck()) { _resetCaches = true; } var matchingText = "Matches (" + matchCount + ")"; visibleProperty.boolValue = EditorGUILayout.Foldout(visibleProperty.boolValue, matchingText); EditorGUI.indentLevel++; GUI.enabled = false; return(visibleProperty.boolValue); }, (path, name, overrideIndex) => { if (!_filteredPaths.Contains(name)) { _filteredPaths.Add(name); GUI.Label( EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), name + " (" + _nameCount[name] + ")"); } }, overrideProperty => { EditorGUI.indentLevel--; GUI.enabled = true; var settingsProperty = overrideProperty.FindPropertyRelative("settings"); if (settingsProperty != null) { EditorGUILayout.PropertyField(settingsProperty, true); } } ); if (_moveCommand != -1) { int direction = (_moveCommand >> 31) | (_moveCommand >> 30); _moveCommand &= ~(3 << 30); overridesProperty.MoveArrayElement(_moveCommand, _moveCommand + direction); } if (_deleteCommand != -1) { overridesProperty.DeleteArrayElementAtIndex(_deleteCommand); } if (_resetCaches) { ResetCaches(); } _filteredPaths.Clear(); DrawLine(); GUI.color = ColorizeDrawer.GetColor(2); var addButtonRect = EditorGUILayout.GetControlRect(); var addButtonRect2 = addButtonRect; addButtonRect2.x += addButtonRect2.width - w; addButtonRect2.width = w; addButtonRect.width -= w * 3; if (GUI.Button(addButtonRect2, "\u271a")) { overridesProperty.InsertArrayElementAtIndex(overridesProperty.arraySize); } _unfilteredVisible = EditorGUI.Foldout(addButtonRect, _unfilteredVisible, _unfilteredText); EditorGUI.indentLevel++; GUI.enabled = false; if (_unfilteredVisible) { foreach (var x in _unfilteredPaths) { if (!_filteredPaths.Contains(x.Value)) { _filteredPaths.Add(x.Value); GUI.Label( EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), x.Value + " (" + _nameCount[x.Value] + ")"); } } } _filteredPaths.Clear(); EditorGUI.indentLevel--; GUI.enabled = true; GUI.color = Color.white; if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }
public override void OnInspectorGUI() { var a = (Patch)target; ColorizeDrawer.Reset(); DrawDefaultInspector(); GUILayout.Space(16); if (GUILayout.Button("Set Clips To Selected")) { var assets = Selection.GetFiltered(typeof(AudioClip), SelectionMode.Assets); Array.Sort(assets, (x, y) => string.Compare(x.name, y.name)); a.program.clips = new AudioProgram.AudioClipParams[assets.Length]; for (int i = 0, n = assets.Length; i < n; ++i) { a.program.clips[i] = new AudioProgram.AudioClipParams { clip = (AudioClip)assets[i] } } ; } GUILayout.Space(16); if (a.sequence != null && a.sequence.timing != null && a.sequence.timing.Length > 0) { DrawAudioSequenceInspectorGUI(a); } else if (a.program != null) { DrawAudioProgramInspectorGUI(a.program); } } void DrawAudioProgramInspectorGUI(AudioProgram a) { AudioClip c = null; GUILayout.BeginHorizontal(); GUI.color = new Color(0.75f, 1.00f, 0.75f); if (GUILayout.Button("\u25b6")) { float gain; if (a.randomize) { _random = Randomizer.zeroToOne; a.weighted.count = a.clips.Length; _weights = (float[])a.weighted.weights.Clone(); c = a.GetClip(_random, out gain); } else { c = a.GetClip(out gain); } if (c != null) { _played = c.name; Synthesizer.KeyOn(null, c, a.audioParameters, null, new Vector3(), 1f + gain); } } GUI.color = new Color(1.00f, 0.75f, 0.75f); if (GUILayout.Button("\u2585")) { Synthesizer.StopAll(); } GUILayout.EndHorizontal(); GUILayout.Space(16); GUI.color = Color.white; _foldout = EditorGUILayout.Foldout(_foldout, "Randomization"); if (_foldout && _weights != null) { float s = 0; for (int i = 0, n = _weights.Length; i < n; ++i) { s += _weights[i]; } float t = _random * s; GUILayout.BeginHorizontal(); GUILayout.Label(s.ToString("N2")); GUILayout.Label(t.ToString("N2")); GUILayout.Label("\t"); GUILayout.EndHorizontal(); for (int i = 0, n = _weights.Length; i < n; ++i) { if (t >= _weights[i]) { GUI.color = Color.white; } else if (a.clips[i].clip.name == _played) { GUI.color = Color.green; } else { GUI.color = Color.gray; } t -= _weights[i]; GUILayout.BeginHorizontal(); GUILayout.Label(_weights[i].ToString("N2")); GUILayout.Label(t.ToString("N2")); GUILayout.Label(a.clips[i].clip.name); GUILayout.EndHorizontal(); } } } void DrawAudioSequenceInspectorGUI(Patch patch) { bool looping; GUILayout.BeginHorizontal(); GUI.color = new Color(0.75f, 1.00f, 0.75f); if (GUILayout.Button("\u25b6")) { Synthesizer.KeyOn(out looping, patch); } GUI.color = new Color(1.00f, 0.75f, 0.75f); if (GUILayout.Button("\u2585")) { Synthesizer.StopAll(); } GUILayout.EndHorizontal(); GUILayout.Space(16); } }
void DrawSequencerGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Pause", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Emitter", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Patch", EditorStyles.boldLabel, GUILayout.Width(220)); GUILayout.Label("Period", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Repeat", EditorStyles.boldLabel, GUILayout.Width(75)); GUILayout.Label("Looping", EditorStyles.boldLabel, GUILayout.Width(55)); EditorGUILayout.EndHorizontal(); int i = 0; var c = GUI.color; Rect p; _scrollSequencer = EditorGUILayout.BeginScrollView(_scrollSequencer); if (Application.isPlaying) { for (var x = Sequencer.activeCues0.GetEnumerator(); x.MoveNext();) { GUI.color = ColorizeDrawer.GetColor(i); var z = x.Current; EditorGUILayout.BeginHorizontal(); // Pause if (z.emitter) { z.emitter.SetPaused( EditorGUILayout.Toggle( z.emitter.IsPaused(), GUILayout.Width(50))); } else { EditorGUILayout.Toggle(false, GUILayout.Width(50)); } GUILayout.Space(5); // Emitter GUILayout.Label(z.emitter.name, GUILayout.Width(110)); // Patch GUILayout.Label(z.emitter.patches[z.index].name, GUILayout.Width(220)); // Period p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(100)); if (z.totalTime > 0f) { EditorGUI.ProgressBar( p, z.currentTime / z.totalTime, z.currentTime.ToString("N3")); } else if (z.emitter.modulation.period > 0f) { float t = z.currentTime % z.emitter.modulation.period; EditorGUI.ProgressBar( p, t / z.emitter.modulation.period, t.ToString("N3")); } else { EditorGUI.ProgressBar(p, 0f, z.currentTime.ToString("N3")); } GUILayout.Space(10); // Repeat if (z.repeatCount == 0) { GUILayout.Label("Never", GUILayout.Width(70)); } else if (z.repeatCount > 0) { string ris; if (!_intLookup.TryGetValue(z.repeatIndex, out ris)) { ris = z.repeatIndex.ToString(); _intLookup[z.repeatIndex] = ris; } p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(70)); EditorGUI.ProgressBar( p, z.repeatIndex / (float)z.repeatCount, ris); } else { GUILayout.Label("Forever", GUILayout.Width(70)); } GUILayout.Space(5); // Looping GUILayout.Label((z.looping ? "\u2713" : ""), GUILayout.Width(50)); GUILayout.Space(5); EditorGUILayout.EndHorizontal(); ++i; } GUI.color = c; } GUI.color = c; EditorGUILayout.EndScrollView(); }
void DrawSynthesizerGUI() { bool shift = Event.current.shift; EditorGUILayout.BeginHorizontal(); GUILayout.Label("Mute", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Mix Group", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Output", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Source", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label(shift ? "Audio Clip" : "Patch", EditorStyles.boldLabel, GUILayout.Width(220)); GUILayout.Label("Keyed", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Time", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Envelope", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Volume", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Distance", EditorStyles.boldLabel, GUILayout.Width(75)); EditorGUILayout.EndHorizontal(); int i = 0; var c = GUI.color; Rect p; _scrollSynthesizer = EditorGUILayout.BeginScrollView(_scrollSynthesizer); if (Application.isPlaying && Heartbeat.listenerTransform) { _srcColors.Clear(); _srcInfo.Clear(); for (var x = Synthesizer.activeSources0.GetEnumerator(); x.MoveNext();) { _srcInfo.Add(x.Current); } for (var x = Synthesizer.freeSources.GetEnumerator(); x.MoveNext();) { _srcInfo.Add(new Synthesizer.ActiveSource { info = x.Current }); } _srcInfo.Sort((x, y) => string.Compare(x.info.audioSource.name, y.info.audioSource.name)); var lp = Heartbeat.listenerTransform.position; for (var x = _srcInfo.GetEnumerator(); x.MoveNext();) { var z = x.Current; EditorGUILayout.BeginHorizontal(); float v; bool dis = z.handle == 0 || z.keyOn > 0f; { _srcColors[z.info.audioSource.name] = i; if (dis) { GUI.color = ColorizeDrawer.disabledColor; } else { GUI.color = ColorizeDrawer.GetColor(i); } // Mute if (z.info.audioSource != null) { z.info.audioSource.mute = EditorGUILayout.Toggle( z.info.audioSource.mute, GUILayout.Width(50)); } else { EditorGUILayout.Toggle(false, GUILayout.Width(50)); } GUILayout.Space(5); // Mix Group GUILayout.Label( (!dis && z.info.audioSource && z.info.audioSource.outputAudioMixerGroup != null ? z.info.audioSource.outputAudioMixerGroup.name : "(None)"), GUILayout.Width(100)); GUILayout.Space(10); // Output GUILayout.Label( (!dis && !z.info.audioSource.isVirtual ? "\u2713" : ""), GUILayout.Width(50)); GUILayout.Space(5); // Source GUILayout.Label( (!dis ? z.info.audioSource.name : ""), GUILayout.Width(110)); // Patch if (shift) { GUILayout.Label( (!dis ? z.info.audioSource.clip != null ? z.info.audioSource.clip.name : "-" : ""), GUILayout.Width(220)); } else { GUILayout.Label( (!dis ? z.patch != null ? z.patch.name : "-" : ""), GUILayout.Width(220)); } // Keyed if (dis || z.keyOff) { GUILayout.Label("Off", GUILayout.Width(50)); } else { GUILayout.Label("On", GUILayout.Width(50)); } GUILayout.Space(5); // Time p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(100)); v = !dis ? z.info.audioSource.time : 0f; EditorGUI.ProgressBar( p, v / (!dis ? z.info.audioSource.clip.length : 1f), v.ToString("N3")); GUILayout.Space(10); // Envelope p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(50)); v = !dis?z.envelope.GetAttackValue() : 0f; EditorGUI.ProgressBar(p, v, v.ToString("N3")); GUILayout.Space(5); p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(50)); v = !dis?z.envelope.GetReleaseValue() : 0f; EditorGUI.ProgressBar(p, v, v.ToString("N3")); GUILayout.Space(5); // Volume p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(100)); v = !dis?z.GetVolume() : 0f; EditorGUI.ProgressBar(p, v, v.ToString("N3")); GUILayout.Space(10); // Distance v = !dis ? (z.info.audioSource.transform.position - lp).magnitude : 0f; GUILayout.Label(v.ToString("N3"), GUILayout.Width(70)); GUILayout.Space(5); } EditorGUILayout.EndHorizontal(); ++i; } } GUI.color = c; EditorGUILayout.EndScrollView(); }
void DrawOcclusionGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Mute", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Mix Group", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Output", EditorStyles.boldLabel, GUILayout.Width(55)); GUILayout.Label("Source", EditorStyles.boldLabel, GUILayout.Width(110)); GUILayout.Label("Patch", EditorStyles.boldLabel, GUILayout.Width(220)); GUILayout.Label("Function", EditorStyles.boldLabel, GUILayout.Width(75)); GUILayout.Label("Distance", EditorStyles.boldLabel, GUILayout.Width(75)); GUILayout.Label("Occlusion", EditorStyles.boldLabel, GUILayout.Width(75)); EditorGUILayout.EndHorizontal(); int i = 0; var c = GUI.color; Rect p; _scrollOcclusion = EditorGUILayout.BeginScrollView(_scrollOcclusion); if (Application.isPlaying) { _srcColors.Clear(); _srcInfo.Clear(); for (var x = Synthesizer.activeSources0.GetEnumerator(); x.MoveNext();) { _srcInfo.Add(x.Current); } for (var x = Synthesizer.freeSources.GetEnumerator(); x.MoveNext();) { _srcInfo.Add(new Synthesizer.ActiveSource { info = x.Current }); } _srcInfo.Sort((x, y) => string.Compare(x.info.audioSource.name, y.info.audioSource.name)); var lp = Heartbeat.listenerTransform.position; for (var x = _srcInfo.GetEnumerator(); x.MoveNext();) { var z = x.Current; if (z.info.occlusion.occlusion.function == OcclusionFunction.None) { continue; } EditorGUILayout.BeginHorizontal(); float v; bool dis = z.handle == 0 || z.keyOn > 0f; { _srcColors[z.info.audioSource.name] = i; if (dis) { GUI.color = ColorizeDrawer.disabledColor; } else { GUI.color = ColorizeDrawer.GetColor(i); } // Mute if (z.info.audioSource != null) { z.info.audioSource.mute = EditorGUILayout.Toggle( z.info.audioSource.mute, GUILayout.Width(50)); } else { EditorGUILayout.Toggle(false, GUILayout.Width(50)); } GUILayout.Space(5); // Mix Group GUILayout.Label( (!dis && z.info.audioSource && z.info.audioSource.outputAudioMixerGroup != null ? z.info.audioSource.outputAudioMixerGroup.name : "(None)"), GUILayout.Width(100)); GUILayout.Space(10); // Output GUILayout.Label( (!dis && !z.info.audioSource.isVirtual ? "\u2713" : ""), GUILayout.Width(50)); GUILayout.Space(5); // Source GUILayout.Label( (!dis ? z.info.audioSource.name : ""), GUILayout.Width(110)); // Patch GUILayout.Label( (!dis ? z.patch.name : ""), GUILayout.Width(220)); // Function GUILayout.Label( (!dis ? z.info.occlusion.occlusion.function.ToString() : ""), GUILayout.Width(70)); GUILayout.Space(5); // Distance v = !dis ? (z.info.audioSource.transform.position - lp).magnitude : 0f; GUILayout.Label(v.ToString("N3"), GUILayout.Width(70)); GUILayout.Space(5); // Occlusion p = GUILayoutUtility.GetRect( GUIContent.none, EditorStyles.label, GUILayout.Width(70)); v = !dis ? 1f - z.info.occlusion.GetCurrent() : 0f; EditorGUI.ProgressBar(p, v, v.ToString("N3")); GUILayout.Space(5); } EditorGUILayout.EndHorizontal(); ++i; } } GUI.color = c; EditorGUILayout.EndScrollView(); }
protected void OnSceneGUI(SceneView sv) { if (!Heartbeat.listenerTransform) { return; } var p = Heartbeat.listenerTransform.position; var c = Handles.color; for (var i = Synthesizer.activeSources0.GetEnumerator(); i.MoveNext();) { if (i.Current.keyOn <= 0f) { int j = Monitor.GetSourceColor(i.Current.info.audioSource.name); Handles.color = ColorizeDrawer.GetColor(j); var q = i.Current.info.audioSource.transform.position; var d = p - q; if (d.magnitude < 1f) { continue; } var e = d.normalized; Handles.DrawLine(p - e * 0.5f, q + e * 0.5f); Handles.ConeHandleCap( 0, p - e * 0.5f, Quaternion.LookRotation(e), 0.05f, Event.current.type); _builder.Append("\n\n"); var ac = i.Current.info.audioSource.clip; _builder.Append(ac != null ? ac.name : "??"); _builder.Append(" ("); _builder.Append(i.Current.patch != null ? i.Current.patch.name : "-"); _builder.Append(")"); var s = _builder.ToString(); _builder.Length = 0; Handles.BeginGUI(); var k = GUI.color; GUI.color = Handles.color; var a = p - d * 0.5f; var x = new GUIContent(i.Current.info.audioSource.name); var y = new GUIContent(s); var l = HandleUtility.WorldPointToSizedRect(a, x, EditorStyles.boldLabel); var m = HandleUtility.WorldPointToSizedRect(a, y, EditorStyles.helpBox); float n = Mathf.Max(l.width, m.width); l.width = n; m.width = n; l.x -= m.width * 1.2f; l.y -= m.height * 0.5f; m.x = l.x - Mathf.Max(0f, m.width - l.width); m.y = l.y + 1f; EditorGUI.HelpBox(m, y.text, MessageType.None); EditorGUI.DropShadowLabel(l, x); GUI.color = k; Handles.EndGUI(); } } Handles.color = c; }