Esempio n. 1
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 0;

        var ma = MasterAudio.Instance;

        if (ma != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }

        ButtonClicker sounds = (ButtonClicker)target;

        maInScene = ma != null;
        if (maInScene)
        {
            groupNames = ma.GroupNames;
        }

        var resizeOnClick = EditorGUILayout.Toggle("Resize On Click", sounds.resizeOnClick);

        if (resizeOnClick != sounds.resizeOnClick)
        {
            UndoHelper.RecordObjectPropertyForUndo(sounds, "change Resize On Click");
            sounds.resizeOnClick = resizeOnClick;
        }

        var resizeOnHover = EditorGUILayout.Toggle("Resize On Hover", sounds.resizeOnHover);

        if (resizeOnHover != sounds.resizeOnHover)
        {
            UndoHelper.RecordObjectPropertyForUndo(sounds, "change Resize On Hover");
            sounds.resizeOnHover = resizeOnHover;
        }

        EditSoundGroup(sounds, ref sounds.mouseDownSound, "Mouse Down Sound");
        EditSoundGroup(sounds, ref sounds.mouseUpSound, "Mouse Up Sound");
        EditSoundGroup(sounds, ref sounds.mouseClickSound, "Mouse Click Sound");
        EditSoundGroup(sounds, ref sounds.mouseOverSound, "Mouse Over Sound");
        EditSoundGroup(sounds, ref sounds.mouseOutSound, "Mouse Out Sound");

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        this.Repaint();

        //DrawDefaultInspector();
    }
    // 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();
    }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            MasterAudio.Instance = null;

            var _ma        = MasterAudio.Instance;
            var _maInScene = _ma != null;

            if (_maInScene)
            {
                DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            }

            DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/AmbientSound.htm");

            var canUse = true;

#if !PHY3D_ENABLED
            canUse = false;
#endif
            if (!canUse)
            {
                DTGUIHelper.ShowLargeBarAlert("You must enable 3D Physics support for your Collider or Trigger or this script will not function. Use the Welcome Window to do that, then this Inspector will show its controls.");
                return;
            }

            var _isDirty = false;

            var _sounds = (DarkTonic.MasterAudio.AmbientSound)target;

            var _groupNames = new List <string>();

            if (_maInScene)
            {
                // ReSharper disable once PossibleNullReferenceException
                _groupNames = _ma.GroupNames;
            }

            PopulateItemNames(_groupNames);

            if (GUI.changed || _isDirty)
            {
                EditorUtility.SetDirty(target);
            }

            if (_maInScene)
            {
                var existingIndex = _groupNames.IndexOf(_sounds.AmbientSoundGroup);

                int?groupIndex = null;

                var noGroup = false;
                var noMatch = false;

                if (existingIndex >= 1)
                {
                    EditorGUILayout.BeginHorizontal();
                    groupIndex = EditorGUILayout.Popup("Ambient Sound Group", existingIndex, _groupNames.ToArray());
                    if (existingIndex == 1)
                    {
                        noGroup = true;
                    }

                    var isUsingVideoPlayersGroup = false;

                    if (_groupNames[groupIndex.Value] == MasterAudio.VideoPlayerSoundGroupName)
                    {
                        isUsingVideoPlayersGroup = true;
                    }

                    if (groupIndex > MasterAudio.HardCodedBusOptions - 1)
                    {
                        var button = DTGUIHelper.AddSettingsButton("Ambient Sound Group");
                        switch (button)
                        {
                        case DTGUIHelper.DTFunctionButtons.Go:
                            var grp = _groupNames[existingIndex];
                            var trs = MasterAudio.FindGroupTransform(grp);
                            if (trs != null)
                            {
                                Selection.activeObject = trs;
                            }
                            break;
                        }

                        var buttonPress = DTGUIHelper.AddDynamicVariationButtons();
                        var sType       = _groupNames[existingIndex];

                        switch (buttonPress)
                        {
                        case DTGUIHelper.DTFunctionButtons.Play:
                            DTGUIHelper.PreviewSoundGroup(sType);
                            break;

                        case DTGUIHelper.DTFunctionButtons.Stop:
                            DTGUIHelper.StopPreview(sType);
                            break;
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                    if (isUsingVideoPlayersGroup)
                    {
                        DTGUIHelper.ShowRedError(MasterAudio.VideoPlayersSoundGroupSelectedError);
                    }
                }
                else if (existingIndex == -1 && _sounds.AmbientSoundGroup == MasterAudio.NoGroupName)
                {
                    groupIndex = EditorGUILayout.Popup("Ambient Sound Group", existingIndex, _groupNames.ToArray());
                }
                else
                { // non-match
                    noMatch = true;
                    var newSound = EditorGUILayout.TextField("Ambient Sound Group", _sounds.AmbientSoundGroup);
                    if (newSound != _sounds.AmbientSoundGroup)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                        _sounds.AmbientSoundGroup = newSound;
                        _sounds.CalculateRadius();
                    }

                    var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray());
                    if (newIndex >= 0)
                    {
                        groupIndex = newIndex;
                    }
                }

                if (noGroup)
                {
                    DTGUIHelper.ShowRedError("No Ambient Sound Group specified.");
                }
                else if (noMatch)
                {
                    DTGUIHelper.ShowRedError("Ambient Sound Group found no match. Type in or choose one.");
                }

                if (groupIndex.HasValue)
                {
                    if (existingIndex != groupIndex.Value)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                    }
                    switch (groupIndex.Value)
                    {
                    case -1:
                        _sounds.AmbientSoundGroup = MasterAudio.NoGroupName;
                        break;

                    default:
                        _sounds.AmbientSoundGroup = _groupNames[groupIndex.Value];
                        break;
                    }
                    _sounds.CalculateRadius();
                }
            }
            else
            {
                var newSType = EditorGUILayout.TextField("Ambient Sound Group", _sounds.AmbientSoundGroup);
                if (newSType != _sounds.AmbientSoundGroup)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                    _sounds.CalculateRadius();
                    _sounds.AmbientSoundGroup = newSType;
                }
            }

            var newVol = DTGUIHelper.DisplayVolumeField(_sounds.playVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
            if (newVol != _sounds.playVolume)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume");
                _sounds.playVolume = newVol;
            }

            var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", _sounds.variationType);
            if (newVarType != _sounds.variationType)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Mode");
                _sounds.CalculateRadius();
                _sounds.variationType = newVarType;
            }

            if (_sounds.variationType == EventSounds.VariationType.PlaySpecific)
            {
                var newVarName = EditorGUILayout.TextField("Variation Name", _sounds.variationName);
                if (newVarName != _sounds.variationName)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Name");
                    _sounds.CalculateRadius();
                    _sounds.variationName = newVarName;
                }

                if (string.IsNullOrEmpty(_sounds.variationName))
                {
                    DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play.");
                }
            }

            var newExitMode = (MasterAudio.AmbientSoundExitMode)EditorGUILayout.EnumPopup("Trigger Exit Behavior", _sounds.exitMode);
            if (newExitMode != _sounds.exitMode)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Trigger Exit Behavior");
                _sounds.exitMode = newExitMode;
            }

            if (_sounds.exitMode == MasterAudio.AmbientSoundExitMode.FadeSound)
            {
                var newFadeTime = EditorGUILayout.Slider("Fade Time (sec)", _sounds.exitFadeTime, .2f, 10f);
                if (newFadeTime != _sounds.exitFadeTime)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time (sec)");
                    _sounds.exitFadeTime = newFadeTime;
                }

                var reEnterMode = (MasterAudio.AmbientSoundReEnterMode)EditorGUILayout.EnumPopup("Trigger Re-Enter Behavior", _sounds.reEnterMode);
                if (reEnterMode != _sounds.reEnterMode)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Trigger Re-Enter Behavior");
                    _sounds.reEnterMode = reEnterMode;
                }

                if (_sounds.reEnterMode == MasterAudio.AmbientSoundReEnterMode.FadeInSameSound)
                {
                    var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _sounds.reEnterFadeTime, .2f, 10f);
                    if (newFadeIn != _sounds.reEnterFadeTime)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade In Time (sec)");
                        _sounds.reEnterFadeTime = newFadeIn;
                    }
                }
            }

            var aud = _sounds.GetNamedOrFirstAudioSource();
            if (aud != null)
            {
                var newMin = EditorGUILayout.Slider("Min Distance", aud.minDistance, .1f, aud.maxDistance);
                if (newMin != aud.minDistance)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, aud, "change Min Distance");

                    switch (_sounds.variationType)
                    {
                    case EventSounds.VariationType.PlayRandom:
                        var sources = _sounds.GetAllVariationAudioSources();
                        if (sources != null)
                        {
                            for (var i = 0; i < sources.Count; i++)
                            {
                                var src = sources[i];
                                src.minDistance = newMin;
                                EditorUtility.SetDirty(src);
                            }
                        }
                        break;

                    case EventSounds.VariationType.PlaySpecific:
                        aud.minDistance = newMin;
                        EditorUtility.SetDirty(aud);
                        break;
                    }
                }

                var newMax = EditorGUILayout.Slider("Max Distance", aud.maxDistance, aud.minDistance, 1000000f);
                if (newMax != aud.maxDistance)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, aud, "change Max Distance");

                    switch (_sounds.variationType)
                    {
                    case EventSounds.VariationType.PlayRandom:
                        var sources = _sounds.GetAllVariationAudioSources();
                        if (sources != null)
                        {
                            for (var i = 0; i < sources.Count; i++)
                            {
                                var src = sources[i];
                                src.maxDistance = newMax;
                                EditorUtility.SetDirty(src);
                            }
                        }
                        break;

                    case EventSounds.VariationType.PlaySpecific:
                        aud.maxDistance = newMax;
                        EditorUtility.SetDirty(aud);
                        break;
                    }
                }
                switch (_sounds.variationType)
                {
                case EventSounds.VariationType.PlayRandom:
                    DTGUIHelper.ShowLargeBarAlert("Adjusting the Min/Max Distance field will change the Min/Max Distance field(s) on the Audio Source of every Variation in the selected Sound Group.");
                    break;

                case EventSounds.VariationType.PlaySpecific:
                    DTGUIHelper.ShowLargeBarAlert("Adjusting the Min/Max Distance field will change the Min/Max Distance field(s) on the Audio Source for the selected Variation in the selected Sound Group.");
                    break;
                }
                DTGUIHelper.ShowColorWarning("You can also bulk apply Min/Max Distance and other Audio Source properties with Audio Source Templates using the Master Audio Mixer.");
            }

            DTGUIHelper.StartGroupHeader();
            var newClosest = GUILayout.Toggle(_sounds.UseClosestColliderPosition, new GUIContent(" Use Closest Collider Position", "Using this option, the Audio Source will be updated every frame to the closest position on the caller's collider(s)."));
            if (newClosest != _sounds.UseClosestColliderPosition)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Follow Caller");
                _sounds.UseClosestColliderPosition = newClosest;
            }

            EditorGUILayout.EndVertical();
            if (_sounds.UseClosestColliderPosition)
            {
                var newTop = EditorGUILayout.Toggle("Use Top Collider", _sounds.UseTopCollider);
                if (newTop != _sounds.UseTopCollider)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Use Top Collider");
                    _sounds.UseTopCollider = newTop;
                }
                var newChild = EditorGUILayout.Toggle("Use Child G.O. Colliders", _sounds.IncludeChildColliders);
                if (newChild != _sounds.IncludeChildColliders)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Use Child G.O. Colliders");
                    _sounds.IncludeChildColliders = newChild;
                }

                var colliderObjects = new List <GameObject>();

                if (_sounds.UseTopCollider)
                {
                    var collider   = _sounds.GetComponent <Collider>();
                    var collider2d = _sounds.GetComponent <Collider2D>();
                    if (collider != null)
                    {
                        colliderObjects.Add(collider.gameObject);
                    }
                    else if (collider2d != null)
                    {
                        colliderObjects.Add(collider2d.gameObject);
                    }
                }
                if (_sounds.IncludeChildColliders)
                {
                    for (var i = 0; i < _sounds.transform.childCount; i++)
                    {
                        var child      = _sounds.transform.GetChild(i);
                        var collider   = child.GetComponent <Collider>();
                        var collider2d = child.GetComponent <Collider2D>();
                        if (collider != null)
                        {
                            colliderObjects.Add(collider.gameObject);
                        }
                        else if (collider2d != null)
                        {
                            colliderObjects.Add(collider2d.gameObject);
                        }
                    }
                }

                if (colliderObjects.Count == 0)
                {
                    DTGUIHelper.ShowRedError("You have zero Colliders selected, so this functionality will not work.");
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    DTGUIHelper.ShowColorWarning("Colliders used: " + colliderObjects.Count);
                    if (GUILayout.Button("Select\nColliders", GUILayout.Width(70)))
                    {
                        Selection.objects = colliderObjects.ToArray();
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.EndVertical();

                DTGUIHelper.StartGroupHeader();
                var newFollow =
                    GUILayout.Toggle(_sounds.FollowCaller, new GUIContent(" Follow Caller",
                                                                          "This option is useful if your caller ever moves, as it will make the Audio Source follow to the location of the caller every frame."));
                if (newFollow != _sounds.FollowCaller)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Follow Caller");
                    _sounds.FollowCaller = newFollow;
                }
                EditorGUILayout.EndVertical();
                if (_sounds.FollowCaller)
                {
                    DTGUIHelper.ShowColorWarning("Will follow caller at runtime.");
                }
                EditorGUILayout.EndVertical();
            }

            if (Application.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Follower Object");
                EditorGUILayout.ObjectField(_sounds.RuntimeFollower, typeof(Transform), false);
                EditorGUILayout.EndHorizontal();
            }

            //DrawDefaultInspector();
        }
