private void DeleteBus(int busIndex) { DynamicSoundGroup aGroup = null; var groupsWithBus = new List <DynamicSoundGroup>(); var groupsWithHigherBus = new List <DynamicSoundGroup>(); for (var i = 0; i < this._groups.Count; i++) { aGroup = this._groups[i]; if (aGroup.busIndex == -1) { continue; } if (aGroup.busIndex == busIndex + DynamicSoundGroupCreator.HardCodedBusOptions) { groupsWithBus.Add(aGroup); } else if (aGroup.busIndex > busIndex + DynamicSoundGroupCreator.HardCodedBusOptions) { groupsWithHigherBus.Add(aGroup); } } var allObjects = new List <UnityEngine.Object>(); allObjects.Add(_creator); foreach (var g in groupsWithBus) { allObjects.Add(g as UnityEngine.Object); } foreach (var g in groupsWithHigherBus) { allObjects.Add(g as UnityEngine.Object); } UndoHelper.RecordObjectsForUndo(allObjects.ToArray(), "delete Bus"); // change all _creator.groupBuses.RemoveAt(busIndex); foreach (var group in groupsWithBus) { group.busIndex = -1; } foreach (var group in groupsWithHigherBus) { group.busIndex--; } }
public void EqualizeWeights(DynamicSoundGroup _group) { var variations = new DynamicGroupVariation[_group.groupVariations.Count]; DynamicGroupVariation variation = null; for (var i = 0; i < _group.groupVariations.Count; i++) { variation = _group.groupVariations[i]; variations[i] = variation; } UndoHelper.RecordObjectsForUndo(variations, "Equalize Weights"); foreach (var vari in variations) { vari.weight = 1; } }
private void CreateBus(int groupIndex, bool isExisting) { var sourceGroup = _groups[groupIndex]; var affectedObjects = new UnityEngine.Object[] { _creator, sourceGroup }; UndoHelper.RecordObjectsForUndo(affectedObjects, "create Bus"); var newBusName = isExisting ? EXISTING_NAME_NAME : MasterAudioInspector.RENAME_ME_BUS_NAME; var newBus = new GroupBus() { busName = newBusName }; newBus.isExisting = isExisting; _creator.groupBuses.Add(newBus); sourceGroup.busIndex = DynamicSoundGroupCreator.HardCodedBusOptions + _creator.groupBuses.Count - 1; }
private void DeleteAllUnusedFilterFX() { var ma = MasterAudio.Instance; if (ma == null) { DTGUIHelper.ShowAlert("There is no MasterAudio prefab in this scene. Try pressing this button on a different Scene."); return; } var affectedVariations = new List <SoundGroupVariation>(); var filtersToDelete = new List <Object>(); for (var g = 0; g < ma.transform.childCount; g++) { var sGroup = ma.transform.GetChild(g); for (var v = 0; v < sGroup.childCount; v++) { var variation = sGroup.GetChild(v); var grpVar = variation.GetComponent <SoundGroupVariation>(); if (grpVar == null) { continue; } if (grpVar.LowPassFilter != null && !grpVar.LowPassFilter.enabled) { if (!filtersToDelete.Contains(grpVar.LowPassFilter)) { filtersToDelete.Add(grpVar.LowPassFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } if (grpVar.HighPassFilter != null && !grpVar.HighPassFilter.enabled) { if (!filtersToDelete.Contains(grpVar.HighPassFilter)) { filtersToDelete.Add(grpVar.HighPassFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } if (grpVar.ChorusFilter != null && !grpVar.ChorusFilter.enabled) { if (!filtersToDelete.Contains(grpVar.ChorusFilter)) { filtersToDelete.Add(grpVar.ChorusFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } if (grpVar.DistortionFilter != null && !grpVar.DistortionFilter.enabled) { if (!filtersToDelete.Contains(grpVar.DistortionFilter)) { filtersToDelete.Add(grpVar.DistortionFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } if (grpVar.EchoFilter != null && !grpVar.EchoFilter.enabled) { if (!filtersToDelete.Contains(grpVar.EchoFilter)) { filtersToDelete.Add(grpVar.EchoFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } if (grpVar.ReverbFilter != null && !grpVar.ReverbFilter.enabled) { if (!filtersToDelete.Contains(grpVar.ReverbFilter)) { filtersToDelete.Add(grpVar.ReverbFilter); } if (!affectedVariations.Contains(grpVar)) { affectedVariations.Add(grpVar); } } } } UndoHelper.RecordObjectsForUndo(affectedVariations.ToArray(), "delete all unused Filter FX Components"); for (var i = 0; i < filtersToDelete.Count; i++) { DestroyImmediate(filtersToDelete[i]); } DTGUIHelper.ShowAlert(string.Format("{0} Filter FX Components deleted.", filtersToDelete.Count)); }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(); EditorGUI.indentLevel = 1; var isDirty = false; _creator = (DynamicSoundGroupCreator)target; var isInProjectView = DTGUIHelper.IsPrefabInProjectView(_creator); if (MasterAudioInspectorResources.logoTexture != null) { DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture); } MasterAudio.Instance = null; MasterAudio ma = MasterAudio.Instance; var busVoiceLimitList = new List <string>(); busVoiceLimitList.Add(MasterAudio.NO_VOICE_LIMIT_NAME); for (var i = 1; i <= 32; i++) { busVoiceLimitList.Add(i.ToString()); } var busList = new List <string>(); busList.Add(MasterAudioGroup.NO_BUS); busList.Add(MasterAudioInspector.NEW_BUS_NAME); busList.Add(EXISTING_BUS); int maxChars = 12; GroupBus bus = null; for (var i = 0; i < _creator.groupBuses.Count; i++) { bus = _creator.groupBuses[i]; busList.Add(bus.busName); if (bus.busName.Length > maxChars) { maxChars = bus.busName.Length; } } var busListWidth = 9 * maxChars; EditorGUI.indentLevel = 0; // Space will handle this for the header var newAwake = EditorGUILayout.Toggle("Auto-create Items", _creator.createOnAwake); if (newAwake != _creator.createOnAwake) { UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Auto-create Items"); _creator.createOnAwake = newAwake; } if (_creator.createOnAwake) { DTGUIHelper.ShowColorWarning("*Items will be created as soon as this object is in the Scene."); } else { DTGUIHelper.ShowColorWarning("*You will need to call this object's CreateItems method."); } var newRemove = EditorGUILayout.Toggle("Auto-remove Items", _creator.removeGroupsOnSceneChange); if (newRemove != _creator.removeGroupsOnSceneChange) { UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Auto-remove Items"); _creator.removeGroupsOnSceneChange = newRemove; } if (_creator.removeGroupsOnSceneChange) { DTGUIHelper.ShowColorWarning("*Items will be deleted when the Scene changes."); } else { DTGUIHelper.ShowColorWarning("*Items will persist across Scenes if MasterAudio does."); } EditorGUILayout.Separator(); _groups = ScanForGroups(); var groupNameList = GroupNameList; EditorGUI.indentLevel = 0; GUI.color = _creator.showMusicDucking ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr; EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newShowDuck = EditorGUILayout.Toggle("Dynamic Music Ducking", _creator.showMusicDucking); if (newShowDuck != _creator.showMusicDucking) { UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Dynamic Music Ducking"); _creator.showMusicDucking = newShowDuck; } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (_creator.showMusicDucking) { GUI.contentColor = Color.green; EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); if (GUILayout.Button(new GUIContent("Add Duck Group"), EditorStyles.toolbarButton, GUILayout.Width(100))) { UndoHelper.RecordObjectPropertyForUndo(_creator, "Add Duck Group"); var defaultBeginUnduck = 0.5f; if (ma != null) { defaultBeginUnduck = ma.defaultRiseVolStart; } _creator.musicDuckingSounds.Add(new DuckGroupInfo() { soundType = MasterAudio.NO_GROUP_NAME, riseVolStart = defaultBeginUnduck }); } EditorGUILayout.EndHorizontal(); GUI.contentColor = Color.white; EditorGUILayout.Separator(); if (_creator.musicDuckingSounds.Count == 0) { DTGUIHelper.ShowColorWarning("*You currently have no ducking sounds set up."); } else { int?duckSoundToRemove = null; for (var i = 0; i < _creator.musicDuckingSounds.Count; i++) { var duckSound = _creator.musicDuckingSounds[i]; var index = groupNameList.IndexOf(duckSound.soundType); if (index == -1) { index = 0; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); var newIndex = EditorGUILayout.Popup(index, groupNameList.ToArray(), GUILayout.MaxWidth(200)); if (newIndex >= 0) { if (index != newIndex) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Duck Group"); } duckSound.soundType = groupNameList[newIndex]; } GUI.contentColor = Color.green; GUILayout.TextField("Begin Unduck " + duckSound.riseVolStart.ToString("N2"), 20, EditorStyles.miniLabel); var newUnduck = GUILayout.HorizontalSlider(duckSound.riseVolStart, 0f, 1f, GUILayout.Width(60)); if (newUnduck != duckSound.riseVolStart) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Begin Unduck"); duckSound.riseVolStart = newUnduck; } GUI.contentColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.Space(10); if (DTGUIHelper.AddDeleteIcon("Duck Sound")) { duckSoundToRemove = i; } EditorGUILayout.EndHorizontal(); } if (duckSoundToRemove.HasValue) { UndoHelper.RecordObjectPropertyForUndo(_creator, "delete Duck Group"); _creator.musicDuckingSounds.RemoveAt(duckSoundToRemove.Value); } } } EditorGUILayout.Separator(); GUI.color = _creator.soundGroupsAreExpanded ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr; EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newGroupEx = EditorGUILayout.Toggle("Dynamic Group Mixer", _creator.soundGroupsAreExpanded); if (newGroupEx != _creator.soundGroupsAreExpanded) { UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Dynamic Group Mixer"); _creator.soundGroupsAreExpanded = newGroupEx; } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (_creator.soundGroupsAreExpanded) { var newDragMode = (MasterAudio.DragGroupMode)EditorGUILayout.EnumPopup("Bulk Creation Mode", _creator.curDragGroupMode); if (newDragMode != _creator.curDragGroupMode) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bulk Creation Mode"); _creator.curDragGroupMode = newDragMode; } var bulkMode = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Variation Create Mode", _creator.bulkVariationMode); if (bulkMode != _creator.bulkVariationMode) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Variation Mode"); _creator.bulkVariationMode = bulkMode; } // create groups start EditorGUILayout.BeginVertical(); var aEvent = Event.current; if (isInProjectView) { DTGUIHelper.ShowLargeBarAlert("*You are in Project View and cannot create or navigate Groups."); DTGUIHelper.ShowLargeBarAlert("*Pull this prefab into the Scene to create Groups."); } else { GUI.color = Color.yellow; var dragAreaGroup = GUILayoutUtility.GetRect(0f, 35f, GUILayout.ExpandWidth(true)); GUI.Box(dragAreaGroup, "Drag Audio clips here to create groups!"); GUI.color = Color.white; switch (aEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragAreaGroup.Contains(aEvent.mousePosition)) { break; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (aEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Transform groupInfo = null; var clips = new List <AudioClip>(); foreach (var dragged in DragAndDrop.objectReferences) { var aClip = dragged as AudioClip; if (aClip == null) { continue; } clips.Add(aClip); } clips.Sort(delegate(AudioClip x, AudioClip y) { return(x.name.CompareTo(y.name)); }); for (var i = 0; i < clips.Count; i++) { var aClip = clips[i]; if (_creator.curDragGroupMode == MasterAudio.DragGroupMode.OneGroupPerClip) { CreateGroup(aClip); } else { if (groupInfo == null) { // one group with variations groupInfo = CreateGroup(aClip); } else { CreateVariation(groupInfo, aClip); } } isDirty = true; } } Event.current.Use(); break; } } EditorGUILayout.EndVertical(); // create groups end if (_creator.soundGroupsToCreate.Count > 0 && !Application.isPlaying) { if (isInProjectView) { DTGUIHelper.ShowLargeBarAlert("You have data in an old format. Pull this prefab into the Scene, then Upgrade Data."); } else { DTGUIHelper.ShowRedError("You have data in an old format. It will not be used as is."); DTGUIHelper.ShowRedError("Upgrade it to the new format by clicking the Upgrade button below."); EditorGUILayout.BeginHorizontal(); GUILayout.Space(154); GUI.contentColor = Color.green; if (GUILayout.Button("Upgrade Data", EditorStyles.toolbarButton, GUILayout.Width(150))) { UpgradeData(); } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); } } if (_groups.Count == 0) { DTGUIHelper.ShowColorWarning("*You currently have no Dynamic Sound Groups created."); } int?indexToDelete = null; EditorGUILayout.LabelField("Group Control", EditorStyles.miniBoldLabel); GUI.color = Color.white; int? busToCreate = null; bool isExistingBus = false; for (var i = 0; i < _groups.Count; i++) { var aGroup = _groups[i]; EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.Label(aGroup.name, GUILayout.Width(150)); GUILayout.FlexibleSpace(); // find bus. var selectedBusIndex = aGroup.busIndex == -1 ? 0 : aGroup.busIndex; GUI.contentColor = Color.white; GUI.color = Color.cyan; var busIndex = EditorGUILayout.Popup("", selectedBusIndex, busList.ToArray(), GUILayout.Width(busListWidth)); if (busIndex == -1) { busIndex = 0; } if (aGroup.busIndex != busIndex && busIndex != 1) { UndoHelper.RecordObjectPropertyForUndo(aGroup, "change Group Bus"); } if (busIndex != 1) // don't change the index, so undo will work. { aGroup.busIndex = busIndex; } GUI.color = Color.white; if (selectedBusIndex != busIndex) { if (busIndex == 1 || busIndex == 2) { busToCreate = i; isExistingBus = busIndex == 2; } else if (busIndex >= DynamicSoundGroupCreator.HardCodedBusOptions) { //GroupBus newBus = _creator.groupBuses[busIndex - MasterAudio.HARD_CODED_BUS_OPTIONS]; // do nothing unless we add muting and soloing here. } } GUI.contentColor = Color.green; GUILayout.TextField("V " + aGroup.groupMasterVolume.ToString("N2"), 6, EditorStyles.miniLabel); var newVol = GUILayout.HorizontalSlider(aGroup.groupMasterVolume, 0f, 1f, GUILayout.Width(100)); if (newVol != aGroup.groupMasterVolume) { UndoHelper.RecordObjectPropertyForUndo(aGroup, "change Group Volume"); aGroup.groupMasterVolume = newVol; } GUI.contentColor = Color.white; var buttonPressed = DTGUIHelper.AddDynamicGroupButtons(); EditorGUILayout.EndHorizontal(); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Go: Selection.activeGameObject = aGroup.gameObject; break; case DTGUIHelper.DTFunctionButtons.Remove: indexToDelete = i; break; case DTGUIHelper.DTFunctionButtons.Play: PreviewGroup(aGroup); break; case DTGUIHelper.DTFunctionButtons.Stop: StopPreviewingGroup(); break; } } if (busToCreate.HasValue) { CreateBus(busToCreate.Value, isExistingBus); } if (indexToDelete.HasValue) { UndoHelper.DestroyForUndo(_groups[indexToDelete.Value].gameObject); } EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(6); GUI.contentColor = Color.green; if (GUILayout.Button(new GUIContent("Max Group Volumes", "Reset all group volumes to full"), EditorStyles.toolbarButton, GUILayout.Width(120))) { UndoHelper.RecordObjectsForUndo(_groups.ToArray(), "Max Group Volumes"); for (var l = 0; l < _groups.Count; l++) { var aGroup = _groups[l]; aGroup.groupMasterVolume = 1f; } } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); //buses if (_creator.groupBuses.Count > 0) { EditorGUILayout.Separator(); EditorGUILayout.LabelField("Bus Control", EditorStyles.miniBoldLabel); GroupBus aBus = null; int? busToDelete = null; for (var i = 0; i < _creator.groupBuses.Count; i++) { aBus = _creator.groupBuses[i]; EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); var newBusName = EditorGUILayout.TextField("", aBus.busName, GUILayout.MaxWidth(200)); if (newBusName != aBus.busName) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bus Name"); aBus.busName = newBusName; } GUILayout.FlexibleSpace(); if (!aBus.isExisting) { GUILayout.Label("Voices"); GUI.color = Color.cyan; var oldLimitIndex = busVoiceLimitList.IndexOf(aBus.voiceLimit.ToString()); if (oldLimitIndex == -1) { oldLimitIndex = 0; } var busVoiceLimitIndex = EditorGUILayout.Popup("", oldLimitIndex, busVoiceLimitList.ToArray(), GUILayout.MaxWidth(70)); if (busVoiceLimitIndex != oldLimitIndex) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bus Voice Limit"); aBus.voiceLimit = busVoiceLimitIndex <= 0 ? -1 : busVoiceLimitIndex; } GUI.color = Color.white; EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(50)); GUILayout.TextField("V " + aBus.volume.ToString("N2"), 6, EditorStyles.miniLabel); EditorGUILayout.EndHorizontal(); var newBusVol = GUILayout.HorizontalSlider(aBus.volume, 0f, 1f, GUILayout.Width(86)); if (newBusVol != aBus.volume) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bus Volume"); aBus.volume = newBusVol; } GUI.contentColor = Color.white; } else { DTGUIHelper.ShowColorWarning("Existing bus. No control."); } if (DTGUIHelper.AddDeleteIcon("Bus")) { busToDelete = i; } EditorGUILayout.EndHorizontal(); } if (busToDelete.HasValue) { DeleteBus(busToDelete.Value); } } } EditorGUILayout.Separator(); // Show Custom Events GUI.color = _creator.showCustomEvents ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr; EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newShowEvents = EditorGUILayout.Toggle("Dynamic Custom Events", _creator.showCustomEvents); if (_creator.showCustomEvents != newShowEvents) { UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Dynamic Custom Events"); _creator.showCustomEvents = newShowEvents; } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (_creator.showCustomEvents) { var newEvent = EditorGUILayout.TextField("New Event Name", _creator.newEventName); if (newEvent != _creator.newEventName) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change New Event Name"); _creator.newEventName = newEvent; } EditorGUILayout.BeginHorizontal(); GUILayout.Space(154); GUI.contentColor = Color.green; if (GUILayout.Button("Create New Event", EditorStyles.toolbarButton, GUILayout.Width(100))) { CreateCustomEvent(_creator.newEventName); } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); if (_creator.customEventsToCreate.Count == 0) { DTGUIHelper.ShowColorWarning("*You currently have no custom events defined here."); } EditorGUILayout.Separator(); int?indexToDelete = null; int?indexToRename = null; for (var i = 0; i < _creator.customEventsToCreate.Count; i++) { var anEvent = _creator.customEventsToCreate[i]; EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.Label(anEvent.EventName, GUILayout.Width(170)); GUILayout.FlexibleSpace(); var newName = GUILayout.TextField(anEvent.ProspectiveName, GUILayout.Width(170)); if (newName != anEvent.ProspectiveName) { UndoHelper.RecordObjectPropertyForUndo(_creator, "change Proposed Event Name"); anEvent.ProspectiveName = newName; } var buttonPressed = DTGUIHelper.AddCustomEventDeleteIcon(true); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Remove: indexToDelete = i; break; case DTGUIHelper.DTFunctionButtons.Rename: indexToRename = i; break; } EditorGUILayout.EndHorizontal(); } if (indexToDelete.HasValue) { _creator.customEventsToCreate.RemoveAt(indexToDelete.Value); } if (indexToRename.HasValue) { RenameEvent(_creator.customEventsToCreate[indexToRename.Value]); } } // End Show Custom Events if (GUI.changed || isDirty) { EditorUtility.SetDirty(target); } this.Repaint(); //DrawDefaultInspector(); }