private DynamicSoundGroup RescanChildren(DynamicSoundGroup group) { var newChildren = new List <DynamicGroupVariation>(); var childNames = new List <string>(); DynamicGroupVariation variation = null; for (var i = 0; i < group.transform.childCount; i++) { var child = group.transform.GetChild(i); if (!Application.isPlaying) { if (childNames.Contains(child.name)) { DTGUIHelper.ShowRedError("You have more than one Variation named: " + child.name + "."); DTGUIHelper.ShowRedError("Please ensure each Variation of this Group has a unique name."); isValid = false; return(null); } } childNames.Add(child.name); variation = child.GetComponent <DynamicGroupVariation>(); newChildren.Add(variation); } group.groupVariations = newChildren; return(group); }
public static float GetRandomPreviewVolume(DynamicGroupVariation var) { var varVol = var.VarAudio.volume; if (var.audLocation == MasterAudio.AudioLocation.FileOnInternet) { return(varVol); } if (!var.useRandomPitch) { return(varVol); } var randomVol = UnityEngine.Random.Range(var.randomVolumeMin, var.randomVolumeMax); switch (var.randomVolumeMode) { case SoundGroupVariation.RandomVolumeMode.AddToClipVolume: varVol += randomVol; break; case SoundGroupVariation.RandomVolumeMode.IgnoreClipVolume: varVol = randomVol; break; } return(varVol); }
public static float GetRandomPreviewPitch(DynamicGroupVariation var) { var randPitch = var.VarAudio.pitch; if (var.audLocation == MasterAudio.AudioLocation.FileOnInternet) { return(randPitch); } if (!var.useRandomPitch) { return(randPitch); } randPitch = UnityEngine.Random.Range(var.randomPitchMin, var.randomPitchMax); switch (var.randomPitchMode) { case SoundGroupVariation.RandomPitchMode.AddToClipPitch: randPitch += var.VarAudio.pitch; break; } return(randPitch); }
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; } }
public void EqualizeWeights(DynamicSoundGroup grp) { var variations = new DynamicGroupVariation[grp.groupVariations.Count]; for (var i = 0; i < grp.groupVariations.Count; i++) { var variation = grp.groupVariations[i]; variations[i] = variation; } AudioUndoHelper.RecordObjectsForUndo(variations, "Equalize Voices"); foreach (var vari in variations) { vari.weight = 1; } }
private void CopyPitches(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { UndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Pitches"); } for (var i = 0; i < _group.groupVariations.Count; i++) { if (i == _group.selectedVariationIndex) { continue; } var aVar = _group.groupVariations[i]; aVar.VarAudio.pitch = variation.VarAudio.pitch; changed++; } Debug.LogWarning(changed + " Variation Pitch(es) changed."); }
private void CopyFxTail(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { UndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Fx Tail"); } for (var i = 0; i < _group.groupVariations.Count; i++) { if (i == _group.selectedVariationIndex) { continue; } var aVar = _group.groupVariations[i]; aVar.fxTailTime = variation.fxTailTime; changed++; } Debug.LogWarning(changed + " Fx Tail(s) changed."); }
private void CopyCustomFade(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { UndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Custom Fade"); } for (var i = 0; i < _group.groupVariations.Count; i++) { if (i == _group.selectedVariationIndex) { continue; } var aVar = _group.groupVariations[i]; aVar.useFades = variation.useFades; aVar.fadeInTime = variation.fadeInTime; aVar.fadeOutTime = variation.fadeOutTime; changed++; } Debug.LogWarning(changed + " Random Custom Fade(s) changed."); }
private void CopyRandomVolume(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { UndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Random Volume"); } for (var i = 0; i < _group.groupVariations.Count; i++) { if (i == _group.selectedVariationIndex) { continue; } var aVar = _group.groupVariations[i]; aVar.useRandomVolume = variation.useRandomVolume; aVar.randomVolumeMode = variation.randomVolumeMode; aVar.randomVolumeMin = variation.randomVolumeMin; aVar.randomVolumeMax = variation.randomVolumeMax; changed++; } Debug.LogWarning(changed + " Random Volume(s) changed."); }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(); EditorGUI.indentLevel = 1; var isDirty = false; _variation = (DynamicGroupVariation)target; if (MasterAudioInspectorResources.logoTexture != null) { DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture); } EditorGUI.indentLevel = 0; // Space will handle this for the header DynamicSoundGroupCreator creator = null; if (_variation.transform.parent != null && _variation.transform.parent.parent != null) { creator = _variation.transform.parent.parent.GetComponent <DynamicSoundGroupCreator>(); } if (creator == null) { DTGUIHelper.ShowRedError("This prefab must have DynamicSoundGroupCreator 2 parents up."); return; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUI.contentColor = Color.green; if (GUILayout.Button(new GUIContent("Back to Group", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(120))) { Selection.activeObject = _variation.transform.parent.gameObject; } GUILayout.FlexibleSpace(); GUI.contentColor = Color.white; var buttonPressed = DTGUIHelper.AddDynamicVariationButtons(); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Play: isDirty = true; if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { creator.PreviewerInstance.Stop(); creator.PreviewerInstance.PlayOneShot(Resources.Load(_variation.resourceFileName) as AudioClip); } else { PlaySound(_variation.audio); } break; case DTGUIHelper.DTFunctionButtons.Stop: if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { creator.PreviewerInstance.Stop(); } else { StopSound(_variation.audio); } break; } EditorGUILayout.EndHorizontal(); if (!Application.isPlaying) { DTGUIHelper.ShowColorWarning("*Fading & random settings are ignored by preview in edit mode."); } var oldLocation = _variation.audLocation; var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation); if (newLocation != oldLocation) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Audio Origin"); _variation.audLocation = newLocation; } switch (_variation.audLocation) { case MasterAudio.AudioLocation.Clip: var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", _variation.audio.clip, typeof(AudioClip), false); if (newClip != _variation.audio.clip) { UndoHelper.RecordObjectPropertyForUndo(_variation.audio, "assign Audio Clip"); _variation.audio.clip = newClip; } break; case MasterAudio.AudioLocation.ResourceFile: if (oldLocation != _variation.audLocation) { if (_variation.audio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation."); } _variation.audio.clip = null; } EditorGUILayout.BeginVertical(); var anEvent = Event.current; GUI.color = Color.yellow; var dragArea = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true)); GUI.Box(dragArea, "Drag Resource Audio clip here to use its name!"); GUI.color = Color.white; var newFilename = string.Empty; switch (anEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragArea.Contains(anEvent.mousePosition)) { break; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (anEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (var dragged in DragAndDrop.objectReferences) { var aClip = dragged as AudioClip; if (aClip == null) { continue; } newFilename = DTGUIHelper.GetResourcePath(aClip); if (string.IsNullOrEmpty(newFilename)) { newFilename = aClip.name; } if (newFilename != _variation.resourceFileName) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Resource filename"); _variation.resourceFileName = aClip.name; } break; } } Event.current.Use(); break; } EditorGUILayout.EndVertical(); newFilename = EditorGUILayout.TextField("Resource Filename", _variation.resourceFileName); if (newFilename != _variation.resourceFileName) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Resource filename"); _variation.resourceFileName = newFilename; } break; } var newVolume = EditorGUILayout.Slider("Volume", _variation.audio.volume, 0f, 1f); if (newVolume != _variation.audio.volume) { UndoHelper.RecordObjectPropertyForUndo(_variation.audio, "change Volume"); _variation.audio.volume = newVolume; } var newPitch = EditorGUILayout.Slider("Pitch", _variation.audio.pitch, -3f, 3f); if (newPitch != _variation.audio.pitch) { UndoHelper.RecordObjectPropertyForUndo(_variation.audio, "change Pitch"); _variation.audio.pitch = newPitch; } var newLoop = EditorGUILayout.Toggle("Loop Clip", _variation.audio.loop); if (newLoop != _variation.audio.loop) { UndoHelper.RecordObjectPropertyForUndo(_variation.audio, "toggle Loop"); _variation.audio.loop = newLoop; } var newRandomPitch = EditorGUILayout.Slider("Random Pitch", _variation.randomPitch, 0f, 3f); if (newRandomPitch != _variation.randomPitch) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Random Pitch"); _variation.randomPitch = newRandomPitch; } var newRandomVolume = EditorGUILayout.Slider("Random Volume", _variation.randomVolume, 0f, 1f); if (newRandomVolume != _variation.randomVolume) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Random Volume"); _variation.randomVolume = newRandomVolume; } var newWeight = EditorGUILayout.IntSlider("Weight (Instances)", _variation.weight, 0, 100); if (newWeight != _variation.weight) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Weight"); _variation.weight = newWeight; } if (_variation.HasActiveFXFilter) { var newFxTailTime = EditorGUILayout.Slider("FX Tail Time", _variation.fxTailTime, 0f, 10f); if (newFxTailTime != _variation.fxTailTime) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change FX Tail Time"); _variation.fxTailTime = newFxTailTime; } } var newSilence = EditorGUILayout.BeginToggleGroup("Use Random Delay", _variation.useIntroSilence); if (newSilence != _variation.useIntroSilence) { UndoHelper.RecordObjectPropertyForUndo(_variation, "toggle Use Random Delay"); _variation.useIntroSilence = newSilence; } if (_variation.useIntroSilence) { var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", _variation.introSilenceMin, 0f, 100f); if (newSilenceMin != _variation.introSilenceMin) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Delay Min (sec)"); _variation.introSilenceMin = newSilenceMin; if (_variation.introSilenceMin > _variation.introSilenceMax) { _variation.introSilenceMax = newSilenceMin; } } var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", _variation.introSilenceMax, 0f, 100f); if (newSilenceMax != _variation.introSilenceMax) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Delay Max (sec)"); _variation.introSilenceMax = newSilenceMax; if (_variation.introSilenceMax < _variation.introSilenceMin) { _variation.introSilenceMin = newSilenceMax; } } } EditorGUILayout.EndToggleGroup(); var newUseFades = EditorGUILayout.BeginToggleGroup("Use Custom Fading", _variation.useFades); if (newUseFades != _variation.useFades) { UndoHelper.RecordObjectPropertyForUndo(_variation, "toggle Use Custom Fading"); _variation.useFades = newUseFades; } if (_variation.useFades) { var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _variation.fadeInTime, 0f, 10f); if (newFadeIn != _variation.fadeInTime) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Fade In Time"); _variation.fadeInTime = newFadeIn; } if (_variation.audio.loop) { DTGUIHelper.ShowColorWarning("*Looped clips cannot have a custom fade out."); } else { var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", _variation.fadeOutTime, 0f, 10f); if (newFadeOut != _variation.fadeOutTime) { UndoHelper.RecordObjectPropertyForUndo(_variation, "change Fade Out Time"); _variation.fadeOutTime = newFadeOut; } } } EditorGUILayout.EndToggleGroup(); var filterList = new List <string>() { MasterAudio.NO_GROUP_NAME, "Low Pass", "High Pass", "Distortion", "Chorus", "Echo", "Reverb" }; var newFilterIndex = EditorGUILayout.Popup("Add Filter Effect", 0, filterList.ToArray()); switch (newFilterIndex) { case 1: AddFilterComponent(typeof(AudioLowPassFilter)); break; case 2: AddFilterComponent(typeof(AudioHighPassFilter)); break; case 3: AddFilterComponent(typeof(AudioDistortionFilter)); break; case 4: AddFilterComponent(typeof(AudioChorusFilter)); break; case 5: AddFilterComponent(typeof(AudioEchoFilter)); break; case 6: AddFilterComponent(typeof(AudioReverbFilter)); break; } if (GUI.changed || isDirty) { EditorUtility.SetDirty(target); } this.Repaint(); //DrawDefaultInspector(); }
private void CopyCustomFade(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { AudioUndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Custom Fade"); } foreach (var aVar in changedVars) { aVar.useFades = variation.useFades; aVar.fadeInTime = variation.fadeInTime; aVar.fadeOutTime = variation.fadeOutTime; changed++; } Debug.LogWarning(changed + " Random Custom Fade(s) changed."); }
private void CopyRandomDelay(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { AudioUndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Random Delay"); } foreach (var aVar in changedVars) { aVar.useIntroSilence = variation.useIntroSilence; aVar.introSilenceMin = variation.introSilenceMin; aVar.introSilenceMax = variation.introSilenceMax; changed++; } Debug.LogWarning(changed + " Random Delay(s) changed."); }
private void CopyRandomPitch(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { AudioUndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Random Pitch"); } foreach (var aVar in changedVars) { aVar.useRandomPitch = variation.useRandomPitch; aVar.randomPitchMode = variation.randomPitchMode; aVar.randomPitchMin = variation.randomPitchMin; aVar.randomPitchMax = variation.randomPitchMax; changed++; } Debug.LogWarning(changed + " Random Pitch(es) changed."); }
private void CopyFxTail(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { AudioUndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Fx Tail"); } foreach (var aVar in changedVars) { aVar.fxTailTime = variation.fxTailTime; changed++; } Debug.LogWarning(changed + " Fx Tail(s) changed."); }
private void CopyLoops(DynamicGroupVariation variation) { var changed = 0; var changedVars = GetNonMatchingVariations(); if (changedVars.Count > 0) { AudioUndoHelper.RecordObjectsForUndo(changedVars.ToArray(), "change Variation Loops"); } foreach (var aVar in changedVars) { aVar.VarAudio.loop = variation.VarAudio.loop; changed++; } Debug.LogWarning(changed + " Variation Loop(s) changed."); }
// ReSharper disable once FunctionComplexityOverflow public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(); EditorGUI.indentLevel = 1; var isDirty = false; _variation = (DynamicGroupVariation)target; if (MasterAudioInspectorResources.LogoTexture != null) { DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture); } EditorGUI.indentLevel = 0; // Space will handle this for the header var previewLang = SystemLanguage.English; if (_variation.transform.parent != null && _variation.transform.parent.parent != null) { var parentParent = _variation.transform.parent.parent; _previewer = parentParent.gameObject; var dgsc = _previewer.GetComponent<DynamicSoundGroupCreator>(); if (dgsc != null) { previewLang = dgsc.previewLanguage; } } if (_previewer == null) { DTGUIHelper.ShowRedError("This prefab must have a GameObject 2 parents up. Prefab broken."); return; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUI.contentColor = DTGUIHelper.BrightButtonColor; if (GUILayout.Button(new GUIContent("Back to Group", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(120))) { // ReSharper disable once PossibleNullReferenceException Selection.activeObject = _variation.transform.parent.gameObject; } GUILayout.FlexibleSpace(); GUI.contentColor = Color.white; if (!DTGUIHelper.IsPrefabInProjectView(_variation)) { var buttonPressed = DTGUIHelper.AddDynamicVariationButtons(); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Play: isDirty = true; var calcVolume = _variation.VarAudio.volume * _variation.ParentGroup.groupMasterVolume; switch (_variation.audLocation) { case MasterAudio.AudioLocation.ResourceFile: StopPreviewer(); var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(previewLang, _variation.useLocalization, _variation.resourceFileName); var clip = Resources.Load(fileName) as AudioClip; if (clip != null) { GetPreviewer().PlayOneShot(clip, calcVolume); } else { DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName); } break; case MasterAudio.AudioLocation.Clip: _variation.VarAudio.PlayOneShot(_variation.VarAudio.clip, calcVolume); break; case MasterAudio.AudioLocation.FileOnInternet: if (!string.IsNullOrEmpty(_variation.internetFileUrl)) { Application.OpenURL(_variation.internetFileUrl); } break; } break; case DTGUIHelper.DTFunctionButtons.Stop: if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { StopPreviewer(); } else { _variation.VarAudio.Stop(); } break; } } EditorGUILayout.EndHorizontal(); if (!Application.isPlaying) { DTGUIHelper.ShowColorWarning(MasterAudio.PreviewText); } var oldLocation = _variation.audLocation; var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation); if (newLocation != oldLocation) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin"); _variation.audLocation = newLocation; } switch (_variation.audLocation) { case MasterAudio.AudioLocation.Clip: var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", _variation.VarAudio.clip, typeof(AudioClip), false); if (newClip != _variation.VarAudio.clip) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "assign Audio Clip"); _variation.VarAudio.clip = newClip; } break; case MasterAudio.AudioLocation.FileOnInternet: if (oldLocation != _variation.audLocation) { if (_variation.VarAudio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on File On Internet Variation."); } _variation.VarAudio.clip = null; } if (!Application.isPlaying) { var newUrl = EditorGUILayout.TextField("Internet File URL", _variation.internetFileUrl); if (newUrl != _variation.internetFileUrl) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Internet File URL"); _variation.internetFileUrl = newUrl; } } if (string.IsNullOrEmpty(_variation.internetFileUrl)) { DTGUIHelper.ShowLargeBarAlert("You have not specified a URL for the File On Internet. This Variation will not be available to play without one."); } break; case MasterAudio.AudioLocation.ResourceFile: if (oldLocation != _variation.audLocation) { if (_variation.VarAudio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation."); } _variation.VarAudio.clip = null; } EditorGUILayout.BeginVertical(); var anEvent = Event.current; GUI.color = DTGUIHelper.DragAreaColor; var dragArea = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true)); GUI.Box(dragArea, "Drag Resource Audio clip here to use its name!"); GUI.color = Color.white; string newFilename; switch (anEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragArea.Contains(anEvent.mousePosition)) { break; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (anEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (var dragged in DragAndDrop.objectReferences) { var aClip = dragged as AudioClip; if (aClip == null) { continue; } AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); var useLocalization = false; newFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization); if (string.IsNullOrEmpty(newFilename)) { newFilename = aClip.name; } _variation.resourceFileName = newFilename; _variation.useLocalization = useLocalization; break; } } Event.current.Use(); break; } EditorGUILayout.EndVertical(); newFilename = EditorGUILayout.TextField("Resource Filename", _variation.resourceFileName); if (newFilename != _variation.resourceFileName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); _variation.resourceFileName = newFilename; } EditorGUI.indentLevel = 1; var newLocal = EditorGUILayout.Toggle("Use Localized Folder", _variation.useLocalization); if (newLocal != _variation.useLocalization) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Localized Folder"); _variation.useLocalization = newLocal; } break; } EditorGUI.indentLevel = 0; var newVolume = EditorGUILayout.Slider("Volume", _variation.VarAudio.volume, 0f, 1f); if (newVolume != _variation.VarAudio.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Volume"); _variation.VarAudio.volume = newVolume; } var newPitch = DTGUIHelper.DisplayPitchField(_variation.VarAudio.pitch); if (newPitch != _variation.VarAudio.pitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Pitch"); _variation.VarAudio.pitch = newPitch; } if (_variation.ParentGroup.curVariationMode == MasterAudioGroup.VariationMode.LoopedChain) { DTGUIHelper.ShowLargeBarAlert("Loop Clip is always OFF for Looped Chain Groups"); } else { var newLoop = EditorGUILayout.Toggle("Loop Clip", _variation.VarAudio.loop); if (newLoop != _variation.VarAudio.loop) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "toggle Loop"); _variation.VarAudio.loop = newLoop; } } var newWeight = EditorGUILayout.IntSlider("Voices (Weight)", _variation.weight, 0, 100); if (newWeight != _variation.weight) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Voices (Weight)"); _variation.weight = newWeight; } var newFxTailTime = EditorGUILayout.Slider("FX Tail Time", _variation.fxTailTime, 0f, 10f); if (newFxTailTime != _variation.fxTailTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change FX Tail Time"); _variation.fxTailTime = newFxTailTime; } var filterList = new List<string>() { MasterAudio.NoGroupName, "Low Pass", "High Pass", "Distortion", "Chorus", "Echo", "Reverb" }; var newFilterIndex = EditorGUILayout.Popup("Add Filter Effect", 0, filterList.ToArray()); switch (newFilterIndex) { case 1: AddFilterComponent(typeof(AudioLowPassFilter)); break; case 2: AddFilterComponent(typeof(AudioHighPassFilter)); break; case 3: AddFilterComponent(typeof(AudioDistortionFilter)); break; case 4: AddFilterComponent(typeof(AudioChorusFilter)); break; case 5: AddFilterComponent(typeof(AudioEchoFilter)); break; case 6: AddFilterComponent(typeof(AudioReverbFilter)); break; } DTGUIHelper.StartGroupHeader(); var newUseRndPitch = EditorGUILayout.BeginToggleGroup(" Use Random Pitch", _variation.useRandomPitch); if (newUseRndPitch != _variation.useRandomPitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Pitch"); _variation.useRandomPitch = newUseRndPitch; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomPitch) { var newMode = (SoundGroupVariation.RandomPitchMode)EditorGUILayout.EnumPopup("Pitch Compute Mode", _variation.randomPitchMode); if (newMode != _variation.randomPitchMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Pitch Compute Mode"); _variation.randomPitchMode = newMode; } var newPitchMin = DTGUIHelper.DisplayPitchField(_variation.randomPitchMin, "Random Pitch Min"); if (newPitchMin != _variation.randomPitchMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Min"); _variation.randomPitchMin = newPitchMin; if (_variation.randomPitchMax <= _variation.randomPitchMin) { _variation.randomPitchMax = _variation.randomPitchMin; } } var newPitchMax = DTGUIHelper.DisplayPitchField(_variation.randomPitchMax, "Random Pitch Max"); if (newPitchMax != _variation.randomPitchMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Max"); _variation.randomPitchMax = newPitchMax; if (_variation.randomPitchMin > _variation.randomPitchMax) { _variation.randomPitchMin = _variation.randomPitchMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newUseRndVol = EditorGUILayout.BeginToggleGroup(" Use Random Volume", _variation.useRandomVolume); if (newUseRndVol != _variation.useRandomVolume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Volume"); _variation.useRandomVolume = newUseRndVol; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomVolume) { var newMode = (SoundGroupVariation.RandomVolumeMode)EditorGUILayout.EnumPopup("Volume Compute Mode", _variation.randomVolumeMode); if (newMode != _variation.randomVolumeMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Volume Compute Mode"); _variation.randomVolumeMode = newMode; } var volMin = 0f; if (_variation.randomVolumeMode == SoundGroupVariation.RandomVolumeMode.AddToClipVolume) { volMin = -1f; } var newVolMin = DTGUIHelper.DisplayVolumeField(_variation.randomVolumeMin, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, volMin, true, "Random Volume Min"); if (newVolMin != _variation.randomVolumeMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Min"); _variation.randomVolumeMin = newVolMin; if (_variation.randomVolumeMax <= _variation.randomVolumeMin) { _variation.randomVolumeMax = _variation.randomVolumeMin; } } var newVolMax = DTGUIHelper.DisplayVolumeField(_variation.randomVolumeMax, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, volMin, true, "Random Volume Max"); if (newVolMax != _variation.randomVolumeMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Max"); _variation.randomVolumeMax = newVolMax; if (_variation.randomVolumeMin > _variation.randomVolumeMax) { _variation.randomVolumeMin = _variation.randomVolumeMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newSilence = EditorGUILayout.BeginToggleGroup(" Use Random Delay", _variation.useIntroSilence); if (newSilence != _variation.useIntroSilence) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Delay"); _variation.useIntroSilence = newSilence; } DTGUIHelper.EndGroupHeader(); if (_variation.useIntroSilence) { var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", _variation.introSilenceMin, 0f, 100f); if (newSilenceMin != _variation.introSilenceMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Min (sec)"); _variation.introSilenceMin = newSilenceMin; if (_variation.introSilenceMin > _variation.introSilenceMax) { _variation.introSilenceMax = newSilenceMin; } } var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", _variation.introSilenceMax, 0f, 100f); if (newSilenceMax != _variation.introSilenceMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Max (sec)"); _variation.introSilenceMax = newSilenceMax; if (_variation.introSilenceMax < _variation.introSilenceMin) { _variation.introSilenceMin = newSilenceMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newStart = EditorGUILayout.BeginToggleGroup(" Use Random Start Position", _variation.useRandomStartTime); if (newStart != _variation.useRandomStartTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Start Position"); _variation.useRandomStartTime = newStart; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomStartTime) { var newMin = EditorGUILayout.Slider("Start Min (%)", _variation.randomStartMinPercent, 0f, 100f); if (newMin != _variation.randomStartMinPercent) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Start Min (%)"); _variation.randomStartMinPercent = newMin; if (_variation.randomStartMaxPercent <= _variation.randomStartMinPercent) { _variation.randomStartMaxPercent = _variation.randomStartMinPercent; } } var newMax = EditorGUILayout.Slider("Start Max (%)", _variation.randomStartMaxPercent, 0f, 100f); if (newMax != _variation.randomStartMaxPercent) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Start Max (%)"); _variation.randomStartMaxPercent = newMax; if (_variation.randomStartMinPercent > _variation.randomStartMaxPercent) { _variation.randomStartMinPercent = _variation.randomStartMaxPercent; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newUseFades = EditorGUILayout.BeginToggleGroup(" Use Custom Fading", _variation.useFades); if (newUseFades != _variation.useFades) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Custom Fading"); _variation.useFades = newUseFades; } DTGUIHelper.EndGroupHeader(); if (_variation.useFades) { var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _variation.fadeInTime, 0f, 10f); if (newFadeIn != _variation.fadeInTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade In Time"); _variation.fadeInTime = newFadeIn; } if (_variation.VarAudio.loop) { DTGUIHelper.ShowColorWarning("Looped clips cannot have a custom fade out."); } else { var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", _variation.fadeOutTime, 0f, 10f); if (newFadeOut != _variation.fadeOutTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade Out Time"); _variation.fadeOutTime = newFadeOut; } } } EditorGUILayout.EndToggleGroup(); if (GUI.changed || isDirty) { EditorUtility.SetDirty(target); } //DrawDefaultInspector(); }
public static DTFunctionButtons AddDynamicVariationButtons(DynamicGroupVariation _variation) { if (GUILayout.Button(new GUIContent(_variation.playTexture, "Click to preview Variation"), EditorStyles.toolbarButton, GUILayout.Width(40))) { return DTFunctionButtons.Play; } if (GUILayout.Button(new GUIContent(_variation.stopTrackTexture, "Click to stop audio preview"), EditorStyles.toolbarButton, GUILayout.Width(40))) { return DTFunctionButtons.Stop; } return DTFunctionButtons.None; }
// ReSharper disable once FunctionComplexityOverflow public override void OnInspectorGUI() { EditorGUI.indentLevel = 1; var isDirty = false; _variation = (DynamicGroupVariation)target; if (MasterAudioInspectorResources.LogoTexture != null) { DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture); } EditorGUI.indentLevel = 0; // Space will handle this for the header var previewLang = SystemLanguage.English; GameObject dgscGO = null; if (_variation.transform.parent != null && _variation.transform.parent.parent != null) { var parentParent = _variation.transform.parent.parent; dgscGO = parentParent.gameObject; var dgsc = dgscGO.GetComponent <DynamicSoundGroupCreator>(); if (dgsc != null) { previewLang = dgsc.previewLanguage; } } if (dgscGO == null) { DTGUIHelper.ShowRedError("This prefab must have a GameObject 2 parents up. Prefab broken."); return; } AudioSource previewer; EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUI.contentColor = DTGUIHelper.BrightButtonColor; if (GUILayout.Button(new GUIContent("Back to Group", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(120))) { // ReSharper disable once PossibleNullReferenceException Selection.activeObject = _variation.transform.parent.gameObject; } GUILayout.FlexibleSpace(); GUI.contentColor = Color.white; var buttonPressed = DTGUIHelper.AddDynamicVariationButtons(); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Play: isDirty = true; previewer = MasterAudioInspector.GetPreviewer(); var randPitch = SoundGroupVariationInspector.GetRandomPreviewPitch(_variation); var varVol = SoundGroupVariationInspector.GetRandomPreviewVolume(_variation); if (_variation.audLocation != MasterAudio.AudioLocation.FileOnInternet) { if (previewer != null) { MasterAudioInspector.StopPreviewer(); previewer.pitch = randPitch; } } var calcVolume = varVol * _variation.ParentGroup.groupMasterVolume; switch (_variation.audLocation) { case MasterAudio.AudioLocation.ResourceFile: var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(previewLang, _variation.useLocalization, _variation.resourceFileName); var clip = Resources.Load(fileName) as AudioClip; if (clip != null) { if (previewer != null) { previewer.PlayOneShot(clip, calcVolume); } } else { DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName); } break; case MasterAudio.AudioLocation.Clip: if (previewer != null) { previewer.PlayOneShot(_variation.VarAudio.clip, calcVolume); } break; case MasterAudio.AudioLocation.FileOnInternet: if (!string.IsNullOrEmpty(_variation.internetFileUrl)) { Application.OpenURL(_variation.internetFileUrl); } break; } break; case DTGUIHelper.DTFunctionButtons.Stop: if (_variation.audLocation != MasterAudio.AudioLocation.FileOnInternet) { MasterAudioInspector.StopPreviewer(); } break; } EditorGUILayout.EndHorizontal(); DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm"); if (!Application.isPlaying) { DTGUIHelper.ShowColorWarning(MasterAudio.PreviewText); } var oldLocation = _variation.audLocation; EditorGUILayout.BeginHorizontal(); var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation); DTGUIHelper.AddHelpIcon("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm#AudioOrigin"); EditorGUILayout.EndHorizontal(); if (newLocation != oldLocation) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin"); _variation.audLocation = newLocation; } switch (_variation.audLocation) { case MasterAudio.AudioLocation.Clip: var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", _variation.VarAudio.clip, typeof(AudioClip), false); if (newClip != _variation.VarAudio.clip) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "assign Audio Clip"); _variation.VarAudio.clip = newClip; } break; case MasterAudio.AudioLocation.FileOnInternet: if (oldLocation != _variation.audLocation) { if (_variation.VarAudio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on File On Internet Variation."); } _variation.VarAudio.clip = null; } if (!Application.isPlaying) { var newUrl = EditorGUILayout.TextField("Internet File URL", _variation.internetFileUrl); if (newUrl != _variation.internetFileUrl) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Internet File URL"); _variation.internetFileUrl = newUrl; } } if (string.IsNullOrEmpty(_variation.internetFileUrl)) { DTGUIHelper.ShowLargeBarAlert("You have not specified a URL for the File On Internet. This Variation will not be available to play without one."); } break; case MasterAudio.AudioLocation.ResourceFile: if (oldLocation != _variation.audLocation) { if (_variation.VarAudio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation."); } _variation.VarAudio.clip = null; } EditorGUILayout.BeginVertical(); var anEvent = Event.current; GUI.color = DTGUIHelper.DragAreaColor; var dragArea = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true)); GUI.Box(dragArea, "Drag Resource Audio clip here to use its name!"); GUI.color = Color.white; string newFilename; switch (anEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragArea.Contains(anEvent.mousePosition)) { break; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (anEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (var dragged in DragAndDrop.objectReferences) { var aClip = dragged as AudioClip; if (aClip == null) { continue; } AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); var useLocalization = false; newFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization); if (string.IsNullOrEmpty(newFilename)) { newFilename = aClip.name; } _variation.resourceFileName = newFilename; _variation.useLocalization = useLocalization; break; } } Event.current.Use(); break; } EditorGUILayout.EndVertical(); newFilename = EditorGUILayout.TextField("Resource Filename", _variation.resourceFileName); if (newFilename != _variation.resourceFileName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); _variation.resourceFileName = newFilename; } EditorGUI.indentLevel = 1; var newLocal = EditorGUILayout.Toggle("Use Localized Folder", _variation.useLocalization); if (newLocal != _variation.useLocalization) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Localized Folder"); _variation.useLocalization = newLocal; } break; } EditorGUI.indentLevel = 0; var newProbability = EditorGUILayout.IntSlider("Probability to Play (%)", _variation.probabilityToPlay, 0, 100); if (newProbability != _variation.probabilityToPlay) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Probability to Play (%)"); _variation.probabilityToPlay = newProbability; } if (_variation.probabilityToPlay < 100) { DTGUIHelper.ShowLargeBarAlert("Since Probability to Play is less than 100%, you will not always hear this Variation when it's selected to play."); } var newVolume = EditorGUILayout.Slider("Volume", _variation.VarAudio.volume, 0f, 1f); if (newVolume != _variation.VarAudio.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Volume"); _variation.VarAudio.volume = newVolume; } var newPitch = DTGUIHelper.DisplayPitchField(_variation.VarAudio.pitch); if (newPitch != _variation.VarAudio.pitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Pitch"); _variation.VarAudio.pitch = newPitch; } if (_variation.ParentGroup.curVariationMode == MasterAudioGroup.VariationMode.LoopedChain) { DTGUIHelper.ShowLargeBarAlert(MasterAudio.LoopDisabledLoopedChain); } else if (_variation.useRandomStartTime && _variation.randomEndPercent != 100f) { DTGUIHelper.ShowLargeBarAlert(MasterAudio.LoopDisabledCustomEnd); } else { var newLoop = EditorGUILayout.Toggle("Loop Clip", _variation.VarAudio.loop); if (newLoop != _variation.VarAudio.loop) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "toggle Loop"); _variation.VarAudio.loop = newLoop; } } EditorGUILayout.BeginHorizontal(); var newWeight = EditorGUILayout.IntSlider("Voices (Weight)", _variation.weight, 0, 100); DTGUIHelper.AddHelpIcon("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm#Voices"); EditorGUILayout.EndHorizontal(); if (newWeight != _variation.weight) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Voices (Weight)"); _variation.weight = newWeight; } DTGUIHelper.StartGroupHeader(); var newUseRndPitch = EditorGUILayout.BeginToggleGroup(" Use Random Pitch", _variation.useRandomPitch); if (newUseRndPitch != _variation.useRandomPitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Pitch"); _variation.useRandomPitch = newUseRndPitch; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomPitch) { var newMode = (SoundGroupVariation.RandomPitchMode)EditorGUILayout.EnumPopup("Pitch Compute Mode", _variation.randomPitchMode); if (newMode != _variation.randomPitchMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Pitch Compute Mode"); _variation.randomPitchMode = newMode; } var newPitchMin = DTGUIHelper.DisplayPitchField(_variation.randomPitchMin, "Random Pitch Min"); if (newPitchMin != _variation.randomPitchMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Min"); _variation.randomPitchMin = newPitchMin; if (_variation.randomPitchMax <= _variation.randomPitchMin) { _variation.randomPitchMax = _variation.randomPitchMin; } } var newPitchMax = DTGUIHelper.DisplayPitchField(_variation.randomPitchMax, "Random Pitch Max"); if (newPitchMax != _variation.randomPitchMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Max"); _variation.randomPitchMax = newPitchMax; if (_variation.randomPitchMin > _variation.randomPitchMax) { _variation.randomPitchMin = _variation.randomPitchMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newUseRndVol = EditorGUILayout.BeginToggleGroup(" Use Random Volume", _variation.useRandomVolume); if (newUseRndVol != _variation.useRandomVolume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Volume"); _variation.useRandomVolume = newUseRndVol; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomVolume) { var newMode = (SoundGroupVariation.RandomVolumeMode)EditorGUILayout.EnumPopup("Volume Compute Mode", _variation.randomVolumeMode); if (newMode != _variation.randomVolumeMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Volume Compute Mode"); _variation.randomVolumeMode = newMode; } var volMin = 0f; if (_variation.randomVolumeMode == SoundGroupVariation.RandomVolumeMode.AddToClipVolume) { volMin = -1f; } var newVolMin = DTGUIHelper.DisplayVolumeField(_variation.randomVolumeMin, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, volMin, true, "Random Volume Min"); if (newVolMin != _variation.randomVolumeMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Min"); _variation.randomVolumeMin = newVolMin; if (_variation.randomVolumeMax <= _variation.randomVolumeMin) { _variation.randomVolumeMax = _variation.randomVolumeMin; } } var newVolMax = DTGUIHelper.DisplayVolumeField(_variation.randomVolumeMax, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, volMin, true, "Random Volume Max"); if (newVolMax != _variation.randomVolumeMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Max"); _variation.randomVolumeMax = newVolMax; if (_variation.randomVolumeMin > _variation.randomVolumeMax) { _variation.randomVolumeMin = _variation.randomVolumeMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newSilence = EditorGUILayout.BeginToggleGroup(" Use Random Delay", _variation.useIntroSilence); if (newSilence != _variation.useIntroSilence) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Delay"); _variation.useIntroSilence = newSilence; } DTGUIHelper.EndGroupHeader(); if (_variation.useIntroSilence) { var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", _variation.introSilenceMin, 0f, 100f); if (newSilenceMin != _variation.introSilenceMin) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Min (sec)"); _variation.introSilenceMin = newSilenceMin; if (_variation.introSilenceMin > _variation.introSilenceMax) { _variation.introSilenceMax = newSilenceMin; } } var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", _variation.introSilenceMax, 0f, 100f); if (newSilenceMax != _variation.introSilenceMax) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Max (sec)"); _variation.introSilenceMax = newSilenceMax; if (_variation.introSilenceMax < _variation.introSilenceMin) { _variation.introSilenceMin = newSilenceMax; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newStart = EditorGUILayout.BeginToggleGroup(" Use Custom Start/End Position", _variation.useRandomStartTime); if (newStart != _variation.useRandomStartTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Custom Start/End Position"); _variation.useRandomStartTime = newStart; } DTGUIHelper.EndGroupHeader(); if (_variation.useRandomStartTime) { var newMin = EditorGUILayout.Slider("Start Min (%)", _variation.randomStartMinPercent, 0f, 100f); if (newMin != _variation.randomStartMinPercent) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Start Min (%)"); _variation.randomStartMinPercent = newMin; if (_variation.randomStartMaxPercent <= _variation.randomStartMinPercent) { _variation.randomStartMaxPercent = _variation.randomStartMinPercent; } } var newMax = EditorGUILayout.Slider("Start Max (%)", _variation.randomStartMaxPercent, 0f, 100f); if (newMax != _variation.randomStartMaxPercent) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Start Max (%)"); _variation.randomStartMaxPercent = newMax; if (_variation.randomStartMinPercent > _variation.randomStartMaxPercent) { _variation.randomStartMinPercent = _variation.randomStartMaxPercent; } } var newEnd = EditorGUILayout.Slider("End (%)", _variation.randomEndPercent, 0f, 100f); if (newEnd != _variation.randomEndPercent || _variation.randomEndPercent < _variation.randomStartMaxPercent) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change End (%)"); _variation.randomEndPercent = newEnd; if (_variation.randomEndPercent < _variation.randomStartMaxPercent) { _variation.randomEndPercent = _variation.randomStartMaxPercent; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); if (_variation.VarAudio.loop) { DTGUIHelper.StartGroupHeader(); newStart = EditorGUILayout.BeginToggleGroup(" Use Finite Looping", _variation.useCustomLooping); if (newStart != _variation.useCustomLooping) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Finite Looping"); _variation.useCustomLooping = newStart; } DTGUIHelper.EndGroupHeader(); if (_variation.useCustomLooping) { var newMin = EditorGUILayout.IntSlider("Min Loops", _variation.minCustomLoops, 1, 100); if (newMin != _variation.minCustomLoops) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Min Loops"); _variation.minCustomLoops = newMin; if (_variation.maxCustomLoops <= _variation.minCustomLoops) { _variation.maxCustomLoops = _variation.minCustomLoops; } } var newMax = EditorGUILayout.IntSlider("Max Loops", _variation.maxCustomLoops, 1, 100); if (newMax != _variation.maxCustomLoops) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Max Loops"); _variation.maxCustomLoops = newMax; if (_variation.minCustomLoops > _variation.maxCustomLoops) { _variation.minCustomLoops = _variation.maxCustomLoops; } } } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); } DTGUIHelper.StartGroupHeader(); var newUseFades = EditorGUILayout.BeginToggleGroup(" Use Custom Fading", _variation.useFades); if (newUseFades != _variation.useFades) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Custom Fading"); _variation.useFades = newUseFades; } DTGUIHelper.EndGroupHeader(); if (_variation.useFades) { var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _variation.fadeInTime, 0f, 10f); if (newFadeIn != _variation.fadeInTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade In Time"); _variation.fadeInTime = newFadeIn; } if (_variation.VarAudio.loop) { DTGUIHelper.ShowColorWarning("Looped clips cannot have a custom fade out."); } else { var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", _variation.fadeOutTime, 0f, 10f); if (newFadeOut != _variation.fadeOutTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade Out Time"); _variation.fadeOutTime = newFadeOut; } } } EditorGUILayout.EndToggleGroup(); if (GUI.changed || isDirty) { EditorUtility.SetDirty(target); } //DrawDefaultInspector(); }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(); EditorGUI.indentLevel = 1; var isDirty = false; _variation = (DynamicGroupVariation)target; if (MasterAudioInspectorResources.logoTexture != null) { DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture); } EditorGUI.indentLevel = 0; // Space will handle this for the header if (_variation.transform.parent != null && _variation.transform.parent.parent != null) { _creator = _variation.transform.parent.parent.GetComponent<DynamicSoundGroupCreator>(); } if (_creator == null) { DTGUIHelper.ShowRedError("This prefab must have DynamicSoundGroupCreator 2 parents up."); return; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUI.contentColor = Color.green; if (GUILayout.Button(new GUIContent("Back to Group", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(120))) { Selection.activeObject = _variation.transform.parent.gameObject; } GUILayout.FlexibleSpace(); GUI.contentColor = Color.white; var buttonPressed = DTGUIHelper.AddDynamicVariationButtons(); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Play: isDirty = true; var calcVolume = _variation.VarAudio.volume * _variation.ParentGroup.groupMasterVolume; if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { _creator.PreviewerInstance.Stop(); var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(_creator, _variation.useLocalization, _variation.resourceFileName); var clip = Resources.Load(fileName) as AudioClip; if (clip != null) { _creator.PreviewerInstance.PlayOneShot(clip, calcVolume); } else { DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName); } } else { _variation.VarAudio.PlayOneShot(_variation.VarAudio.clip, calcVolume); } break; case DTGUIHelper.DTFunctionButtons.Stop: if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { _creator.PreviewerInstance.Stop(); } else { _variation.VarAudio.Stop(); } break; } EditorGUILayout.EndHorizontal(); if (!Application.isPlaying) { DTGUIHelper.ShowColorWarning(MasterAudio.PREVIEW_TEXT); } var oldLocation = _variation.audLocation; var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation); if (newLocation != oldLocation) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin"); _variation.audLocation = newLocation; } switch (_variation.audLocation) { case MasterAudio.AudioLocation.Clip: var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", _variation.VarAudio.clip, typeof(AudioClip), false); if (newClip != _variation.VarAudio.clip) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "assign Audio Clip"); _variation.VarAudio.clip = newClip; } break; case MasterAudio.AudioLocation.ResourceFile: if (oldLocation != _variation.audLocation) { if (_variation.VarAudio.clip != null) { Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation."); } _variation.VarAudio.clip = null; } EditorGUILayout.BeginVertical(); var anEvent = Event.current; GUI.color = Color.yellow; var dragArea = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true)); GUI.Box(dragArea, "Drag Resource Audio clip here to use its name!"); GUI.color = Color.white; var newFilename = string.Empty; switch (anEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragArea.Contains(anEvent.mousePosition)) { break; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (anEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (var dragged in DragAndDrop.objectReferences) { var aClip = dragged as AudioClip; if (aClip == null) { continue; } UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); var useLocalization = false; newFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization); if (string.IsNullOrEmpty(newFilename)) { newFilename = aClip.name; } _variation.resourceFileName = newFilename; _variation.useLocalization = useLocalization; break; } } Event.current.Use(); break; } EditorGUILayout.EndVertical(); newFilename = EditorGUILayout.TextField("Resource Filename", _variation.resourceFileName); if (newFilename != _variation.resourceFileName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename"); _variation.resourceFileName = newFilename; } EditorGUI.indentLevel = 1; var newLocal = EditorGUILayout.Toggle("Use Localized Folder", _variation.useLocalization); if (newLocal != _variation.useLocalization) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Localized Folder"); _variation.useLocalization = newLocal; } break; } EditorGUI.indentLevel = 0; var newVolume = EditorGUILayout.Slider("Volume", _variation.VarAudio.volume, 0f, 1f); if (newVolume != _variation.VarAudio.volume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Volume"); _variation.VarAudio.volume = newVolume; } var newPitch = EditorGUILayout.Slider("Pitch", _variation.VarAudio.pitch, -3f, 3f); if (newPitch != _variation.VarAudio.pitch) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Pitch"); _variation.VarAudio.pitch = newPitch; } var newLoop = EditorGUILayout.Toggle("Loop Clip", _variation.VarAudio.loop); if (newLoop != _variation.VarAudio.loop) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "toggle Loop"); _variation.VarAudio.loop = newLoop; } var newWeight = EditorGUILayout.IntSlider("Weight (Instances)", _variation.weight, 0, 100); if (newWeight != _variation.weight) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Weight"); _variation.weight = newWeight; } var newFxTailTime = EditorGUILayout.Slider("FX Tail Time", _variation.fxTailTime, 0f, 10f); if (newFxTailTime != _variation.fxTailTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change FX Tail Time"); _variation.fxTailTime = newFxTailTime; } var newUseRndPitch = EditorGUILayout.BeginToggleGroup("Use Random Pitch", _variation.useRandomPitch); if (newUseRndPitch != _variation.useRandomPitch) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Pitch"); _variation.useRandomPitch = newUseRndPitch; } if (_variation.useRandomPitch) { var newMode = (SoundGroupVariation.RandomPitchMode)EditorGUILayout.EnumPopup("Pitch Compute Mode", _variation.randomPitchMode); if (newMode != _variation.randomPitchMode) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Pitch Compute Mode"); _variation.randomPitchMode = newMode; } var newPitchMin = EditorGUILayout.Slider("Random Pitch Min", _variation.randomPitchMin, -3f, 3f); if (newPitchMin != _variation.randomPitchMin) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Min"); _variation.randomPitchMin = newPitchMin; if (_variation.randomPitchMax <= _variation.randomPitchMin) { _variation.randomPitchMax = _variation.randomPitchMin; } } var newPitchMax = EditorGUILayout.Slider("Random Pitch Max", _variation.randomPitchMax, -3f, 3f); if (newPitchMax != _variation.randomPitchMax) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Max"); _variation.randomPitchMax = newPitchMax; if (_variation.randomPitchMin > _variation.randomPitchMax) { _variation.randomPitchMin = _variation.randomPitchMax; } } } EditorGUILayout.EndToggleGroup(); var newUseRndVol = EditorGUILayout.BeginToggleGroup("Use Random Volume", _variation.useRandomVolume); if (newUseRndVol != _variation.useRandomVolume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Volume"); _variation.useRandomVolume = newUseRndVol; } if (_variation.useRandomVolume) { var newMode = (SoundGroupVariation.RandomVolumeMode)EditorGUILayout.EnumPopup("Volume Compute Mode", _variation.randomVolumeMode); if (newMode != _variation.randomVolumeMode) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Volume Compute Mode"); _variation.randomVolumeMode = newMode; } var volMin = 0f; if (_variation.randomVolumeMode == SoundGroupVariation.RandomVolumeMode.AddToClipVolume) { volMin = -1f; } var newVolMin = EditorGUILayout.Slider("Random Volume Min", _variation.randomVolumeMin, volMin, 1f); if (newVolMin != _variation.randomVolumeMin) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Min"); _variation.randomVolumeMin = newVolMin; if (_variation.randomVolumeMax <= _variation.randomVolumeMin) { _variation.randomVolumeMax = _variation.randomVolumeMin; } } var newVolMax = EditorGUILayout.Slider("Random Volume Max", _variation.randomVolumeMax, volMin, 1f); if (newVolMax != _variation.randomVolumeMax) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Max"); _variation.randomVolumeMax = newVolMax; if (_variation.randomVolumeMin > _variation.randomVolumeMax) { _variation.randomVolumeMin = _variation.randomVolumeMax; } } } EditorGUILayout.EndToggleGroup(); var newSilence = EditorGUILayout.BeginToggleGroup("Use Random Delay", _variation.useIntroSilence); if (newSilence != _variation.useIntroSilence) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Delay"); _variation.useIntroSilence = newSilence; } if (_variation.useIntroSilence) { var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", _variation.introSilenceMin, 0f, 100f); if (newSilenceMin != _variation.introSilenceMin) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Min (sec)"); _variation.introSilenceMin = newSilenceMin; if (_variation.introSilenceMin > _variation.introSilenceMax) { _variation.introSilenceMax = newSilenceMin; } } var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", _variation.introSilenceMax, 0f, 100f); if (newSilenceMax != _variation.introSilenceMax) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Max (sec)"); _variation.introSilenceMax = newSilenceMax; if (_variation.introSilenceMax < _variation.introSilenceMin) { _variation.introSilenceMin = newSilenceMax; } } } EditorGUILayout.EndToggleGroup(); var newUseFades = EditorGUILayout.BeginToggleGroup("Use Custom Fading", _variation.useFades); if (newUseFades != _variation.useFades) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Custom Fading"); _variation.useFades = newUseFades; } if (_variation.useFades) { var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _variation.fadeInTime, 0f, 10f); if (newFadeIn != _variation.fadeInTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade In Time"); _variation.fadeInTime = newFadeIn; } if (_variation.VarAudio.loop) { DTGUIHelper.ShowColorWarning("*Looped clips cannot have a custom fade out."); } else { var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", _variation.fadeOutTime, 0f, 10f); if (newFadeOut != _variation.fadeOutTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade Out Time"); _variation.fadeOutTime = newFadeOut; } } } EditorGUILayout.EndToggleGroup(); var filterList = new List<string>() { MasterAudio.NO_GROUP_NAME, "Low Pass", "High Pass", "Distortion", "Chorus", "Echo", "Reverb" }; var newFilterIndex = EditorGUILayout.Popup("Add Filter Effect", 0, filterList.ToArray()); switch (newFilterIndex) { case 1: AddFilterComponent(typeof(AudioLowPassFilter)); break; case 2: AddFilterComponent(typeof(AudioHighPassFilter)); break; case 3: AddFilterComponent(typeof(AudioDistortionFilter)); break; case 4: AddFilterComponent(typeof(AudioChorusFilter)); break; case 5: AddFilterComponent(typeof(AudioEchoFilter)); break; case 6: AddFilterComponent(typeof(AudioReverbFilter)); break; } if (GUI.changed || isDirty) { EditorUtility.SetDirty(target); } //DrawDefaultInspector(); }
public static void CopyOculusAudioSource(DynamicGroupVariation sourceVariation, SoundGroupVariation destVariation) { return; }
public static void CopyResonanceAudioSource(SoundGroupVariation sourceVariation, DynamicGroupVariation destVariation) { return; }