Esempio n. 4
0
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        var ma = MasterAudio.Instance;

        _maInScene = ma != null;

        if (_maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        var sounds = (ButtonClicker)target;

        if (_maInScene)
        {
            // ReSharper disable once PossibleNullReferenceException
            _groupNames = ma.GroupNames;
        }
        PopulateGroupNames(_groupNames);

        var resizeOnClick = EditorGUILayout.Toggle("Resize On Click", sounds.resizeOnClick);

        if (resizeOnClick != sounds.resizeOnClick)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, sounds, "change Resize On Click");
            sounds.resizeOnClick = resizeOnClick;
        }

        if (sounds.resizeOnClick)
        {
            EditorGUI.indentLevel = 1;
            var newResize = EditorGUILayout.Toggle("Resize All Siblings", sounds.resizeClickAllSiblings);
            if (newResize != sounds.resizeClickAllSiblings)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, sounds, "Toggle Resize All Siblings");
                sounds.resizeClickAllSiblings = newResize;
            }
        }

        EditorGUI.indentLevel = 0;
        var resizeOnHover = EditorGUILayout.Toggle("Resize On Hover", sounds.resizeOnHover);

        if (resizeOnHover != sounds.resizeOnHover)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, sounds, "change Resize On Hover");
            sounds.resizeOnHover = resizeOnHover;
        }

        if (sounds.resizeOnHover)
        {
            EditorGUI.indentLevel = 1;
            var newResize = EditorGUILayout.Toggle("Resize All Siblings", sounds.resizeHoverAllSiblings);
            if (newResize != sounds.resizeHoverAllSiblings)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, sounds, "Toggle Resize All Siblings");
                sounds.resizeHoverAllSiblings = newResize;
            }
        }

        EditorGUI.indentLevel = 0;

        EditSoundGroup(sounds, ref sounds.mouseDownSound, "Mouse Down Sound");
        EditSoundGroup(sounds, ref sounds.mouseUpSound, "Mouse Up Sound");
        EditSoundGroup(sounds, ref sounds.mouseClickSound, "Mouse Click Sound");
        EditSoundGroup(sounds, ref sounds.mouseOverSound, "Mouse Over Sound");
        EditSoundGroup(sounds, ref sounds.mouseOutSound, "Mouse Out Sound");

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 1;

        var ma = MasterAudio.Instance;

        if (ma != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }

        EventCalcSounds sounds = (EventCalcSounds)target;

        maInScene = ma != null;
        if (maInScene)
        {
            groupNames = ma.GroupNames;
        }

        GUILayout.Label("Group Controls", EditorStyles.boldLabel);

        var newSpawnMode = (MasterAudio.SoundSpawnLocationMode)EditorGUILayout.EnumPopup("Sound Spawn Mode", sounds.soundSpawnMode);

        if (newSpawnMode != sounds.soundSpawnMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(sounds, "change Spawn Mode");
            sounds.soundSpawnMode = newSpawnMode;
        }

        var newDisable = EditorGUILayout.Toggle("Disable Sounds", sounds.disableSounds);

        if (newDisable != sounds.disableSounds)
        {
            UndoHelper.RecordObjectPropertyForUndo(sounds, "toggle Disable Sounds");
            sounds.disableSounds = newDisable;
        }

        EditorGUILayout.Separator();
        GUILayout.Label("Sound Triggers", EditorStyles.boldLabel);

        var disabledText = "";

        if (sounds.disableSounds)
        {
            disabledText = " (DISABLED) ";
        }

        var aud = sounds.GetComponent <AudioSource>();

        if (aud == null || aud.clip == null)
        {
            GUI.color = Color.green;
            EditorGUILayout.LabelField("Audio Source Ended Sound - needs AudioSource component.", EditorStyles.whiteMiniLabel);
            GUI.color = Color.white;
            sounds.useAudioSourceEndedSound = false;
        }
        else
        {
            var newAudioEnded = EditorGUILayout.BeginToggleGroup("Audio Source Ended" + disabledText, sounds.useAudioSourceEndedSound);
            if (newAudioEnded != sounds.useAudioSourceEndedSound)
            {
                UndoHelper.RecordObjectPropertyForUndo(sounds, "toggle Audio  Source Ended");
                sounds.useAudioSourceEndedSound = newAudioEnded;
            }
            if (sounds.useAudioSourceEndedSound && !sounds.disableSounds)
            {
                EditorGUI.indentLevel = 2;

                if (maInScene)
                {
                    var existingIndex = groupNames.IndexOf(sounds.audioSourceEndedSound.soundType);

                    int?groupIndex = null;
                    var noMatch    = false;

                    if (existingIndex >= 1)
                    {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray());
                    }
                    else if (existingIndex == -1 && sounds.audioSourceEndedSound.soundType == MasterAudio.NO_GROUP_NAME)
                    {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray());
                    }
                    else                         // non-match
                    {
                        noMatch = true;
                        var newGroup = EditorGUILayout.TextField("Sound Group", sounds.audioSourceEndedSound.soundType);
                        if (newGroup != sounds.audioSourceEndedSound.soundType)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
                            sounds.audioSourceEndedSound.soundType = newGroup;
                        }
                        var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, groupNames.ToArray());
                        if (newIndex >= 0)
                        {
                            groupIndex = newIndex;
                        }
                    }

                    if (noMatch)
                    {
                        DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one.");
                    }

                    if (groupIndex.HasValue)
                    {
                        if (existingIndex != groupIndex.Value)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
                        }

                        if (groupIndex.Value == -1)
                        {
                            sounds.audioSourceEndedSound.soundType = MasterAudio.NO_GROUP_NAME;
                        }
                        else
                        {
                            sounds.audioSourceEndedSound.soundType = groupNames[groupIndex.Value];
                        }
                    }
                }
                else
                {
                    var newSoundGroup = EditorGUILayout.TextField("Sound Group", sounds.audioSourceEndedSound.soundType);
                    if (newSoundGroup != sounds.audioSourceEndedSound.soundType)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
                        sounds.audioSourceEndedSound.soundType = newSoundGroup;
                    }
                }

                var newVolume = EditorGUILayout.Slider("Volume", sounds.audioSourceEndedSound.volume, 0f, 1f);
                if (newVolume != sounds.audioSourceEndedSound.volume)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "change Volume");
                    sounds.audioSourceEndedSound.volume = newVolume;
                }

                var newPitch = EditorGUILayout.Toggle("Override pitch?", sounds.audioSourceEndedSound.useFixedPitch);
                if (newPitch != sounds.audioSourceEndedSound.useFixedPitch)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "toggle Override pitch");
                    sounds.audioSourceEndedSound.useFixedPitch = newPitch;
                }

                if (sounds.audioSourceEndedSound.useFixedPitch)
                {
                    DTGUIHelper.ShowColorWarning("*Random pitches for the variation will not be used.");
                    var newFixedPitch = EditorGUILayout.Slider("Pitch", sounds.audioSourceEndedSound.pitch, -3f, 3f);
                    if (newFixedPitch != sounds.audioSourceEndedSound.pitch)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(sounds, "change Pitch");
                        sounds.audioSourceEndedSound.pitch = newFixedPitch;
                    }
                }

                var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", sounds.audioSourceEndedSound.delaySound, 0f, 10f);
                if (newDelay != sounds.audioSourceEndedSound.delaySound)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "change Delay Sound");
                    sounds.audioSourceEndedSound.delaySound = newDelay;
                }

                var newEmit = EditorGUILayout.Toggle("Emit Particle", sounds.audioSourceEndedSound.emitParticles);
                if (newEmit != sounds.audioSourceEndedSound.emitParticles)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "toggle Emit Particle");
                    sounds.audioSourceEndedSound.emitParticles = newEmit;
                }

                var newParticleCount = EditorGUILayout.IntSlider("Particle Count", sounds.audioSourceEndedSound.particleCountToEmit, 1, 100);
                if (newParticleCount != sounds.audioSourceEndedSound.particleCountToEmit)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "change Particle Count");
                    sounds.audioSourceEndedSound.particleCountToEmit = newParticleCount;
                }
            }
            EditorGUILayout.EndToggleGroup();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
Esempio n. 6
0
        void OnGUI()
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            //DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/MasterAudioManager.htm");

            DTGUIHelper.DrawUILine(DTGUIHelper.DividerColor);
            GUILayout.Label("Welcome to Master Audio for Unity! The buttons below are shortcuts to commonly used help options.", EditorStyles.textArea);
            DTGUIHelper.DrawUILine(DTGUIHelper.DividerColor);

            GUILayout.Label("Help", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Quick Starts", GUILayout.Width(90)))
            {
                Application.OpenURL("http://www.dtdevtools.com/docs/masteraudio/HowToCreateSFX.htm");
            }
            if (GUILayout.Button("Manual", GUILayout.Width(90)))
            {
                Application.OpenURL("http://www.dtdevtools.com/docs/masteraudio/TOC.htm");
            }
            if (GUILayout.Button("Videos", GUILayout.Width(90)))
            {
                Application.OpenURL("https://www.youtube.com/watch?v=8bHDhPR-jJg&list=PLW6fMWQDKB24osBmTuJd0IG8R5tOim6eV&index=1");
            }
            if (GUILayout.Button("Scripting API", GUILayout.Width(90)))
            {
                Application.OpenURL("http://www.dtdevtools.com/API/masteraudio/annotated.html");
            }
            if (GUILayout.Button("Support Forum", GUILayout.Width(100)))
            {
                Application.OpenURL("http://darktonic.freeforums.net/board/1/master-audio-aaa-sound-solution");
            }
            EditorGUILayout.EndHorizontal();
            DTGUIHelper.DrawUILine(DTGUIHelper.DividerColor);

            GUILayout.Label("Optional package support", EditorStyles.boldLabel);
            GUILayout.Label("Enable support for:");

            // physics 2D
            var enable2D = DTDefineHelper.DoesScriptingDefineSymbolExist(Physics2DSymbol);
            var new2D    = GUILayout.Toggle(enable2D, " 2D Physics (" + Physics2DSymbol + ")");

            if (new2D != enable2D)
            {
                if (new2D)
                {
                    DTDefineHelper.TryAddScriptingDefineSymbols(Physics2DSymbol);
                }
                else
                {
                    DTDefineHelper.TryRemoveScriptingDefineSymbols(Physics2DSymbol);
                }
            }

            // physics 3D
            var enable3D = DTDefineHelper.DoesScriptingDefineSymbolExist(Physics3DSymbol);
            var new3D    = GUILayout.Toggle(enable3D, " 3D Physics (" + Physics3DSymbol + ")");

            if (new3D != enable3D)
            {
                if (new3D)
                {
                    DTDefineHelper.TryAddScriptingDefineSymbols(Physics3DSymbol);
                }
                else
                {
                    DTDefineHelper.TryRemoveScriptingDefineSymbols(Physics3DSymbol);
                }
            }

#if UNITY_2018_2_OR_NEWER
            // Addressables
            var enableAddress = DTDefineHelper.DoesScriptingDefineSymbolExist(AddresablesSymbol);
            var newAddress    = GUILayout.Toggle(enableAddress, " Addressables (" + AddresablesSymbol + ")");
            if (newAddress != enableAddress)
            {
                if (newAddress)
                {
                    DTDefineHelper.TryAddScriptingDefineSymbols(AddresablesSymbol);
                }
                else
                {
                    DTDefineHelper.TryRemoveScriptingDefineSymbols(AddresablesSymbol);
                }
            }
#endif

            DTGUIHelper.ShowLargeBarAlert("Enabling a package you do not have installed will cause a compile error and you will not be able to use this window to undo until you install the missing package.");

            DTGUIHelper.DrawUILine(DTGUIHelper.DividerColor);

            EditorGUILayout.BeginHorizontal();
            var show    = showOnStartPrefs;
            var newShow = GUILayout.Toggle(show, " Show at start");
            if (newShow != show)
            {
                showOnStartPrefs = newShow;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("Email Support", "*****@*****.**"), GUILayout.Width(100)))
            {
                Application.OpenURL("mailto:[email protected]");
            }

            EditorGUILayout.EndHorizontal();
        }
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        MasterAudio.Instance = null;

        var ma        = MasterAudio.Instance;
        var maInScene = ma != null;

        if (maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            _groupNames = ma.GroupNames;
        }
        else
        {
            _groupNames = new List <string>();
        }
        PopulateGroupNames(_groupNames);

        DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/FootstepSounds.htm");

        _isDirty = false;

        _sounds = (FootstepSounds)target;

        var newSpawnMode = (MasterAudio.SoundSpawnLocationMode)EditorGUILayout.EnumPopup("Sound Spawn Mode", _sounds.soundSpawnMode);

        if (newSpawnMode != _sounds.soundSpawnMode)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Spawn Mode");
            _sounds.soundSpawnMode = newSpawnMode;
        }

        var newEvent = (FootstepSounds.FootstepTriggerMode)EditorGUILayout.EnumPopup("Event Used", _sounds.footstepEvent);

        if (newEvent != _sounds.footstepEvent)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Event Used");
            _sounds.footstepEvent = newEvent;
        }

        if (_sounds.footstepEvent == FootstepSounds.FootstepTriggerMode.None)
        {
            DTGUIHelper.ShowRedError("No sound will be made when Event Used is set to None.");
            return;
        }

        DTGUIHelper.VerticalSpace(3);

        EditorGUILayout.BeginHorizontal();
        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        GUILayout.Space(10);
        if (GUILayout.Button("Add Footstep Sound", EditorStyles.toolbarButton, GUILayout.Width(125)))
        {
            AddFootstepSound();
        }

        if (_sounds.footstepGroups.Count > 0)
        {
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Delete Footstep Sound", "Delete the bottom Footstep Sound"), EditorStyles.toolbarButton, GUILayout.Width(125)))
            {
                DeleteFootstepSound();
            }
            var buttonText   = "Collapse All";
            var allCollapsed = true;

            foreach (var t in _sounds.footstepGroups)
            {
                if (!t.isExpanded)
                {
                    continue;
                }

                allCollapsed = false;
                break;
            }

            if (allCollapsed)
            {
                buttonText = "Expand All";
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent(buttonText), EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                _isDirty = true;
                ExpandCollapseAll(allCollapsed);
            }
        }

        GUI.contentColor = Color.white;
        EditorGUILayout.EndHorizontal();
        DTGUIHelper.VerticalSpace(3);

        DTGUIHelper.StartGroupHeader();
        var newRetrigger = (EventSounds.RetriggerLimMode)EditorGUILayout.EnumPopup("Retrigger Limit Mode", _sounds.retriggerLimitMode);

        if (newRetrigger != _sounds.retriggerLimitMode)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Retrigger Limit Mode");
            _sounds.retriggerLimitMode = newRetrigger;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        switch (_sounds.retriggerLimitMode)
        {
        case EventSounds.RetriggerLimMode.FrameBased:
            var newFrm = EditorGUILayout.IntSlider("Min Frames Between", _sounds.limitPerXFrm, 0, 10000);
            if (newFrm != _sounds.limitPerXFrm)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Frames Between");
                _sounds.limitPerXFrm = newFrm;
            }
            break;

        case EventSounds.RetriggerLimMode.TimeBased:
            var newSec = EditorGUILayout.Slider("Min Seconds Between", _sounds.limitPerXSec, 0f, 10000f);
            if (newSec != _sounds.limitPerXSec)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Seconds Between");
                _sounds.limitPerXSec = newSec;
            }
            break;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        if (_sounds.footstepGroups.Count == 0)
        {
            DTGUIHelper.ShowRedError("You have no Footstep Sounds configured.");
        }
        for (var f = 0; f < _sounds.footstepGroups.Count; f++)
        {
            EditorGUI.indentLevel = 1;
            var step = _sounds.footstepGroups[f];


            var state = step.isExpanded;
            var text  = "Footstep Sound #" + (f + 1);

            DTGUIHelper.ShowCollapsibleSection(ref state, text);

            GUI.backgroundColor = Color.white;
            GUILayout.Space(3f);

            if (state != step.isExpanded)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Expand Variation");
                step.isExpanded = state;
            }

            DTGUIHelper.AddHelpIconNoStyle("http://www.dtdevtools.com/docs/masteraudio/FootstepSounds.htm#FootstepSound");

            EditorGUILayout.EndHorizontal();

            if (!step.isExpanded)
            {
                DTGUIHelper.VerticalSpace(3);
                continue;
            }

            EditorGUI.indentLevel = 0;
            DTGUIHelper.BeginGroupedControls();

            DTGUIHelper.StartGroupHeader();

            var newUseLayers = EditorGUILayout.BeginToggleGroup("Layer filters", step.useLayerFilter);
            if (newUseLayers != step.useLayerFilter)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Layer filters");
                step.useLayerFilter = newUseLayers;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useLayerFilter)
            {
                for (var i = 0; i < step.matchingLayers.Count; i++)
                {
                    var newLayer = EditorGUILayout.LayerField("Layer Match " + (i + 1), step.matchingLayers[i]);
                    if (newLayer == step.matchingLayers[i])
                    {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Layer filter");
                    step.matchingLayers[i] = newLayer;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);

                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a layer match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Layer filter");
                    step.matchingLayers.Add(0);
                }
                if (step.matchingLayers.Count > 1)
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last layer match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Layer filter");
                        step.matchingLayers.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            DTGUIHelper.StartGroupHeader();
            var newTagFilter = EditorGUILayout.BeginToggleGroup("Tag filter", step.useTagFilter);
            if (newTagFilter != step.useTagFilter)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Tag filter");
                step.useTagFilter = newTagFilter;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useTagFilter)
            {
                for (var i = 0; i < step.matchingTags.Count; i++)
                {
                    var newTag = EditorGUILayout.TagField("Tag Match " + (i + 1), step.matchingTags[i]);
                    if (newTag == step.matchingTags[i])
                    {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Tag filter");
                    step.matchingTags[i] = newTag;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);
                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a tag match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Add Tag filter");
                    step.matchingTags.Add("Untagged");
                }
                if (step.matchingTags.Count > 1)
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last tag match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Tag filter");
                        step.matchingTags.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            EditorGUI.indentLevel = 0;

            if (maInScene)
            {
                var existingIndex = _groupNames.IndexOf(step.soundType);

                int?groupIndex = null;

                var noGroup = false;
                var noMatch = false;

                if (existingIndex >= 1)
                {
                    EditorGUILayout.BeginHorizontal();
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                    if (existingIndex == 1)
                    {
                        noGroup = true;
                    }

                    var button = DTGUIHelper.AddSettingsButton("Sound Group");
                    switch (button)
                    {
                    case DTGUIHelper.DTFunctionButtons.Go:
                        var grp = _groupNames[existingIndex];
                        var trs = MasterAudio.FindGroupTransform(grp);
                        if (trs != null)
                        {
                            Selection.activeObject = trs;
                        }
                        break;
                    }

                    EditorGUILayout.EndHorizontal();
                }
                else if (existingIndex == -1 && step.soundType == MasterAudio.NoGroupName)
                {
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                }
                else     // non-match
                {
                    noMatch = true;
                    var newSound = EditorGUILayout.TextField("Sound Group", step.soundType);
                    if (newSound != step.soundType)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                        step.soundType = newSound;
                    }

                    var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray());
                    if (newIndex >= 0)
                    {
                        groupIndex = newIndex;
                    }
                }

                if (noGroup)
                {
                    DTGUIHelper.ShowRedError("No Sound Group specified. Footstep will not sound.");
                }
                else if (noMatch)
                {
                    DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one.");
                }

                if (groupIndex.HasValue)
                {
                    if (existingIndex != groupIndex.Value)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (groupIndex.Value == -1)
                    {
                        step.soundType = MasterAudio.NoGroupName;
                    }
                    else
                    {
                        step.soundType = _groupNames[groupIndex.Value];
                    }
                }
            }
            else
            {
                var newSType = EditorGUILayout.TextField("Sound Group", step.soundType);
                if (newSType != step.soundType)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    step.soundType = newSType;
                }
            }

            var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", step.variationType);
            if (newVarType != step.variationType)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Mode");
                step.variationType = newVarType;
            }

            if (step.variationType == EventSounds.VariationType.PlaySpecific)
            {
                var newVarName = EditorGUILayout.TextField("Variation Name", step.variationName);
                if (newVarName != step.variationName)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Name");
                    step.variationName = newVarName;
                }

                if (string.IsNullOrEmpty(step.variationName))
                {
                    DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play.");
                }
            }

            var newVol = DTGUIHelper.DisplayVolumeField(step.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (newVol != step.volume)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume");
                step.volume = newVol;
            }

            var newFixedPitch = EditorGUILayout.Toggle("Override pitch?", step.useFixedPitch);
            if (newFixedPitch != step.useFixedPitch)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Override pitch");
                step.useFixedPitch = newFixedPitch;
            }
            if (step.useFixedPitch)
            {
                var newPitch = DTGUIHelper.DisplayPitchField(step.pitch);
                if (newPitch != step.pitch)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Pitch");
                    step.pitch = newPitch;
                }
            }

            var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", step.delaySound, 0f, 10f);
            if (newDelay == step.delaySound)
            {
                DTGUIHelper.EndGroupedControls();
                continue;
            }

            DTGUIHelper.EndGroupedControls();

            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Delay Sound");
            step.delaySound = newDelay;
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;
        var isDirty = false;

        _variation = (SoundGroupVariation)target;

        if (MasterAudioInspectorResources.LogoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        var parentGroup = _variation.ParentGroup;

        if (parentGroup == null)
        {
            DTGUIHelper.ShowLargeBarAlert("This file cannot be edited in Project View.");
            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(90)))
        {
            Selection.activeObject = _variation.transform.parent.gameObject;
        }
        GUILayout.FlexibleSpace();

        if (Application.isPlaying)
        {
            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (_variation.IsPlaying && _variation.VarAudio.clip != null)   // wait for Resource files to load
            {
                GUI.color = Color.green;

                var label = "Playing ({0}%)";

                if (AudioUtil.IsAudioPaused(_variation.VarAudio))
                {
                    GUI.color = Color.yellow;
                    label     = "Paused ({0}%)";
                }

                var percentagePlayed = (int)(_variation.VarAudio.time / _variation.VarAudio.clip.length * 100);

                EditorGUILayout.LabelField(string.Format(label, percentagePlayed),
                                           EditorStyles.miniButtonMid, GUILayout.Height(16), GUILayout.Width(240));

                _variation.frames++;
                isDirty = true;

                GUI.color = DTGUIHelper.BrightButtonColor;
                if (_variation.ObjectToFollow != null || _variation.ObjectToTriggerFrom != null)
                {
                    if (GUILayout.Button("Select Caller", EditorStyles.miniButton, GUILayout.Width(80)))
                    {
                        if (_variation.ObjectToFollow != null)
                        {
                            Selection.activeGameObject = _variation.ObjectToFollow.gameObject;
                        }
                        else
                        {
                            Selection.activeGameObject = _variation.ObjectToTriggerFrom.gameObject;
                        }
                    }
                }
            }
            else
            {
                GUI.color = Color.red;
                EditorGUILayout.LabelField("Not playing", EditorStyles.miniButtonMid, GUILayout.Height(16), GUILayout.Width(240));
            }
        }

        GUI.color        = Color.white;
        GUI.contentColor = Color.white;

        _ma = MasterAudio.Instance;
        var maInScene = _ma != null;

        var canPreview = !DTGUIHelper.IsPrefabInProjectView(_variation);

        if (maInScene)
        {
            var buttonPressed = DTGUIHelper.DTFunctionButtons.None;
            if (canPreview)
            {
                buttonPressed = DTGUIHelper.AddVariationButtons();
            }

            switch (buttonPressed)
            {
            case DTGUIHelper.DTFunctionButtons.Play:
                previewer = MasterAudioInspector.GetPreviewer();

                if (Application.isPlaying)
                {
                    MasterAudio.PlaySound3DAtVector3AndForget(_variation.ParentGroup.name, previewer.transform.position, 1f, null, 0f, _variation.name);
                }
                else
                {
                    isDirty = true;

                    var randPitch = GetRandomPreviewPitch(_variation);
                    var varVol    = GetRandomPreviewVolume(_variation);

                    if (_variation.audLocation != MasterAudio.AudioLocation.FileOnInternet)
                    {
                        if (previewer != null)
                        {
                            MasterAudioInspector.StopPreviewer();
                            previewer.pitch = randPitch;
                        }
                    }

                    var calcVolume = varVol * parentGroup.groupMasterVolume;

                    switch (_variation.audLocation)
                    {
                    case MasterAudio.AudioLocation.ResourceFile:
                        if (previewer != null)
                        {
                            var fileName = AudioResourceOptimizer.GetLocalizedFileName(_variation.useLocalization, _variation.resourceFileName);
                            previewer.PlayOneShot(Resources.Load(fileName) as AudioClip, calcVolume);
                        }
                        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 (Application.isPlaying)
                {
                    MasterAudio.StopAllOfSound(_variation.transform.parent.name);
                }
                else
                {
                    if (_variation.audLocation != MasterAudio.AudioLocation.FileOnInternet)
                    {
                        MasterAudioInspector.StopPreviewer();
                    }
                }
                break;
            }
        }

        EditorGUILayout.EndHorizontal();

        DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm", "http://www.dtdevtools.com/API/masteraudio/class_dark_tonic_1_1_master_audio_1_1_sound_group_variation.html");

        if (maInScene && !Application.isPlaying)
        {
            DTGUIHelper.ShowColorWarning(MasterAudio.PreviewText);
        }

        var oldLocation = _variation.audLocation;

        EditorGUILayout.BeginHorizontal();
        if (!Application.isPlaying)
        {
            var newLocation =
                (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation);

            if (newLocation != oldLocation)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin");
                _variation.audLocation = newLocation;
            }
        }
        else
        {
            EditorGUILayout.LabelField("Audio Origin", _variation.audLocation.ToString());
        }
        DTGUIHelper.AddHelpIcon("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm#AudioOrigin");
        EditorGUILayout.EndHorizontal();

        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;
                }
            }
            else
            {
                EditorGUILayout.LabelField("Internet File URL", _variation.internetFileUrl);
                switch (_variation.internetFileLoadStatus)
                {
                case MasterAudio.InternetFileLoadStatus.Loading:
                    DTGUIHelper.ShowLargeBarAlert("Attempting to download.");
                    break;

                case MasterAudio.InternetFileLoadStatus.Loaded:
                    DTGUIHelper.ShowColorWarning("Downloaded and ready to play.");
                    break;

                case MasterAudio.InternetFileLoadStatus.Failed:
                    DTGUIHelper.ShowRedError("Failed Download.");
                    break;
                }
            }

            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)
                    {
                        // ReSharper disable once ExpressionIsAlwaysNull
                        var aClip = dragged as AudioClip;
                        // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                        if (aClip == null)
                        {
                            continue;
                        }

                        // ReSharper disable HeuristicUnreachableCode
                        var useLocalization = false;
                        newFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization);
                        if (string.IsNullOrEmpty(newFilename))
                        {
                            newFilename = aClip.name;
                        }

                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename");
                        _variation.resourceFileName = newFilename;
                        _variation.useLocalization  = useLocalization;
                        break;
                        // ReSharper restore HeuristicUnreachableCode
                    }
                }
                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 = DTGUIHelper.DisplayVolumeField(_variation.VarAudio.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);

        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 (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;
            }
        }

        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;
        }

        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"
        };

        EditorGUILayout.BeginHorizontal();

        var newFilterIndex = EditorGUILayout.Popup("Add Filter Effect", 0, filterList.ToArray());

        DTGUIHelper.AddHelpIcon("http://www.dtdevtools.com/docs/masteraudio/FilterFX.htm");
        EditorGUILayout.EndHorizontal();

        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 override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 0;
        var isDirty = false;

        _group = (DynamicSoundGroup)target;

        _group = RescanChildren(_group);

        var dsgc = _group.transform.parent;
        DynamicSoundGroupCreator creator = null;

        if (dsgc != null)
        {
            creator = dsgc.GetComponent <DynamicSoundGroupCreator>();
        }

        if (creator == null)
        {
            isValid = false;
        }

        if (!isValid)
        {
            return;
        }

        var isInProjectView = DTGUIHelper.IsPrefabInProjectView(_group);

        if (MasterAudioInspectorResources.logoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        GUI.contentColor = Color.green;
        if (GUILayout.Button(new GUIContent("Back to Dynamic Sound Group Creator", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(220)))
        {
            Selection.activeObject = _group.transform.parent.gameObject;
        }
        GUI.contentColor = Color.white;
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        var newVol = EditorGUILayout.Slider("Group Master Volume", _group.groupMasterVolume, 0f, 1f);

        if (newVol != _group.groupMasterVolume)
        {
            UndoHelper.RecordObjectPropertyForUndo(_group, "change Group Master Volume");
            _group.groupMasterVolume = newVol;
        }

        var newVarSequence = (MasterAudioGroup.VariationSequence)EditorGUILayout.EnumPopup("Variation Sequence", _group.curVariationSequence);

        if (newVarSequence != _group.curVariationSequence)
        {
            UndoHelper.RecordObjectPropertyForUndo(_group, "change Variation Sequence");
            _group.curVariationSequence = newVarSequence;
        }

        if (_group.curVariationSequence == MasterAudioGroup.VariationSequence.TopToBottom)
        {
            var newUseInactive = EditorGUILayout.BeginToggleGroup("Refill Variation Pool After Inactive Time", _group.useInactivePeriodPoolRefill);
            if (newUseInactive != _group.useInactivePeriodPoolRefill)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "toggle Inactive Refill");
                _group.useInactivePeriodPoolRefill = newUseInactive;
            }

            EditorGUI.indentLevel = 1;
            var newInactivePeriod = EditorGUILayout.Slider("Inactive Time (sec)", _group.inactivePeriodSeconds, .2f, 30f);
            if (newInactivePeriod != _group.inactivePeriodSeconds)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Inactive Time");
                _group.inactivePeriodSeconds = newInactivePeriod;
            }

            EditorGUILayout.EndToggleGroup();
        }

        EditorGUI.indentLevel = 0;
        var newVarMode = (MasterAudioGroup.VariationMode)EditorGUILayout.EnumPopup("Variation Mode", _group.curVariationMode);

        if (newVarMode != _group.curVariationMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(_group, "change Variation Mode");
            _group.curVariationMode = newVarMode;
        }

        EditorGUI.indentLevel = 1;
        switch (_group.curVariationMode)
        {
        case MasterAudioGroup.VariationMode.LoopedChain:
            DTGUIHelper.ShowColorWarning("*In this mode, only one Variation can be played at a time.");

            var newLoopMode = (MasterAudioGroup.ChainedLoopLoopMode)EditorGUILayout.EnumPopup("Loop Mode", _group.chainLoopMode);
            if (newLoopMode != _group.chainLoopMode)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Loop Mode");
                _group.chainLoopMode = newLoopMode;
            }

            if (_group.chainLoopMode == MasterAudioGroup.ChainedLoopLoopMode.NumberOfLoops)
            {
                var newLoopCount = EditorGUILayout.IntSlider("Number of Loops", _group.chainLoopNumLoops, 1, 500);
                if (newLoopCount != _group.chainLoopNumLoops)
                {
                    UndoHelper.RecordObjectPropertyForUndo(_group, "change Number of Loops");
                    _group.chainLoopNumLoops = newLoopCount;
                }
            }

            var newDelayMin = EditorGUILayout.Slider("Clip Change Delay Min", _group.chainLoopDelayMin, 0f, 20f);
            if (newDelayMin != _group.chainLoopDelayMin)
            {
                if (_group.chainLoopDelayMax < newDelayMin)
                {
                    _group.chainLoopDelayMax = newDelayMin;
                }
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Chained Clip Delay Min");
                _group.chainLoopDelayMin = newDelayMin;
            }

            var newDelayMax = EditorGUILayout.Slider("Clip Change Delay Max", _group.chainLoopDelayMax, 0f, 20f);
            if (newDelayMax != _group.chainLoopDelayMax)
            {
                if (newDelayMax < _group.chainLoopDelayMin)
                {
                    newDelayMax = _group.chainLoopDelayMin;
                }
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Chained Clip Delay Max");
                _group.chainLoopDelayMax = newDelayMax;
            }
            break;

        case MasterAudioGroup.VariationMode.Normal:
            var newRetrigger = EditorGUILayout.IntSlider("Retrigger Percentage", _group.retriggerPercentage, 0, 100);
            if (newRetrigger != _group.retriggerPercentage)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Retrigger Percentage");
                _group.retriggerPercentage = newRetrigger;
            }

            var newLimitPoly = EditorGUILayout.Toggle("Limit Polyphony", _group.limitPolyphony);
            if (newLimitPoly != _group.limitPolyphony)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "toggle Limit Polyphony");
                _group.limitPolyphony = newLimitPoly;
            }
            if (_group.limitPolyphony)
            {
                int maxVoices = 0;
                for (var i = 0; i < _group.groupVariations.Count; i++)
                {
                    var variation = _group.groupVariations[i];
                    maxVoices += variation.weight;
                }

                var newVoiceLimit = EditorGUILayout.IntSlider("Polyphony Voice Limit", _group.voiceLimitCount, 1, maxVoices);
                if (newVoiceLimit != _group.voiceLimitCount)
                {
                    UndoHelper.RecordObjectPropertyForUndo(_group, "change Polyphony Voice Limit");
                    _group.voiceLimitCount = newVoiceLimit;
                }
            }

            var newLimitMode = (MasterAudioGroup.LimitMode)EditorGUILayout.EnumPopup("Replay Limit Mode", _group.limitMode);
            if (newLimitMode != _group.limitMode)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "change Replay Limit Mode");
                _group.limitMode = newLimitMode;
            }

            switch (_group.limitMode)
            {
            case MasterAudioGroup.LimitMode.FrameBased:
                var newFrameLimit = EditorGUILayout.IntSlider("Min Frames Between", _group.limitPerXFrames, 1, 120);
                if (newFrameLimit != _group.limitPerXFrames)
                {
                    UndoHelper.RecordObjectPropertyForUndo(_group, "change Min Frames Between");
                    _group.limitPerXFrames = newFrameLimit;
                }
                break;

            case MasterAudioGroup.LimitMode.TimeBased:
                var newMinTime = EditorGUILayout.Slider("Min Seconds Between", _group.minimumTimeBetween, 0.1f, 10f);
                if (newMinTime != _group.minimumTimeBetween)
                {
                    UndoHelper.RecordObjectPropertyForUndo(_group, "change Min Seconds Between");
                    _group.minimumTimeBetween = newMinTime;
                }
                break;
            }
            break;

        case MasterAudioGroup.VariationMode.Dialog:
            DTGUIHelper.ShowColorWarning("*In this mode, only one Variation can be played at a time.");

            var newUseDialog = EditorGUILayout.Toggle("Dialog Custom Fade?", _group.useDialogFadeOut);
            if (newUseDialog != _group.useDialogFadeOut)
            {
                UndoHelper.RecordObjectPropertyForUndo(_group, "toggle Dialog Custom Fade?");
                _group.useDialogFadeOut = newUseDialog;
            }

            if (_group.useDialogFadeOut)
            {
                var newFadeTime = EditorGUILayout.Slider("Custom Fade Out Time", _group.dialogFadeOutTime, 0.1f, 20f);
                if (newFadeTime != _group.dialogFadeOutTime)
                {
                    UndoHelper.RecordObjectPropertyForUndo(_group, "change Custom Fade Out Time");
                    _group.dialogFadeOutTime = newFadeTime;
                }
            }
            break;
        }

        EditorGUI.indentLevel = 0;

        var newBulkMode = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Variation Create Mode", _group.bulkVariationMode);

        if (newBulkMode != _group.bulkVariationMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(_group, "change Bulk Variation Mode");
            _group.bulkVariationMode = newBulkMode;
        }
        if (_group.bulkVariationMode == MasterAudio.AudioLocation.ResourceFile)
        {
            DTGUIHelper.ShowColorWarning("*Resource mode: make sure to drag from Resource folders only.");
        }

        var newLog = EditorGUILayout.Toggle("Log Sounds", _group.logSound);

        if (newLog != _group.logSound)
        {
            UndoHelper.RecordObjectPropertyForUndo(_group, "toggle Log Sounds");
            _group.logSound = newLog;
        }

        int?deadChildIndex = null;

        if (!Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUILayout.Label("Actions", EditorStyles.wordWrappedLabel, GUILayout.Width(50f));
            GUILayout.Space(96);
            GUI.contentColor = Color.green;
            if (GUILayout.Button(new GUIContent("Equalize Weights", "Reset Weights to one"), EditorStyles.toolbarButton, GUILayout.Width(120)))
            {
                isDirty = true;
                EqualizeWeights(_group);
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Equalize Variation Volumes"), EditorStyles.toolbarButton, GUILayout.Width(150)))
            {
                EqualizeVariationVolumes(_group.groupVariations);
            }

            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();
        }

        if (!Application.isPlaying)
        {
            // new variation settings
            EditorGUILayout.BeginVertical();
            var anEvent = Event.current;

            if (isInProjectView)
            {
                DTGUIHelper.ShowLargeBarAlert("*You are in Project View and cannot create Variations.");
                DTGUIHelper.ShowLargeBarAlert("*Pull this prefab into the Scene to create Variations.");
            }
            else
            {
                GUI.color = Color.yellow;

                var dragArea = GUILayoutUtility.GetRect(0f, 35f, GUILayout.ExpandWidth(true));
                GUI.Box(dragArea, "Drag Audio clips here to create Variations!");

                GUI.color = Color.white;

                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;
                            }

                            CreateVariation(_group, aClip);
                        }
                    }
                    Event.current.Use();
                    break;
                }
            }
            EditorGUILayout.EndVertical();
            // end new variation settings
        }

        if (_group.groupVariations.Count == 0)
        {
            DTGUIHelper.ShowRedError("You currently have no Variations.");
        }
        else
        {
            _group.groupVariations.Sort(delegate(DynamicGroupVariation x, DynamicGroupVariation y) {
                return(x.name.CompareTo(y.name));
            });

            for (var i = 0; i < _group.groupVariations.Count; i++)
            {
                var variation = _group.groupVariations[i];
                EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
                EditorGUILayout.LabelField(variation.name, EditorStyles.boldLabel);

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(new GUIContent(MasterAudioInspectorResources.gearTexture, "Click to goto Variation"), EditorStyles.toolbarButton, GUILayout.Width(40)))
                {
                    Selection.activeObject = variation;
                }

                if (!Application.isPlaying)
                {
                    if (GUILayout.Button(new GUIContent(MasterAudioInspectorResources.deleteTexture, "Click to delete this Variation"), EditorStyles.toolbarButton, GUILayout.Width(40)))
                    {
                        deadChildIndex = i;
                        isDirty        = true;
                    }
                }

                var buttonPressed = DTGUIHelper.AddDynamicGroupButtons(_group);
                switch (buttonPressed)
                {
                case DTGUIHelper.DTFunctionButtons.Play:
                    if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile)
                    {
                        creator.PreviewerInstance.Stop();
                        creator.PreviewerInstance.PlayOneShot(Resources.Load(variation.resourceFileName) as AudioClip);
                    }
                    else
                    {
                        variation.audio.Stop();
                        variation.audio.Play();
                    }
                    isDirty = true;
                    break;

                case DTGUIHelper.DTFunctionButtons.Stop:
                    if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile)
                    {
                        creator.PreviewerInstance.Stop();
                    }
                    else
                    {
                        variation.audio.Stop();
                    }
                    isDirty = true;
                    break;
                }

                EditorGUILayout.EndHorizontal();

                if (!Application.isPlaying)
                {
                    DTGUIHelper.ShowColorWarning("*Fading & random settings are ignored by preview in edit mode.");
                }
                if (variation.audio == null)
                {
                    DTGUIHelper.ShowRedError(string.Format("The Variation: '{0}' has no Audio Source.", variation.name));
                    break;
                }

                var oldLocation = variation.audLocation;
                var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", variation.audLocation);
                if (newLocation != variation.audLocation)
                {
                    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, "change 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;

                    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(variation, "change Resource Filename");
                                variation.resourceFileName = aClip.name;
                            }
                        }
                        Event.current.Use();
                        break;
                    }
                    EditorGUILayout.EndVertical();

                    var 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 Clip");
                    variation.audio.loop = newLoop;
                }

                EditorUtility.SetDirty(variation.audio);

                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 newUseRndPitch = EditorGUILayout.BeginToggleGroup("Use Random Pitch", variation.useRandomPitch);
                if (newUseRndPitch != variation.useRandomPitch)
                {
                    UndoHelper.RecordObjectPropertyForUndo(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(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(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(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(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(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(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(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(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 newFades = EditorGUILayout.BeginToggleGroup("Use Custom Fading", variation.useFades);
                if (newFades != variation.useFades)
                {
                    UndoHelper.RecordObjectPropertyForUndo(variation, "toggle Use Custom Fading");
                    variation.useFades = newFades;
                }

                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;
                    }

                    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();

                EditorGUILayout.Separator();
            }
        }

        if (deadChildIndex.HasValue)
        {
            var deadVar = _group.groupVariations[deadChildIndex.Value];

            if (deadVar != null)
            {
                // delete variation from Hierarchy
                UndoHelper.DestroyForUndo(deadVar.gameObject);
            }

            // delete group.
            _group.groupVariations.RemoveAt(deadChildIndex.Value);
        }



        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

        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();
    }
Esempio n. 11
0
    void OnGUI()
    {
        outsideScrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), outsideScrollPos, new Rect(0, 0, 900, 660));

        if (MasterAudioInspectorResources.logoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }

        filterClips = null;

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

        GUI.contentColor = Color.green;
        if (GUILayout.Button(new GUIContent("Scan Project"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            BuildCache();
            return;
        }

        GUILayout.Space(10);
        if (GUILayout.Button(new GUIContent("Revert Selected"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            RevertSelected();
            return;
        }

        GUILayout.Space(10);
        if (GUILayout.Button(new GUIContent("Apply Selected"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            ApplySelected();
            return;
        }

        GUILayout.Space(10);
        RevertColor();

        GUILayout.Label("Full Path Filter");
        clipList.searchFilter = GUILayout.TextField(clipList.searchFilter, EditorStyles.toolbarTextField, GUILayout.Width(200));

        var myPosition = GUILayoutUtility.GetRect(10, 10, ToolbarSeachCancelButton);

        myPosition.x -= 5;
        if (GUI.Button(myPosition, "", ToolbarSeachCancelButton))
        {
            clipList.searchFilter = string.Empty;
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!File.Exists(CACHE_FILE_PATH))
        {
            DTGUIHelper.ShowLargeBarAlert("Click 'Scan Project' to generate list of Audio Clips.");
            GUI.EndScrollView();
            return;
        }

        if (clipList.audioInfo.Count == 0 || clipList.needsRefresh)
        {
            if (!LoadAndTranslateFile())
            {
                GUI.EndScrollView();
                return;
            }
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Folder");
        var selectedIndex = folderPaths.IndexOf(selectedFolderPath);
        var newIndex      = EditorGUILayout.Popup(selectedIndex, folderPaths.ToArray(), GUILayout.Width(800));

        if (newIndex != selectedIndex)
        {
            selectedFolderPath = folderPaths[newIndex];
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        var dynamicText = string.Format("{0}/{1} clips selected.", SelectedClips.Count, FilteredClips.Count);

        if (!string.IsNullOrEmpty(clipList.searchFilter) || selectedFolderPath != ALL_FOLDERS_KEY)
        {
            var totalCount  = clipList.audioInfo.Count;
            var filterCount = FilteredClips.Count;

            dynamicText += string.Format(" {0} clips filtered out.", totalCount - filterCount);
        }

        EditorGUILayout.LabelField(dynamicText);


        // display
        DisplayClips();

        ShowBulkOperations();

        GUI.EndScrollView();
    }
    public override void OnInspectorGUI()
    {
        MasterAudio.Instance = null;

        var _ma        = MasterAudio.Instance;
        var _maInScene = _ma != null;

        if (_maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        _isDirty = false;

        DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/AmbientSound.htm");

        var _sounds = (AmbientSound)target;

        var _groupNames = new List <string>();

        if (_maInScene)
        {
            // ReSharper disable once PossibleNullReferenceException
            _groupNames = _ma.GroupNames;
        }

        PopulateItemNames(_groupNames);

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);
        }

        if (_maInScene)
        {
            var existingIndex = _groupNames.IndexOf(_sounds.AmbientSoundGroup);

            int?groupIndex = null;

            var noGroup = false;
            var noMatch = false;

            if (existingIndex >= 1)
            {
                EditorGUILayout.BeginHorizontal();
                groupIndex = EditorGUILayout.Popup("Ambient Sound Group", existingIndex, _groupNames.ToArray());
                if (existingIndex == 1)
                {
                    noGroup = true;
                }

                if (groupIndex > MasterAudio.HardCodedBusOptions - 1)
                {
                    var button = DTGUIHelper.AddSettingsButton("Ambient Sound Group");
                    switch (button)
                    {
                    case DTGUIHelper.DTFunctionButtons.Go:
                        var grp = _groupNames[existingIndex];
                        var trs = MasterAudio.FindGroupTransform(grp);
                        if (trs != null)
                        {
                            Selection.activeObject = trs;
                        }
                        break;
                    }

                    var buttonPress = DTGUIHelper.AddDynamicVariationButtons();
                    var sType       = _groupNames[existingIndex];

                    switch (buttonPress)
                    {
                    case DTGUIHelper.DTFunctionButtons.Play:
                        DTGUIHelper.PreviewSoundGroup(sType);
                        break;

                    case DTGUIHelper.DTFunctionButtons.Stop:
                        DTGUIHelper.StopPreview(sType);
                        break;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }
            else if (existingIndex == -1 && _sounds.AmbientSoundGroup == MasterAudio.NoGroupName)
            {
                groupIndex = EditorGUILayout.Popup("Ambient Sound Group", existingIndex, _groupNames.ToArray());
            }
            else     // non-match
            {
                noMatch = true;
                var newSound = EditorGUILayout.TextField("Ambient Sound Group", _sounds.AmbientSoundGroup);
                if (newSound != _sounds.AmbientSoundGroup)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                    _sounds.AmbientSoundGroup = newSound;
                }

                var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray());
                if (newIndex >= 0)
                {
                    groupIndex = newIndex;
                }
            }

            if (noGroup)
            {
                DTGUIHelper.ShowRedError("No Ambient Sound Group specified.");
            }
            else if (noMatch)
            {
                DTGUIHelper.ShowRedError("Ambient Sound Group found no match. Type in or choose one.");
            }

            if (groupIndex.HasValue)
            {
                if (existingIndex != groupIndex.Value)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                }
                switch (groupIndex.Value)
                {
                case -1:
                    _sounds.AmbientSoundGroup = MasterAudio.NoGroupName;
                    break;

                default:
                    _sounds.AmbientSoundGroup = _groupNames[groupIndex.Value];
                    break;
                }
            }
        }
        else
        {
            var newSType = EditorGUILayout.TextField("Ambient Sound Group", _sounds.AmbientSoundGroup);
            if (newSType != _sounds.AmbientSoundGroup)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Ambient Sound Group");
                _sounds.AmbientSoundGroup = newSType;
            }
        }

                #if UNITY_5_6_OR_NEWER
        DTGUIHelper.StartGroupHeader();
        var newClosest = GUILayout.Toggle(_sounds.UseClosestColliderPosition, new GUIContent(" Use Closest Collider Position", "Using this option, the Audio Source will be updated every frame to the closest position on the caller's collider(s)."));
        if (newClosest != _sounds.UseClosestColliderPosition)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Follow Caller");
            _sounds.UseClosestColliderPosition = newClosest;
        }

        EditorGUILayout.EndVertical();
        if (_sounds.UseClosestColliderPosition)
        {
            var newTop = EditorGUILayout.Toggle("Use Top Collider", _sounds.UseTopCollider);
            if (newTop != _sounds.UseTopCollider)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Use Top Collider");
                _sounds.UseTopCollider = newTop;
            }
            var newChild = EditorGUILayout.Toggle("Use Child G.O. Colliders", _sounds.IncludeChildColliders);
            if (newChild != _sounds.IncludeChildColliders)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Use Child G.O. Colliders");
                _sounds.IncludeChildColliders = newChild;
            }

            var colliderObjects = new List <GameObject>();

            if (_sounds.UseTopCollider)
            {
                var collider   = _sounds.GetComponent <Collider>();
                var collider2d = _sounds.GetComponent <Collider2D>();
                if (collider != null)
                {
                    colliderObjects.Add(collider.gameObject);
                }
                else if (collider2d != null)
                {
                    colliderObjects.Add(collider2d.gameObject);
                }
            }
            if (_sounds.IncludeChildColliders)
            {
                for (var i = 0; i < _sounds.transform.childCount; i++)
                {
                    var child      = _sounds.transform.GetChild(i);
                    var collider   = child.GetComponent <Collider>();
                    var collider2d = child.GetComponent <Collider2D>();
                    if (collider != null)
                    {
                        colliderObjects.Add(collider.gameObject);
                    }
                    else if (collider2d != null)
                    {
                        colliderObjects.Add(collider2d.gameObject);
                    }
                }
            }

            if (colliderObjects.Count == 0)
            {
                DTGUIHelper.ShowRedError("You have zero Colliders selected, so this functionality will not work.");
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                DTGUIHelper.ShowColorWarning("Colliders used: " + colliderObjects.Count);
                if (GUILayout.Button("Select\nColliders", GUILayout.Width(70)))
                {
                    Selection.objects = colliderObjects.ToArray();
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
            //DTGUIHelper.ShowColorWarning("Use Closest Collider Position takes precedence over Follow Caller, so that option is hidden.");
        }
        else
        {
            EditorGUILayout.EndVertical();
            DTGUIHelper.StartGroupHeader();
            var newFollow =
                GUILayout.Toggle(_sounds.FollowCaller, new GUIContent(" Follow Caller",
                                                                      "This option is useful if your caller ever moves, as it will make the Audio Source follow to the location of the caller every frame."));
            if (newFollow != _sounds.FollowCaller)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Follow Caller");
                _sounds.FollowCaller = newFollow;
            }
            EditorGUILayout.EndVertical();
            if (_sounds.FollowCaller)
            {
                DTGUIHelper.ShowColorWarning("Will follow caller at runtime.");
            }
            EditorGUILayout.EndVertical();
        }
#else
        DTGUIHelper.StartGroupHeader();
        var newFollow =
            GUILayout.Toggle(_sounds.FollowCaller, new GUIContent(" Follow Caller",
                                                                  "This option is useful if your caller ever moves, as it will make the Audio Source follow to the location of the caller every frame."));
        if (newFollow != _sounds.FollowCaller)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Follow Caller");
            _sounds.FollowCaller = newFollow;
        }
        EditorGUILayout.EndVertical();
        if (_sounds.FollowCaller)
        {
            DTGUIHelper.ShowColorWarning("Will follow caller at runtime.");
        }
        EditorGUILayout.EndVertical();
#endif

        if (Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Follower Object");
            EditorGUILayout.ObjectField(_sounds.RuntimeFollower, typeof(Transform), false);
            EditorGUILayout.EndHorizontal();
        }

        //DrawDefaultInspector();
    }
Esempio n. 13
0
    // ReSharper disable once UnusedMember.Local
    // ReSharper disable once InconsistentNaming
    void OnGUI()
    {
        _scrollPos = GUI.BeginScrollView(
            new Rect(0, 0, position.width, position.height),
            _scrollPos,
            new Rect(0, 0, 600, 210)
            );


        if (MasterAudioInspectorResources.LogoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        if (Application.isPlaying)
        {
            DTGUIHelper.ShowLargeBarAlert("This window can only be used in edit mode.");
        }
        else
        {
            DTGUIHelper.ShowColorWarning("This window will help you prepare a project that has existing audio for switching over to Master Audio.");
            DTGUIHelper.ShowColorWarning("All Audio Source components should be created by Master Audio only. Let's remove all your old ones.");
            DTGUIHelper.ShowLargeBarAlert("For each Scene, open the Scene, then go through the steps below to locate & delete items.");

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Step 1", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Find Audio Sources In Scene"), EditorStyles.toolbarButton, GUILayout.Width(200)))
            {
                var audSources = GetNonMAAudioSources();
                _audioSources = audSources.Count;

                if (_audioSources > 0)
                {
                    Selection.objects = audSources.ToArray();
                }

                if (_audioSources == 0)
                {
                    DTGUIHelper.ShowAlert("You have zero AudioSources in your Scene. You are finished.");
                }
                else
                {
                    DTGUIHelper.ShowAlert(audSources.Count + " AudioSource(s) found and selected in the Hierarchy. Please take note of what game objects these are, so you can add sound to them later with Master Audio.");
                }
            }
            GUI.contentColor = Color.white;

            if (_audioSources < 0)
            {
                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                GUILayout.Label("Click button to find Audio Sources.");
            }
            else if (_audioSources == 0)
            {
                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                GUILayout.Label("No Audio Sources! You are finished.");
            }
            else
            {
                GUI.contentColor = Color.red;
                GUILayout.Label(_audioSources.ToString() + " Audio Source(s) selected. Take note of them and go to step 2.");
            }
            GUI.contentColor = Color.white;

            EditorGUILayout.EndHorizontal();


            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Step 2", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Delete Audio Sources In Scene"), EditorStyles.toolbarButton, GUILayout.Width(200)))
            {
                var audSources = GetNonMAAudioSources();
                _audioSources = audSources.Count;

                if (_audioSources == 0)
                {
                    DTGUIHelper.ShowAlert("You have zero AudioSources in your Scene. You are finished.");
                    _audioSources = 0;
                }
                else
                {
                    DeleteAudioSources();
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        GUI.EndScrollView();
    }
    void OnGUI()
    {
        scrollPos = GUI.BeginScrollView(
            new Rect(0, 0, position.width, position.height),
            scrollPos,
            new Rect(0, 0, 520, 220)
            );

        PlaylistController.Instances = null;
        var pcs = PlaylistController.Instances;
        var plControllerInScene = pcs.Count > 0;

        if (MasterAudioInspectorResources.logoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }
        Texture settings = (Texture)Resources.LoadAssetAtPath(MasterAudioFolderPath + "/Sources/Textures/gearIcon.png", typeof(Texture));

        MasterAudio.Instance = null;
        var ma = MasterAudio.Instance;

        DTGUIHelper.ShowColorWarning("The Master Audio prefab holds sound FX group and mixer controls. Add this first (only one per scene).");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);

        EditorGUILayout.LabelField("Master Audio prefab", GUILayout.Width(300));
        if (ma == null)
        {
            GUI.contentColor = Color.green;
            if (GUILayout.Button(new GUIContent("Create", "Create Master Audio prefab"), EditorStyles.toolbarButton, GUILayout.Width(100)))
            {
                CreateMasterAudio();
            }
            GUI.contentColor = Color.white;
        }
        else
        {
            if (settings != null)
            {
                if (GUILayout.Button(new GUIContent(settings, "Master Audio Settings"), EditorStyles.toolbarButton))
                {
                    Selection.activeObject = ma.transform;
                }
            }
            EditorGUILayout.LabelField("Exists in scene", EditorStyles.boldLabel);
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        // Playlist Controller
        DTGUIHelper.ShowColorWarning("The Playlist Controller prefab controls sets of songs (or other audio) and ducking. No limit per scene.");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.LabelField("Playlist Controller prefab", GUILayout.Width(300));

        GUI.contentColor = Color.green;
        if (GUILayout.Button(new GUIContent("Create", "Place a Playlist Controller prefab in the current scene."), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            CreatePlaylistController();
        }
        GUI.contentColor = Color.white;

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        if (!plControllerInScene)
        {
            DTGUIHelper.ShowRedError("*There is no Playlist Controller in the scene. Music will not play.");
        }

        EditorGUILayout.Separator();
        // Dynamic Sound Group Creators
        DTGUIHelper.ShowColorWarning("The Dynamic Sound Group Creator prefab can create Sound Groups on the fly. No limit per scene.");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.LabelField("Dynamic Sound Group Creator prefab", GUILayout.Width(300));

        GUI.contentColor = Color.green;
        if (GUILayout.Button(new GUIContent("Create", "Place a Dynamic Sound Group prefab in the current scene."), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            CreateDynamicSoundGroupCreator();
        }
        GUI.contentColor = Color.white;

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        if (!Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            GUILayout.Label("Utility Functions");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUI.contentColor = Color.green;
            if (GUILayout.Button(new GUIContent("Delete all unused Filter FX", "This will delete all unused Unity Audio Filter FX components in the entire MasterAudio prefab and all Sound Groups within."), EditorStyles.toolbarButton, GUILayout.Width(150)))
            {
                DeleteAllUnusedFilterFX();
            }
            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();
        }

        GUI.EndScrollView();
    }
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 0;

        PlaylistController controller = (PlaylistController)target;

        MasterAudio.Instance = null;

        var ma = MasterAudio.Instance;

        if (ma != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.logoTexture);
        }

        var newVol = EditorGUILayout.Slider("Playlist Volume", controller.playlistVolume, 0f, 1f);

        if (newVol != controller.playlistVolume)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "change Playlist Volume");
            controller.playlistVolume = newVol;
            controller.UpdateMasterVolume();
        }

        ma = MasterAudio.Instance;
        if (ma != null)
        {
            var plNames = MasterAudio.Instance.PlaylistNames;

            var existingIndex = plNames.IndexOf(controller.startPlaylistName);

            int?groupIndex = null;

            var noPl    = false;
            var noMatch = false;

            if (existingIndex >= 1)
            {
                groupIndex = EditorGUILayout.Popup("Initial Playlist", existingIndex, plNames.ToArray());
                if (existingIndex == 1)
                {
                    noPl = true;
                }
            }
            else if (existingIndex == -1 && controller.startPlaylistName == MasterAudio.NO_GROUP_NAME)
            {
                groupIndex = EditorGUILayout.Popup("Initial Playlist", existingIndex, plNames.ToArray());
            }
            else                 // non-match
            {
                noMatch = true;
                var newPlaylist = EditorGUILayout.TextField("Initial Playlist", controller.startPlaylistName);
                if (newPlaylist != controller.startPlaylistName)
                {
                    UndoHelper.RecordObjectPropertyForUndo(controller, "change Initial Playlist");
                    controller.startPlaylistName = newPlaylist;
                }

                var newIndex = EditorGUILayout.Popup("All Playlists", -1, plNames.ToArray());
                if (newIndex >= 0)
                {
                    groupIndex = newIndex;
                }
            }

            if (noPl)
            {
                DTGUIHelper.ShowRedError("Initial Playlist not specified. No music will play.");
            }
            else if (noMatch)
            {
                DTGUIHelper.ShowRedError("Initial Playlist found no match. Type in or choose one from 'All Playlists'.");
            }

            if (groupIndex.HasValue)
            {
                if (existingIndex != groupIndex.Value)
                {
                    UndoHelper.RecordObjectPropertyForUndo(controller, "change Initial Playlist");
                }
                if (groupIndex.Value == -1)
                {
                    controller.startPlaylistName = MasterAudio.NO_GROUP_NAME;
                }
                else
                {
                    controller.startPlaylistName = plNames[groupIndex.Value];
                }
            }
        }


        var syncGroupList = new List <string>();

        for (var i = 0; i < 4; i++)
        {
            syncGroupList.Add((i + 1).ToString());
        }
        syncGroupList.Insert(0, MasterAudio.NO_GROUP_NAME);

        var syncIndex = syncGroupList.IndexOf(controller.syncGroupNum.ToString());

        if (syncIndex == -1)
        {
            syncIndex = 0;
        }
        var newSync = EditorGUILayout.Popup("Controller Sync Group", syncIndex, syncGroupList.ToArray());

        if (newSync != syncIndex)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "change Controller Sync Group");
            controller.syncGroupNum = newSync;
        }

        EditorGUI.indentLevel = 0;
        var newAwake = EditorGUILayout.Toggle("Start Playlist on Awake?", controller.startPlaylistOnAwake);

        if (newAwake != controller.startPlaylistOnAwake)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "toggle Start Playlist on Awake");
            controller.startPlaylistOnAwake = newAwake;
        }

        var newShuffle = EditorGUILayout.Toggle("Shuffle Mode", controller.isShuffle);

        if (newShuffle != controller.isShuffle)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "toggle Shuffle Mode");
            controller.isShuffle = newShuffle;
        }

        var newLoop = EditorGUILayout.Toggle("Loop Playlists", controller.loopPlaylist);

        if (newLoop != controller.loopPlaylist)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "toggle Loop Playlists");
            controller.loopPlaylist = newLoop;
        }

        var newAuto = EditorGUILayout.Toggle("Auto advance clips", controller.isAutoAdvance);

        if (newAuto != controller.isAutoAdvance)
        {
            UndoHelper.RecordObjectPropertyForUndo(controller, "toggle Auto advance clips");
            controller.isAutoAdvance = newAuto;
        }

        DTGUIHelper.ShowColorWarning("*Note: auto advance will not advance past a looped track.");

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
        // ReSharper disable once FunctionComplexityOverflow
        public override void OnInspectorGUI()
        {
            EditorGUI.indentLevel = 0;
            var isDirty = false;

            _variation = (SoundGroupVariation)target;

            if (MasterAudioInspectorResources.LogoTexture != null)
            {
                DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            }

            var parentGroup = _variation.ParentGroup;

            if (parentGroup == null)
            {
                DTGUIHelper.ShowLargeBarAlert("This file cannot be edited in Project View.");
                return;
            }

            var         isVideoPlayersGroup = DTGUIHelper.IsVideoPlayersGroup(_variation.ParentGroup.name);
            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(90)))
            {
                Selection.activeObject = _variation.transform.parent.gameObject;
            }
            GUILayout.FlexibleSpace();

            if (Application.isPlaying)
            {
                if (isVideoPlayersGroup && DTMonoHelper.IsActive(_variation.gameObject))
                {
                    GUI.color = Color.green;
                    var label = "Playing";
                    EditorGUILayout.LabelField(label,
                                               EditorStyles.miniButtonMid, GUILayout.Height(16), GUILayout.Width(240));
                }
                else if (_variation.IsPlaying && _variation.VarAudio.clip != null)
                {
                    // wait for Resource files to load
                    GUI.color = Color.green;

                    var label = "Playing ({0}%)";

                    if (_variation.IsPaused)
                    {
                        GUI.color = Color.yellow;
                        label     = "Paused ({0}%)";
                    }

                    var percentagePlayed = (int)(_variation.VarAudio.time / _variation.VarAudio.clip.length * 100);

                    EditorGUILayout.LabelField(string.Format(label, percentagePlayed),
                                               EditorStyles.miniButtonMid, GUILayout.Height(16), GUILayout.Width(240));

                    _variation.frames++;
                    isDirty = true;

                    GUI.color = DTGUIHelper.BrightButtonColor;
                    if (_variation.ObjectToFollow != null || _variation.ObjectToTriggerFrom != null)
                    {
                        if (GUILayout.Button("Select Caller", EditorStyles.toolbarButton, GUILayout.Width(80)))
                        {
                            if (_variation.ObjectToFollow != null)
                            {
                                Selection.activeGameObject = _variation.ObjectToFollow.gameObject;
                            }
                            else
                            {
                                Selection.activeGameObject = _variation.ObjectToTriggerFrom.gameObject;
                            }
                        }
                    }
                }
                else
                {
                    GUI.color = Color.red;
                    EditorGUILayout.LabelField("Not playing", EditorStyles.miniButtonMid, GUILayout.Height(16), GUILayout.Width(240));
                }
            }

            GUI.color        = Color.white;
            GUI.contentColor = Color.white;

            _ma = MasterAudio.Instance;
            var maInScene = _ma != null;

            if (maInScene)
            {
                var buttonPressed = DTGUIHelper.AddVariationButtons();

                switch (buttonPressed)
                {
                case DTGUIHelper.DTFunctionButtons.Play:
                    if (DTGUIHelper.IsVideoPlayersGroup(_variation.ParentGroup.name))
                    {
                        break;
                    }

                    previewer = MasterAudioInspector.GetPreviewer();

                    if (Application.isPlaying)
                    {
                        MasterAudio.PlaySound3DAtVector3AndForget(_variation.ParentGroup.name, previewer.transform.position, 1f, null, 0f, _variation.name);
                    }
                    else
                    {
                        isDirty = true;

                        var randPitch = GetRandomPreviewPitch(_variation);
                        var varVol    = GetRandomPreviewVolume(_variation);

                        if (previewer != null)
                        {
                            MasterAudioInspector.StopPreviewer();
                            previewer.pitch = randPitch;
                        }

                        var calcVolume = varVol * parentGroup.groupMasterVolume;

                        switch (_variation.audLocation)
                        {
                        case MasterAudio.AudioLocation.ResourceFile:
                            if (previewer != null)
                            {
                                var fileName = AudioResourceOptimizer.GetLocalizedFileName(_variation.useLocalization, _variation.resourceFileName);
                                previewer.PlayOneShot(Resources.Load(fileName) as AudioClip, calcVolume);
                            }
                            break;

                        case MasterAudio.AudioLocation.Clip:
                            if (previewer != null)
                            {
                                previewer.PlayOneShot(_variation.VarAudio.clip, calcVolume);
                            }
                            break;

#if ADDRESSABLES_ENABLED
                        case MasterAudio.AudioLocation.Addressable:
                            DTGUIHelper.PreviewAddressable(_variation.audioClipAddressable, previewer, calcVolume);
                            break;
#endif
                        }
                    }
                    break;

                case DTGUIHelper.DTFunctionButtons.Stop:
                    if (DTGUIHelper.IsVideoPlayersGroup(_variation.ParentGroup.name))
                    {
                        break;
                    }

                    if (Application.isPlaying)
                    {
                        MasterAudio.StopAllOfSound(_variation.transform.parent.name);
                    }
                    else
                    {
                        MasterAudioInspector.StopPreviewer();
                    }
                    break;
                }
            }

            EditorGUILayout.EndHorizontal();

            DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm", "http://www.dtdevtools.com/API/masteraudio/class_dark_tonic_1_1_master_audio_1_1_sound_group_variation.html");

            if (!isVideoPlayersGroup)
            {
                if (maInScene && !Application.isPlaying)
                {
                    DTGUIHelper.ShowColorWarning(MasterAudio.PreviewText);
                }

                if (!Application.isPlaying)
                {
                    var newAlias = EditorGUILayout.TextField("Clip Id (optional)", _variation.clipAlias);

                    if (newAlias != _variation.clipAlias)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Clip Id");
                        _variation.clipAlias = newAlias;
                    }
                }

                var oldLocation = _variation.audLocation;
                EditorGUILayout.BeginHorizontal();
                if (!Application.isPlaying)
                {
                    var newLocation =
                        (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation);

                    if (newLocation != oldLocation)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin");
                        _variation.audLocation = newLocation;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Audio Origin", _variation.audLocation.ToString());
                }
                DTGUIHelper.AddHelpIconNoStyle("http://www.dtdevtools.com/docs/masteraudio/SoundGroupVariations.htm#AudioOrigin");
                EditorGUILayout.EndHorizontal();

                if (oldLocation != _variation.audLocation && oldLocation == MasterAudio.AudioLocation.Clip)
                {
                    if (_variation.VarAudio.clip != null)
                    {
                        Debug.Log("Audio clip removed to prevent unnecessary memory usage.");
                    }
                    _variation.VarAudio.clip = null;
                }

                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;

#if ADDRESSABLES_ENABLED
                case MasterAudio.AudioLocation.Addressable:
                    serializedObject.Update();
                    EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(SoundGroupVariation.audioClipAddressable)), true);
                    serializedObject.ApplyModifiedProperties();

                    if (!DTGUIHelper.IsAddressableTypeValid(_variation.audioClipAddressable, _variation.name))
                    {
                        _variation.audioClipAddressable = null;
                        isDirty = true;
                    }
                    break;
#endif
                case MasterAudio.AudioLocation.ResourceFile:
                    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)
                            {
                                // ReSharper disable once ExpressionIsAlwaysNull
                                var aClip = dragged as AudioClip;
                                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                                if (aClip == null)
                                {
                                    continue;
                                }

                                // ReSharper disable HeuristicUnreachableCode
                                var useLocalization = false;
                                newFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization);
                                if (string.IsNullOrEmpty(newFilename))
                                {
                                    newFilename = aClip.name;
                                }

                                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename");
                                _variation.resourceFileName = newFilename;
                                _variation.useLocalization  = useLocalization;
                                break;
                                // ReSharper restore HeuristicUnreachableCode
                            }
                        }
                        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 = DTGUIHelper.DisplayVolumeField(_variation.VarAudio.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
            if (newVolume != _variation.VarAudio.volume)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Volume");
                _variation.VarAudio.volume = newVolume;
            }

            if (isVideoPlayersGroup)
            {
                DTGUIHelper.ShowColorWarning("This is the specially named Sound Group for Video Players. Most controls for this Sound Group cannot be used for Video Players and are hidden.");
            }

            if (!isVideoPlayersGroup)
            {
                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 (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.AddHelpIconNoStyle("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.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.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.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();

                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.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;
                    }

                    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;
                    }

                    if (_variation.VarAudio.loop)
                    {
                        DTGUIHelper.ShowColorWarning("Looped clips will not automatically use the custom fade out. You will need to call FadeOutNowAndStop() on the Variation to use the fade.");
                    }
                }

                EditorGUILayout.EndToggleGroup();
            }

            if (GUI.changed || isDirty)
            {
                EditorUtility.SetDirty(target);
            }

            //DrawDefaultInspector();
        }
Esempio n. 17
0
    public override void OnInspectorGUI()
    {
        var tracker = (AudioTransformTracker)target;

        MasterAudio.Instance = null;

        var ma        = MasterAudio.SafeInstance;
        var maInScene = ma != null;

        if (maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }
        else
        {
            return;
        }

        if (!Application.isPlaying)
        {
            DTGUIHelper.ShowLargeBarAlert("This script only works at runtime.");
            return;
        }

        var allVars = MasterAudio.GetAllPlayingVariationsOfTransform(tracker.Trans);

        DTGUIHelper.ShowColorWarning("Sounds made by this Transform: " + allVars.Count);

        if (allVars.Count > 0)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Stop All Sounds", EditorStyles.toolbarButton, GUILayout.Width(110)))
            {
                MasterAudio.StopAllSoundsOfTransform(tracker.Trans);
            }
            GUILayout.Space(4);
            if (GUILayout.Button("Pause All Sounds", EditorStyles.toolbarButton, GUILayout.Width(110)))
            {
                MasterAudio.PauseAllSoundsOfTransform(tracker.Trans);
            }
            GUILayout.Space(4);
            if (GUILayout.Button("Unpause All Sounds", EditorStyles.toolbarButton, GUILayout.Width(120)))
            {
                MasterAudio.UnpauseAllSoundsOfTransform(tracker.Trans);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();
        }

        GUI.color = Color.white;
        var lastGrpName = string.Empty;
        var groupCount  = 0;

        foreach (var variation in allVars)
        {
            var grpName = variation.ParentGroup.GameObjectName;

            if (grpName != lastGrpName)
            {
                groupCount++;
                if (groupCount > 1)
                {
                    EditorGUILayout.Separator();
                }

                GUI.color = DTGUIHelper.ActiveHeaderColor;
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                GUILayout.Label(grpName);

                GUILayout.FlexibleSpace();
                if (DTGUIHelper.AddSettingsButton("Group", true) == DTGUIHelper.DTFunctionButtons.Go)
                {
                    Selection.activeObject = variation.ParentGroup.gameObject;
                }
                var groupButtonPressed = DTGUIHelper.Add2WayTrackerButtons();

                switch (groupButtonPressed)
                {
                case DTGUIHelper.DTFunctionButtons.Stop:
                    tracker.Trans.StopSoundGroupOfTransform(grpName);
                    break;

                case DTGUIHelper.DTFunctionButtons.Pause:
                    tracker.Trans.PauseSoundGroupOfTransform(grpName);
                    break;

                case DTGUIHelper.DTFunctionButtons.Play:
                    tracker.Trans.UnpauseSoundGroupOfTransform(grpName);
                    break;
                }

                EditorGUILayout.EndHorizontal();
            }

            GUI.color = Color.white;
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(10);

            var varName = variation.name;
            GUILayout.Label(varName);

            GUILayout.FlexibleSpace();
            GUI.color = Color.green;

            var label = "Playing ({0}%)";

            if (variation.IsPaused)
            {
                GUI.color = Color.yellow;
                label     = "Paused ({0}%)";
            }

            var percentagePlayed = 0;
            if (variation.VarAudio.clip != null)
            {
                percentagePlayed = (int)(variation.VarAudio.time / variation.VarAudio.clip.length * 100);
            }

            EditorGUILayout.LabelField(string.Format(label, percentagePlayed), EditorStyles.miniButtonMid, GUILayout.Height(16));

            GUI.color = Color.white;

            if (DTGUIHelper.AddSettingsButton("Variation") == DTGUIHelper.DTFunctionButtons.Go)
            {
                Selection.activeObject = variation.gameObject;
            }
            var buttonPressed = DTGUIHelper.Add2WayTrackerButtons();

            switch (buttonPressed)
            {
            case DTGUIHelper.DTFunctionButtons.Stop:
                variation.Stop();
                break;

            case DTGUIHelper.DTFunctionButtons.Pause:
                variation.Pause();
                break;

            case DTGUIHelper.DTFunctionButtons.Play:
                variation.VarAudio.Play();
                break;
            }

            EditorGUILayout.EndHorizontal();

            lastGrpName = grpName;
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
    // ReSharper disable once UnusedMember.Local
    // ReSharper disable once InconsistentNaming
    void OnGUI()
    {
        _scrollPos = GUI.BeginScrollView(
            new Rect(0, 0, position.width, position.height),
            _scrollPos,
            new Rect(0, 0, 550, 540)
            );

        PlaylistController.Instances = null;
        var pcs = PlaylistController.Instances;
        // ReSharper disable once PossibleNullReferenceException
        var plControllerInScene = pcs.Count > 0;

        if (MasterAudioInspectorResources.LogoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        if (Application.isPlaying)
        {
            DTGUIHelper.ShowLargeBarAlert("This screen cannot be used during play.");
            GUI.EndScrollView();
            return;
        }

        var settings = MasterAudioInspectorResources.GearTexture;

        MasterAudio.Instance = null;
        var ma        = MasterAudio.Instance;
        var maInScene = ma != null;

        var organizer    = FindObjectOfType(typeof(SoundGroupOrganizer));
        var hasOrganizer = organizer != null;

        DTGUIHelper.ShowColorWarning("The Master Audio prefab holds sound FX group and mixer controls. Add this first (only one per scene).");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);

        EditorGUILayout.LabelField("Master Audio prefab", GUILayout.Width(300));
        if (!maInScene)
        {
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Create", "Create Master Audio prefab"), EditorStyles.toolbarButton, GUILayout.Width(100)))
            {
                var go = MasterAudio.CreateMasterAudio();
                AudioUndoHelper.CreateObjectForUndo(go, "Create Master Audio prefab");
            }
            GUI.contentColor = Color.white;
        }
        else
        {
            if (settings != null)
            {
                if (GUILayout.Button(new GUIContent(settings, "Master Audio Settings"), EditorStyles.toolbarButton))
                {
                    Selection.activeObject = ma.transform;
                }
            }
            EditorGUILayout.LabelField("Exists in scene", EditorStyles.boldLabel);
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        // Playlist Controller
        DTGUIHelper.ShowColorWarning("The Playlist Controller prefab controls sets of songs (or other audio) and ducking. No limit per scene.");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.LabelField("Playlist Controller prefab", GUILayout.Width(300));

        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        if (GUILayout.Button(new GUIContent("Create", "Place a Playlist Controller prefab in the current scene."), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            var go = MasterAudio.CreatePlaylistController();
            AudioUndoHelper.CreateObjectForUndo(go, "Create Playlist Controller prefab");
        }
        GUI.contentColor = Color.white;

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        if (!plControllerInScene)
        {
            DTGUIHelper.ShowLargeBarAlert("There is no Playlist Controller in the scene. Music will not play.");
        }

        EditorGUILayout.Separator();
        // Dynamic Sound Group Creators
        DTGUIHelper.ShowColorWarning("The Dynamic Sound Group Creator prefab can per-Scene Sound Groups and other audio. No limit per scene.");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.LabelField("Dynamic Sound Group Creator prefab", GUILayout.Width(300));

        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        if (GUILayout.Button(new GUIContent("Create", "Place a Dynamic Sound Group prefab in the current scene."), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            var go = MasterAudio.CreateDynamicSoundGroupCreator();
            AudioUndoHelper.CreateObjectForUndo(go, "Create Dynamic Sound Group Creator prefab");
        }

        GUI.contentColor = Color.white;

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.Separator();
        // Sound Group Organizer
        DTGUIHelper.ShowColorWarning("The Sound Group Organizer prefab can import/export Groups to/from MA and Dynamic SGC prefabs.");
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.LabelField("Sound Group Organizer prefab", GUILayout.Width(300));

        if (hasOrganizer)
        {
            if (settings != null)
            {
                if (GUILayout.Button(new GUIContent(settings, "Sound Group Organizer Settings"), EditorStyles.toolbarButton))
                {
                    Selection.activeObject = organizer;
                }
            }
            EditorGUILayout.LabelField("Exists in scene", EditorStyles.boldLabel);
        }
        else
        {
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Create", "Place a Sound Group Organizer prefab in the current scene."), EditorStyles.toolbarButton, GUILayout.Width(100)))
            {
                var go = MasterAudio.CreateSoundGroupOrganizer();
                AudioUndoHelper.CreateObjectForUndo(go, "Create Dynamic Sound Group Creator prefab");
            }
        }

        GUI.contentColor = Color.white;

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.Separator();

        if (!Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            GUILayout.Label("Global Settings");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            var newVol = GUILayout.Toggle(MasterAudio.UseDbScaleForVolume, " Display dB For Volumes");
            // ReSharper disable once RedundantCheckBeforeAssignment
            if (newVol != MasterAudio.UseDbScaleForVolume)
            {
                MasterAudio.UseDbScaleForVolume = newVol;
            }

            GUILayout.Space(30);

            var newCents = GUILayout.Toggle(MasterAudio.UseCentsForPitch, " Display Semitones for Pitches");
            // ReSharper disable once RedundantCheckBeforeAssignment
            if (newCents != MasterAudio.UseCentsForPitch)
            {
                MasterAudio.UseCentsForPitch = newCents;
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            var useLogo = GUILayout.Toggle(MasterAudio.HideLogoNav, " Hide Logo Nav. in Inspectors");
            // ReSharper disable once RedundantCheckBeforeAssignment
            if (useLogo != MasterAudio.HideLogoNav)
            {
                MasterAudio.HideLogoNav = useLogo;
            }

            if (!Application.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                MasterAudio._editMAFolder = GUILayout.Toggle(MasterAudio._editMAFolder, " Edit Installation Path");

                if (MasterAudio._editMAFolder)
                {
                    var path = EditorGUILayout.TextField("", MasterAudio.ProspectiveMAPath);
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (!string.IsNullOrEmpty(path))
                    {
                        MasterAudio.ProspectiveMAPath = path;
                    }
                    else
                    {
                        MasterAudio.ProspectiveMAPath = MasterAudio.MasterAudioFolderPath;
                    }
                    GUI.contentColor = DTGUIHelper.BrightButtonColor;
                    if (GUILayout.Button(new GUIContent("Update", "This will update the installation folder path with the value to the left."), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        MasterAudio.MasterAudioFolderPath = MasterAudio.ProspectiveMAPath;
                        DTGUIHelper.ShowAlert("Installation Path updated!");
                    }
                    GUILayout.Space(4);
                    if (GUILayout.Button(new GUIContent("Revert", "Revert to default settings"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        MasterAudio.MasterAudioFolderPath = MasterAudio.MasterAudioDefaultFolder;
                        MasterAudio.ProspectiveMAPath     = MasterAudio.MasterAudioDefaultFolder;
                        DTGUIHelper.ShowAlert("Installation Path reverted!");
                    }
                    GUI.contentColor = Color.white;
                    GUILayout.Space(10);
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            GUILayout.Label("Utility Functions");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Delete all unused Filter FX", "This will delete all unused Unity Audio Filter FX components in the entire MasterAudio prefab and all Sound Groups within."), EditorStyles.toolbarButton, GUILayout.Width(160)))
            {
                DeleteAllUnusedFilterFx();
            }

            GUILayout.Space(10);

            if (GUILayout.Button(new GUIContent("Reset Prefs / Settings", "This will delete all Master Audio's Persistent Settings and global preferences (back to installation default). None of your prefabs will be deleted."), EditorStyles.toolbarButton, GUILayout.Width(160)))
            {
                ResetPrefs();
            }

            if (maInScene)
            {
                GUILayout.Space(10);

                if (GUILayout.Button(new GUIContent("Upgrade MA Prefab to V3.5.5", "This will upgrade all Sound Groups in the entire MasterAudio prefab and all Sound Groups within to the latest changes, including a new script in V3.5.5."), EditorStyles.toolbarButton, GUILayout.Width(160)))
                {
                    UpgradeMasterAudioPrefab();
                }
            }

            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();
        }

        GUI.EndScrollView();
    }
Esempio n. 19
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        var controller = (PlaylistController)target;

        MasterAudio.Instance = null;

        var ma        = MasterAudio.SafeInstance;
        var maInScene = ma != null;

        if (maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            _customEventNames = ma.CustomEventNames;
        }

        DTGUIHelper.HelpHeader("https://dl.dropboxusercontent.com/u/40293802/DarkTonic/MA_OnlineDocs/PlaylistControllers.htm", "https://dl.dropboxusercontent.com/u/40293802/DarkTonic/MasterAudio_API/class_dark_tonic_1_1_master_audio_1_1_playlist_controller.html");

        var isDirty = false;

        EditorGUILayout.BeginHorizontal();

        var newVol = DTGUIHelper.DisplayVolumeField(controller._playlistVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Playlist Volume");

        // ReSharper disable once CompareOfFloatsByEqualityOperator
        if (newVol != controller._playlistVolume)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Playlist Volume");
            controller.PlaylistVolume = newVol;
        }

        var buttonPressed = DTGUIHelper.AddPlaylistControllerGOButtons(controller, "Playlist Controller");

        EditorGUILayout.EndHorizontal();

        switch (buttonPressed)
        {
        case DTGUIHelper.DTFunctionButtons.Mute:
            controller.ToggleMutePlaylist();
            break;
        }

        if (maInScene)
        {
            // ReSharper disable once PossibleNullReferenceException
            var plNames = MasterAudio.Instance.PlaylistNames;

            var existingIndex = plNames.IndexOf(controller.startPlaylistName);

            int?groupIndex = null;

            var noPl    = false;
            var noMatch = false;

            if (existingIndex >= 1)
            {
                groupIndex = EditorGUILayout.Popup("Initial Playlist", existingIndex, plNames.ToArray());
                if (existingIndex == 1)
                {
                    noPl = true;
                }
            }
            else if (existingIndex == -1 && controller.startPlaylistName == MasterAudio.NoGroupName)
            {
                groupIndex = EditorGUILayout.Popup("Initial Playlist", existingIndex, plNames.ToArray());
            }
            else     // non-match
            {
                noMatch = true;
                var newPlaylist = EditorGUILayout.TextField("Initial Playlist", controller.startPlaylistName);
                if (newPlaylist != controller.startPlaylistName)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Initial Playlist");
                    controller.startPlaylistName = newPlaylist;
                }

                var newIndex = EditorGUILayout.Popup("All Playlists", -1, plNames.ToArray());
                if (newIndex >= 0)
                {
                    groupIndex = newIndex;
                }
            }

            if (noPl)
            {
                DTGUIHelper.ShowRedError("Initial Playlist not specified. No music will play.");
            }
            else if (noMatch)
            {
                DTGUIHelper.ShowRedError("Initial Playlist found no match. Type in or choose one from 'All Playlists'.");
            }

            if (groupIndex.HasValue)
            {
                if (existingIndex != groupIndex.Value)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Initial Playlist");
                }
                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (groupIndex.Value == -1)
                {
                    controller.startPlaylistName = MasterAudio.NoGroupName;
                }
                else
                {
                    controller.startPlaylistName = plNames[groupIndex.Value];
                }
            }
        }


        var syncGroupList = new List <string>();

        for (var i = 0; i < 4; i++)
        {
            syncGroupList.Add((i + 1).ToString());
        }
        syncGroupList.Insert(0, MasterAudio.NoGroupName);

        var syncIndex = syncGroupList.IndexOf(controller.syncGroupNum.ToString());

        if (syncIndex == -1)
        {
            syncIndex = 0;
        }
        var newSync = EditorGUILayout.Popup("Controller Sync Group", syncIndex, syncGroupList.ToArray());

        if (newSync != syncIndex)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Controller Sync Group");
            controller.syncGroupNum = newSync;
        }

        EditorGUI.indentLevel = 0;

#if UNITY_5
        var newChan = (AudioMixerGroup)EditorGUILayout.ObjectField("Mixer Group", controller.mixerChannel, typeof(AudioMixerGroup), false);
        if (newChan != controller.mixerChannel)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Unity Mixer Group");
            controller.mixerChannel = newChan;

            if (Application.isPlaying)
            {
                controller.RouteToMixerChannel(newChan);
            }
        }

        if (!maInScene || ma.musicSpatialBlendType == MasterAudio.AllMusicSpatialBlendType.AllowDifferentPerController)
        {
            var newMusicSpatialType = (MasterAudio.ItemSpatialBlendType)EditorGUILayout.EnumPopup("Spatial Blend Rule", controller.spatialBlendType);
            if (newMusicSpatialType != controller.spatialBlendType)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Spatial Blend Rule");
                controller.spatialBlendType = newMusicSpatialType;
                if (Application.isPlaying)
                {
                    controller.SetSpatialBlend();
                }
            }

            switch (controller.spatialBlendType)
            {
            case MasterAudio.ItemSpatialBlendType.ForceToCustom:
                EditorGUI.indentLevel = 1;
                DTGUIHelper.ShowLargeBarAlert(MasterAudioInspector.SpatialBlendSliderText);
                var newMusic3D = EditorGUILayout.Slider("Spatial Blend", controller.spatialBlend, 0f, 1f);
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (newMusic3D != controller.spatialBlend)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Spatial Blend");
                    controller.spatialBlend = newMusic3D;

                    if (Application.isPlaying)
                    {
                        controller.SetSpatialBlend();
                    }
                }
                break;
            }
        }
        else
        {
            DTGUIHelper.ShowLargeBarAlert("Spatial Blend is currently controlled globally in the Master Audio prefab.");
        }
                #endif

        EditorGUI.indentLevel = 0;
        var newAwake = EditorGUILayout.Toggle("Start Playlist on Awake?", controller.startPlaylistOnAwake);
        if (newAwake != controller.startPlaylistOnAwake)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle Start Playlist on Awake");
            controller.startPlaylistOnAwake = newAwake;
        }

        var newShuffle = EditorGUILayout.Toggle("Shuffle Mode", controller.isShuffle);
        if (newShuffle != controller.isShuffle)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle Shuffle Mode");
            controller.isShuffle = newShuffle;
        }

        var newLoop = EditorGUILayout.Toggle("Loop Playlists", controller.loopPlaylist);
        if (newLoop != controller.loopPlaylist)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle Loop Playlists");
            controller.loopPlaylist = newLoop;
        }

        var newAuto = EditorGUILayout.Toggle("Auto advance clips", controller.isAutoAdvance);
        if (newAuto != controller.isAutoAdvance)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle Auto advance clips");
            controller.isAutoAdvance = newAuto;
        }

        DTGUIHelper.ShowColorWarning("Note: auto advance will not advance past a looped track.");

        DTGUIHelper.StartGroupHeader();

        var newUse = EditorGUILayout.BeginToggleGroup(" Song Changed Event", controller.songChangedEventExpanded);
        if (newUse != controller.songChangedEventExpanded)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle expand Song Changed Event");
            controller.songChangedEventExpanded = newUse;
        }
        DTGUIHelper.EndGroupHeader();

        GUI.color = Color.white;

        if (controller.songChangedEventExpanded)
        {
            DTGUIHelper.ShowColorWarning("When song changes, fire Custom Event below.");

            if (maInScene)
            {
                var existingIndex = _customEventNames.IndexOf(controller.songChangedCustomEvent);

                int?customEventIndex = null;

                EditorGUI.indentLevel = 0;

                var noEvent = false;
                var noMatch = false;

                if (existingIndex >= 1)
                {
                    customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                    if (existingIndex == 1)
                    {
                        noEvent = true;
                    }
                }
                else if (existingIndex == -1 && controller.songChangedCustomEvent == MasterAudio.NoGroupName)
                {
                    customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                }
                else                     // non-match
                {
                    noMatch = true;
                    var newEventName = EditorGUILayout.TextField("Custom Event Name", controller.songChangedCustomEvent);
                    if (newEventName != controller.songChangedCustomEvent)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Custom Event Name");
                        controller.songChangedCustomEvent = newEventName;
                    }

                    var newIndex = EditorGUILayout.Popup("All Custom Events", -1, _customEventNames.ToArray());
                    if (newIndex >= 0)
                    {
                        customEventIndex = newIndex;
                    }
                }

                if (noEvent)
                {
                    DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing.");
                }
                else if (noMatch)
                {
                    DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one.");
                }

                if (customEventIndex.HasValue)
                {
                    if (existingIndex != customEventIndex.Value)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Custom Event");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (customEventIndex.Value == -1)
                    {
                        controller.songChangedCustomEvent = MasterAudio.NoGroupName;
                    }
                    else
                    {
                        controller.songChangedCustomEvent = _customEventNames[customEventIndex.Value];
                    }
                }
            }
            else
            {
                var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", controller.songChangedCustomEvent);
                if (newCustomEvent != controller.songChangedCustomEvent)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "Custom Event Name");
                    controller.songChangedCustomEvent = newCustomEvent;
                }
            }
        }

        EditorGUILayout.EndToggleGroup();
        DTGUIHelper.AddSpaceForNonU5(2);

        DTGUIHelper.StartGroupHeader();

        newUse = EditorGUILayout.BeginToggleGroup(" Song Ended Event", controller.songEndedEventExpanded);
        if (newUse != controller.songEndedEventExpanded)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "toggle expand Song Ended Event");
            controller.songEndedEventExpanded = newUse;
        }
        DTGUIHelper.EndGroupHeader();

        GUI.color = Color.white;

        if (controller.songEndedEventExpanded)
        {
            DTGUIHelper.ShowColorWarning("When song ends, fire Custom Event below.");

            if (maInScene)
            {
                var existingIndex = _customEventNames.IndexOf(controller.songEndedCustomEvent);

                int?customEventIndex = null;

                EditorGUI.indentLevel = 0;

                var noEvent = false;
                var noMatch = false;

                if (existingIndex >= 1)
                {
                    customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                    if (existingIndex == 1)
                    {
                        noEvent = true;
                    }
                }
                else if (existingIndex == -1 && controller.songEndedCustomEvent == MasterAudio.NoGroupName)
                {
                    customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                }
                else     // non-match
                {
                    noMatch = true;
                    var newEventName = EditorGUILayout.TextField("Custom Event Name", controller.songEndedCustomEvent);
                    if (newEventName != controller.songEndedCustomEvent)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Custom Event Name");
                        controller.songEndedCustomEvent = newEventName;
                    }

                    var newIndex = EditorGUILayout.Popup("All Custom Events", -1, _customEventNames.ToArray());
                    if (newIndex >= 0)
                    {
                        customEventIndex = newIndex;
                    }
                }

                if (noEvent)
                {
                    DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing.");
                }
                else if (noMatch)
                {
                    DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one.");
                }

                if (customEventIndex.HasValue)
                {
                    if (existingIndex != customEventIndex.Value)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "change Custom Event");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (customEventIndex.Value == -1)
                    {
                        controller.songEndedCustomEvent = MasterAudio.NoGroupName;
                    }
                    else
                    {
                        controller.songEndedCustomEvent = _customEventNames[customEventIndex.Value];
                    }
                }
            }
            else
            {
                var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", controller.songEndedCustomEvent);
                if (newCustomEvent != controller.songEndedCustomEvent)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, controller, "Custom Event Name");
                    controller.songEndedCustomEvent = newCustomEvent;
                }
            }
        }
        EditorGUILayout.EndToggleGroup();

        if (GUI.changed || isDirty)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
Esempio n. 20
0
    // ReSharper disable once UnusedMember.Local
    // ReSharper disable once InconsistentNaming
    void OnGUI()
    {
        _outsideScrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), _outsideScrollPos, new Rect(0, 0, 900, 666));

        if (MasterAudioInspectorResources.LogoTexture != null)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
        }

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        if (GUILayout.Button(new GUIContent("Scan Project"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            BuildCache();
            return;
        }

        GUILayout.Space(10);
        if (GUILayout.Button(new GUIContent("Revert Selected"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            RevertSelected();
            return;
        }

        GUILayout.Space(10);
        if (GUILayout.Button(new GUIContent("Apply Selected"), EditorStyles.toolbarButton, GUILayout.Width(100)))
        {
            ApplySelected();
            return;
        }

        GUILayout.Space(10);
        RevertColor();

        GUILayout.Label("Full Path Filter");
        var oldFilter = _clipList.SearchFilter;
        var newFilter = GUILayout.TextField(_clipList.SearchFilter, EditorStyles.toolbarTextField, GUILayout.Width(200));

        if (newFilter != oldFilter)
        {
            _clipList.SearchFilter = newFilter;
            RebuildFilteredList();
        }

        var myPosition = GUILayoutUtility.GetRect(10, 10, ToolbarSeachCancelButton);

        myPosition.x -= 5;
        if (GUI.Button(myPosition, "", ToolbarSeachCancelButton))
        {
            _clipList.SearchFilter = string.Empty;
            RebuildFilteredList();
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!File.Exists(CacheFilePath))
        {
            DTGUIHelper.ShowLargeBarAlert("Click 'Scan Project' to generate list of Audio Clips.");
            GUI.EndScrollView();
            return;
        }

        if (_clipList.AudioInfor.Count == 0 || _clipList.NeedsRefresh)
        {
            if (!LoadAndTranslateFile())
            {
                GUI.EndScrollView();
                return;
            }
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Folder");
        var selectedIndex = _folderPaths.IndexOf(_selectedFolderPath);
        var newIndex      = EditorGUILayout.Popup(selectedIndex, _folderPaths.ToArray(), GUILayout.Width(800));

        if (newIndex != selectedIndex)
        {
            _selectedFolderPath = _folderPaths[newIndex];
            RebuildFilteredList();
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        var totalClips  = _clipList.AudioInfor.Count;
        var dynamicText = string.Format("{0}/{1} clips selected.", SelectedClips.Count, FilteredClips.Count);

        dynamicText += " Total clips: " + totalClips;

        double clipCount = totalClips;

        if (_filteredOut != null)
        {
            clipCount = _filteredOut.Count;
        }

        var pageCount = (int)Math.Ceiling(clipCount / MaxPageSize);

        var pageNames = new string[pageCount];
        var pageNums  = new int[pageCount];

        for (var i = 0; i < pageCount; i++)
        {
            pageNames[i] = "Page " + (i + 1);
            pageNums[i]  = i;
        }


        EditorGUILayout.LabelField(dynamicText);

        var oldPage = _pageNumber;

        EditorGUILayout.BeginHorizontal();
        _pageNumber = EditorGUILayout.IntPopup("", _pageNumber, pageNames, pageNums, GUILayout.Width(100));
        if (oldPage != _pageNumber)
        {
            RebuildFilteredList(true);
        }
        GUILayout.Label("of " + pageCount);

        EditorGUILayout.EndHorizontal();

        // display
        DisplayClips();

        ShowBulkOperations();

        GUI.EndScrollView();
    }
    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();
    }