コード例 #1
0
    public static void CopyFromAudioSourceTemplate(DynamicSoundGroupCreator creator, AudioSource oldAudSrc, bool showError)
    {
        #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0
        Debug.LogError("This feature is only supported in Unity 4.1+");
        #else
        var selSource = SelectedAudioSourceTemplate(creator);
        if (selSource == null) {
            if (showError) {
                Debug.LogError("No Audio Source Template selected.");
            }
            return;
        }

        var templateAudio = selSource.GetComponent<AudioSource>();

        var oldPitch = oldAudSrc.pitch;
        var oldLoop = oldAudSrc.loop;
        var oldClip = oldAudSrc.clip;
        var oldVol = oldAudSrc.volume;

        UnityEditorInternal.ComponentUtility.CopyComponent(templateAudio);
        UnityEditorInternal.ComponentUtility.PasteComponentValues(oldAudSrc);

        oldAudSrc.pitch = oldPitch;
        oldAudSrc.loop = oldLoop;
        oldAudSrc.clip = oldClip;
        oldAudSrc.volume = oldVol;
        #endif
    }
コード例 #2
0
    public static string GetLocalizedDynamicSoundGroupFileName(DynamicSoundGroupCreator creator, bool useLocalization, string resourceFileName)
    {
        if (!useLocalization) {
            return resourceFileName;
        }

        if (MasterAudio.Instance != null) {
            return GetLocalizedFileName(useLocalization, resourceFileName);
        }

        return creator.previewLanguage.ToString() + "/" + resourceFileName;
    }
コード例 #3
0
ファイル: GUIHelper.cs プロジェクト: Tavrox/4E_Sinusoid
    public static DTFunctionButtons AddDynamicGroupButtons(DynamicSoundGroupCreator creator)
    {
        GUIContent deleteIcon;
        GUIContent settingsIcon;
        GUIContent previewIcon;
        GUIContent stopPreviewIcon;

        if (creator.deleteTexture != null) {
            deleteIcon = new GUIContent(creator.deleteTexture, "Click to delete Group");
        } else {
            deleteIcon = new GUIContent("Delete", "Click to delete Group");
        }

        if (creator.settingsTexture != null) {
            settingsIcon = new GUIContent(creator.settingsTexture, "Click to edit Group");
        } else {
            settingsIcon = new GUIContent("Edit", "Click to edit Group");
        }

        if (creator.playTexture != null) {
            previewIcon = new GUIContent(creator.playTexture, "Click to preview Group");
        } else {
            previewIcon = new GUIContent("Preview", "Click to preview Group");
        }

        if (creator.stopTrackTexture != null) {
            stopPreviewIcon = new GUIContent(creator.stopTrackTexture, "Click to stop previewing Group");
        } else {
            stopPreviewIcon = new GUIContent("End Preview", "Click to stop previewing Group");
        }

        if (GUILayout.Button(settingsIcon, EditorStyles.toolbarButton)) {
            return DTFunctionButtons.Go;
        }

        if (GUILayout.Button(previewIcon, EditorStyles.toolbarButton)) {
            return DTFunctionButtons.Play;
        }

        if (GUILayout.Button(stopPreviewIcon, EditorStyles.toolbarButton)) {
            return DTFunctionButtons.Stop;
        }

        if (!Application.isPlaying) {
            if (GUILayout.Button(deleteIcon, EditorStyles.toolbarButton)) {
                return DTFunctionButtons.Remove;
            }
        }

        return DTFunctionButtons.None;
    }
コード例 #4
0
ファイル: GUIHelper.cs プロジェクト: Tavrox/4E_Sinusoid
 public static bool AddDynamicDeleteIcon(DynamicSoundGroupCreator creator, string itemName)
 {
     var deleteIcon = creator.deleteTexture;
     return GUILayout.Button(new GUIContent(deleteIcon, "Click to delete " + itemName), EditorStyles.toolbarButton, GUILayout.MaxWidth(30));
 }
コード例 #5
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 0;
        var isDirty = false;
        isValid = true;

        _group = (DynamicSoundGroup)target;

        _group = RescanChildren(_group);

        if (_group == null) {
            return;
        }

        var dsgc = _group.transform.parent;
        if (dsgc != null) {
            _creator = dsgc.GetComponent<DynamicSoundGroupCreator>();
        }

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

        if (!isValid) {
            return;
        }

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

        if (maInScene) {
            groupNames = ma.GroupNames;
            groupNames.Remove(_group.name);
        }

        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(ref isDirty, _group, "change Group Master Volume");
            _group.groupMasterVolume = newVol;
        }

        var newVarSequence = (MasterAudioGroup.VariationSequence) EditorGUILayout.EnumPopup("Variation Sequence", _group.curVariationSequence);
        if (newVarSequence != _group.curVariationSequence) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _group, "change Retrigger Percentage");
                    _group.retriggerPercentage = newRetrigger;
                }

                var newLimitPoly = EditorGUILayout.Toggle("Limit Polyphony", _group.limitPolyphony);
                if (newLimitPoly != _group.limitPolyphony) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _group, "change Custom Fade Out Time");
                        _group.dialogFadeOutTime = newFadeTime;
                    }
                }
                break;
        }

        EditorGUI.indentLevel = 0;

        var newChildMode = (MasterAudioGroup.ChildGroupMode)EditorGUILayout.EnumPopup(new GUIContent("Linked Group Mode", "Groups you set up in this section will also get played automatically when this Group plays."), _group.childGroupMode);
        if (newChildMode != _group.childGroupMode) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Linked Group Mode");
            _group.childGroupMode = newChildMode;
        }

        if (_group.childGroupMode != MasterAudioGroup.ChildGroupMode.None) {
            if (_group.childSoundGroups.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You have no other Groups set up to trigger.");
                EditorGUILayout.Separator();
            }

            EditorGUI.indentLevel = 1;
            for (var i = 0; i < _group.childSoundGroups.Count; i++) {
                var aGroup = _group.childSoundGroups[i];
                if (maInScene) {
                    var existingIndex = groupNames.IndexOf(aGroup);

                    int? groupIndex = null;

                    EditorGUI.indentLevel = 1;

                    var noGroup = false;
                    var noMatch = false;

                    if (existingIndex >= 1) {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray());
                        if (existingIndex == 1) {
                            noGroup = true;
                        }
                    } else if (existingIndex == -1 && aGroup == MasterAudio.NO_GROUP_NAME) {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray());
                    } else { // non-match
                        noMatch = true;
                        var newSound = EditorGUILayout.TextField("Sound Group", aGroup);
                        if (newSound != aGroup) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                            _group.childSoundGroups[i] = newSound;
                        }

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

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

                    if (groupIndex.HasValue) {
                        if (existingIndex != groupIndex.Value) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                        }
                        if (groupIndex.Value == -1) {
                            _group.childSoundGroups[i] = MasterAudio.NO_GROUP_NAME;
                        } else {
                            _group.childSoundGroups[i] = groupNames[groupIndex.Value];
                        }
                    }
                } else {
                    var newSType = EditorGUILayout.TextField("Sound Group", aGroup);
                    if (newSType != aGroup) {
                        UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                        _group.childSoundGroups[i] = newSType;
                    }
                }
            }

            GUI.contentColor = Color.green;
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Add Trigger Group"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                _group.childSoundGroups.Add(string.Empty);
            }
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Delete Trigger Group", "Delete the last Trigger Group"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                _group.childSoundGroups.RemoveAt(_group.childSoundGroups.Count - 1);
            }
            EditorGUILayout.EndHorizontal();
            GUI.contentColor = Color.white;
        }

        var newTargetGone = (MasterAudioGroup.TargetDespawnedBehavior) EditorGUILayout.EnumPopup("Caller Despawned Mode", _group.targetDespawnedBehavior);
        if (newTargetGone != _group.targetDespawnedBehavior) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "Change Caller Despawned Mode");
            _group.targetDespawnedBehavior = newTargetGone;
        }

        if (_group.targetDespawnedBehavior == MasterAudioGroup.TargetDespawnedBehavior.FadeOut) {
            EditorGUI.indentLevel = 1;
            var newFade = EditorGUILayout.Slider("Fade Out Time", _group.despawnFadeTime, .1f, 20f);
            if (newFade != _group.despawnFadeTime) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "Change Called Despawned Fade Out Time");
                _group.despawnFadeTime = newFade;
            }
        }

        EditorGUI.indentLevel = 0;

        var newBulkMode = (MasterAudio.AudioLocation) EditorGUILayout.EnumPopup("Variation Create Mode", _group.bulkVariationMode);
        if (newBulkMode != _group.bulkVariationMode) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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 groupHasResource = false;
        for (var s = 0; s < _group.groupVariations.Count; s++) {
            if (_group.groupVariations[s].audLocation == MasterAudio.AudioLocation.ResourceFile) {
                groupHasResource = true;
                break;
            }
        }

        if (MasterAudio.HasAsyncResourceLoaderFeature() && groupHasResource) {
            if ((maInScene && !ma.resourceClipsAllLoadAsync) || !maInScene) {
                var newAsync = EditorGUILayout.Toggle(new GUIContent("Load Resources Async", "Checking this means Resource files in this Sound Group will be loaded asynchronously."), _group.resourceClipsAllLoadAsync);
                if (newAsync != _group.resourceClipsAllLoadAsync) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Load Resources Async");
                    _group.resourceClipsAllLoadAsync = newAsync;
                }
            }
        }

        var newLog = EditorGUILayout.Toggle("Log Sounds", _group.logSound);
        if (newLog != _group.logSound) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Log Sounds");
            _group.logSound = newLog;
        }

        int? deadChildIndex = null;

        if (!Application.isPlaying) {
            EditorGUILayout.BeginHorizontal();
            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();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Localization", EditorStyles.wordWrappedLabel, GUILayout.Width(100f));
            GUILayout.Space(46);
            GUI.contentColor = Color.green;
            if (GUILayout.Button(new GUIContent("All Use Localization", "Check the 'Use Localized Folder' checkbox for all Variations."), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                isDirty = true;
                BulkUseLocalization(_group.groupVariations, true);
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("None Use Localiation", "Uncheck the 'Use Localized Folder' checkbox for all Variations."), EditorStyles.toolbarButton, GUILayout.Width(150))) {
                isDirty = true;
                BulkUseLocalization(_group.groupVariations, false);
            }

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

        if (!Application.isPlaying) {
            // bulk copy settings
            EditorGUI.indentLevel = 0;
            GUI.color = _group.copySettingsExpanded ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr;
            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);

            var newBulk = EditorGUILayout.Toggle("Show Copy Settings", _group.copySettingsExpanded);
            if (newBulk != _group.copySettingsExpanded) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Show Copy Settings");
                _group.copySettingsExpanded = newBulk;
            }
            EditorGUILayout.EndHorizontal();
            GUI.color = Color.white;

            if (_group.copySettingsExpanded) {
                if (_group.groupVariations.Count == 0) {
                    DTGUIHelper.ShowLargeBarAlert("You currently have no Variations in this Group.");
                } else if (_group.groupVariations.Count == 1) {
                    DTGUIHelper.ShowLargeBarAlert("You only have a single Variation in this Group. No point to copy.");
                } else {
                    var varNames = new List<string>(_group.groupVariations.Count);
                    for (var i = 0; i < _group.groupVariations.Count; i++) {
                        varNames.Add(_group.groupVariations[i].name);
                    }

                    if (_group.selectedVariationIndex >= varNames.Count) {
                        _group.selectedVariationIndex = 0;
                    }

                    var newVar = EditorGUILayout.Popup("Source Variation", _group.selectedVariationIndex, varNames.ToArray());
                    if (newVar != _group.selectedVariationIndex) {
                        UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Source Variation");
                        _group.selectedVariationIndex = newVar;
                    }

                    DTGUIHelper.ShowColorWarning("*Click a setting below to copy from Source Variation to all Variations in this Group.");

                    var sourceVar = _group.groupVariations[_group.selectedVariationIndex];

                    GUI.contentColor = Color.green;
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    if (GUILayout.Button("Volume", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyVolumes(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Pitch", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyPitches(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Loop", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyLoops(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("FX Tail Time", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyFxTail(sourceVar);
                        isDirty = true;
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Pitch", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyRandomPitch(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Volume", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyRandomVolume(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Delay", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyRandomDelay(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Custom Fade", EditorStyles.toolbarButton, GUILayout.Width(90))) {
                        CopyCustomFade(sourceVar);
                        isDirty = true;
                    }

                    EditorGUILayout.EndHorizontal();

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

            // 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 varIsDirty = false;

                var buttonPressed = DTGUIHelper.AddDynamicGroupButtons(_group);
                switch (buttonPressed) {
                    case DTGUIHelper.DTFunctionButtons.Play:
                        var calcVolume = variation.VarAudio.volume * _group.groupMasterVolume;

                        if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                            _creator.PreviewerInstance.Stop();
                            var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(_creator, variation.useLocalization, variation.resourceFileName);
                            var clip = Resources.Load(fileName) as AudioClip;
                            if (clip != null) {
                                _creator.PreviewerInstance.PlayOneShot(clip, calcVolume);
                            } else {
                                DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName);
                            }
                        } else {
                            variation.VarAudio.PlayOneShot(variation.VarAudio.clip, calcVolume);
                        }
                        isDirty = true;
                        break;
                    case DTGUIHelper.DTFunctionButtons.Stop:
                        if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                            _creator.PreviewerInstance.Stop();
                        } else {
                            variation.VarAudio.Stop();
                        }
                        isDirty = true;
                        break;
                }

                EditorGUILayout.EndHorizontal();

                if (!Application.isPlaying) {
                    DTGUIHelper.ShowColorWarning(MasterAudio.PREVIEW_TEXT);
                }
                if (variation.VarAudio == 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(ref varIsDirty, variation, "change Audio Origin");
                    variation.audLocation = newLocation;
                }

                switch (variation.audLocation) {
                    case MasterAudio.AudioLocation.Clip:
                        var newClip = (AudioClip) EditorGUILayout.ObjectField("Audio Clip", variation.VarAudio.clip, typeof(AudioClip), false);
                        if (newClip != variation.VarAudio.clip) {
                            UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "change Audio Clip");
                            variation.VarAudio.clip = newClip;
                        }
                        break;
                    case MasterAudio.AudioLocation.ResourceFile:
                        if (oldLocation != variation.audLocation) {
                            if (variation.VarAudio.clip != null) {
                                Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation.");
                            }
                            variation.VarAudio.clip = null;
                            varIsDirty = true;
                        }

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

                                    var useLocalization = false;
                                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Resource Filename");

                                    var newsFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization);

                                    variation.resourceFileName = newsFilename;
                                    variation.useLocalization = useLocalization;
                                }
                            }
                            Event.current.Use();
                            break;
                        }
                        EditorGUILayout.EndVertical();

                        var newFilename = EditorGUILayout.TextField("Resource Filename", variation.resourceFileName);
                        if (newFilename != variation.resourceFileName) {
                            UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Resource Filename");
                            variation.resourceFileName = newFilename;
                        }

                        EditorGUI.indentLevel = 1;

                        var newLocal = EditorGUILayout.Toggle("Use Localized Folder", variation.useLocalization);
                        if (newLocal != variation.useLocalization) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, variation, "toggle Use Localized Folder");
                            variation.useLocalization = newLocal;
                        }

                        break;
                }

                EditorGUI.indentLevel = 0;

                var newVolume = EditorGUILayout.Slider("Volume", variation.VarAudio.volume, 0f, 1f);
                if (newVolume != variation.VarAudio.volume) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "change Volume");
                    variation.VarAudio.volume = newVolume;
                }

                var newPitch = EditorGUILayout.Slider("Pitch", variation.VarAudio.pitch, -3f, 3f);
                if (newPitch != variation.VarAudio.pitch) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "change Pitch");
                    variation.VarAudio.pitch = newPitch;
                }

                var newLoop = EditorGUILayout.Toggle("Loop Clip", variation.VarAudio.loop);
                if (newLoop != variation.VarAudio.loop) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "toggle Loop Clip");
                    variation.VarAudio.loop = newLoop;
                }

                var newWeight = EditorGUILayout.IntSlider("Weight (Instances)", variation.weight, 0, 100);
                if (newWeight != variation.weight) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Weight");
                    variation.weight = newWeight;
                }

                var newFxTailTime = EditorGUILayout.Slider("FX Tail Time", variation.fxTailTime, 0f, 10f);
                if (newFxTailTime != variation.fxTailTime) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change FX Tail Time");
                    variation.fxTailTime = newFxTailTime;
                }

                var newUseRndPitch = EditorGUILayout.BeginToggleGroup("Use Random Pitch", variation.useRandomPitch);
                if (newUseRndPitch != variation.useRandomPitch) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "toggle Use Random Pitch");
                    variation.useRandomPitch = newUseRndPitch;
                }

                if (variation.useRandomPitch) {
                    var newMode = (SoundGroupVariation.RandomPitchMode) EditorGUILayout.EnumPopup("Pitch Compute Mode", variation.randomPitchMode);
                    if (newMode != variation.randomPitchMode) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Pitch Compute Mode");
                        variation.randomPitchMode = newMode;
                    }

                    var newPitchMin = EditorGUILayout.Slider("Random Pitch Min", variation.randomPitchMin, -3f, 3f);
                    if (newPitchMin != variation.randomPitchMin) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Random Pitch Min");
                        variation.randomPitchMin = newPitchMin;
                        if (variation.randomPitchMax <= variation.randomPitchMin) {
                            variation.randomPitchMax = variation.randomPitchMin;
                        }
                    }

                    var newPitchMax = EditorGUILayout.Slider("Random Pitch Max", variation.randomPitchMax, -3f, 3f);
                    if (newPitchMax != variation.randomPitchMax) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Random Pitch Max");
                        variation.randomPitchMax = newPitchMax;
                        if (variation.randomPitchMin > variation.randomPitchMax) {
                            variation.randomPitchMin = variation.randomPitchMax;
                        }
                    }
                }

                EditorGUILayout.EndToggleGroup();

                var newUseRndVol = EditorGUILayout.BeginToggleGroup("Use Random Volume", variation.useRandomVolume);
                if (newUseRndVol != variation.useRandomVolume) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "toggle Use Random Volume");
                    variation.useRandomVolume = newUseRndVol;
                }

                if (variation.useRandomVolume) {
                    var newMode = (SoundGroupVariation.RandomVolumeMode) EditorGUILayout.EnumPopup("Volume Compute Mode", variation.randomVolumeMode);
                    if (newMode != variation.randomVolumeMode) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Volume Compute Mode");
                        variation.randomVolumeMode = newMode;
                    }

                    var volMin = 0f;
                    if (variation.randomVolumeMode == SoundGroupVariation.RandomVolumeMode.AddToClipVolume) {
                        volMin = -1f;
                    }

                    var newVolMin = EditorGUILayout.Slider("Random Volume Min", variation.randomVolumeMin, volMin, 1f);
                    if (newVolMin != variation.randomVolumeMin) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Random Volume Min");
                        variation.randomVolumeMin = newVolMin;
                        if (variation.randomVolumeMax <= variation.randomVolumeMin) {
                            variation.randomVolumeMax = variation.randomVolumeMin;
                        }
                    }

                    var newVolMax = EditorGUILayout.Slider("Random Volume Max", variation.randomVolumeMax, volMin, 1f);
                    if (newVolMax != variation.randomVolumeMax) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Random Volume Max");
                        variation.randomVolumeMax = newVolMax;
                        if (variation.randomVolumeMin > variation.randomVolumeMax) {
                            variation.randomVolumeMin = variation.randomVolumeMax;
                        }
                    }
                }

                EditorGUILayout.EndToggleGroup();

                var newSilence = EditorGUILayout.BeginToggleGroup("Use Random Delay", variation.useIntroSilence);
                if (newSilence != variation.useIntroSilence) {
                    UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "toggle Use Random Delay");
                    variation.useIntroSilence = newSilence;
                }

                if (variation.useIntroSilence) {
                    var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", variation.introSilenceMin, 0f, 100f);
                    if (newSilenceMin != variation.introSilenceMin) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Delay Min (sec)");
                        variation.introSilenceMin = newSilenceMin;
                        if (variation.introSilenceMin > variation.introSilenceMax) {
                            variation.introSilenceMax = newSilenceMin;
                        }
                    }

                    var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", variation.introSilenceMax, 0f, 100f);
                    if (newSilenceMax != variation.introSilenceMax) {
                        UndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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(ref varIsDirty, 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(ref varIsDirty, 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(ref varIsDirty, variation, "change Fade Out Time");
                        variation.fadeOutTime = newFadeOut;
                    }
                }
                EditorGUILayout.EndToggleGroup();

                EditorGUILayout.Separator();

                if (varIsDirty)
                {
                    EditorUtility.SetDirty(variation.VarAudio);
                    EditorUtility.SetDirty(variation);
                }
            }
        }

        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();
    }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 1;
        var isDirty = false;

        _creator = (DynamicSoundGroupCreator)target;

        if (_creator.logoTexture != null) {
            GUIHelper.ShowHeaderTexture(_creator.logoTexture);
        }

        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) {
            GUIHelper.ShowColorWarning("*Items will be created as soon as this object is in the Scene.");
        } else {
            GUIHelper.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) {
            GUIHelper.ShowColorWarning("*Items will be deleted when the Scene changes.");
        } else {
            GUIHelper.ShowColorWarning("*Items will persist across Scenes if MasterAudio does.");
        }

        EditorGUILayout.Separator();

        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;

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

                    DynamicSoundGroupInfo 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

        GUI.color = _creator.soundGroupsAreExpanded ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr;

        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        var newGroupEx = EditorGUILayout.Toggle("Dynamic Sound Groups", _creator.soundGroupsAreExpanded);
        if (newGroupEx != _creator.soundGroupsAreExpanded) {
            UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Dynamic Sound Groups");
            _creator.soundGroupsAreExpanded = newGroupEx;
        }

        if (_creator.soundGroupsAreExpanded) {
            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));
            GUIContent content;
            var collapseIcon = '\u2261'.ToString();
            content = new GUIContent(collapseIcon, "Click to collapse all");
            var masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton);

            var expandIcon = '\u25A1'.ToString();
            content = new GUIContent(expandIcon, "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton);
            if (masterExpand) {
                ExpandCollapseAllSoundGroups(true);
            }
            if (masterCollapse) {
                ExpandCollapseAllSoundGroups(false);
            }
            EditorGUILayout.EndHorizontal();
        }
        GUI.color = Color.white;

        EditorGUILayout.EndHorizontal();

        DynamicSoundGroupVariation aVar;

        if (_creator.soundGroupsAreExpanded) {
            int? addGroupIndex = null;
            int? removeGroupIndex = null;
            int? addVariationIndex = null;
            int? removeVariationIndex = null;
            int? variationIndextoShiftUp = null;
            int? variationIndextoShiftDown = null;

            for (var i = 0; i < _creator.soundGroupsToCreate.Count; i++) {
                EditorGUILayout.Separator();
                var aGroup = _creator.soundGroupsToCreate[i];

                EditorGUI.indentLevel = 1;  // Space will handle this for the header
                EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);

                var newGroupExpanded = GUIHelper.Foldout(aGroup.isExpanded, "GROUP: " + aGroup.groupName);
                if (newGroupExpanded != aGroup.isExpanded) {
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Group");
                    aGroup.isExpanded = newGroupExpanded;
                }

                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));

                var groupButtonPressed = GUIHelper.AddFoldOutListItemButtons(i, _creator.soundGroupsToCreate.Count, "Sound Group", false, false);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndHorizontal();

                if (aGroup.isExpanded) {
                    EditorGUI.indentLevel = 0;  // Space will handle this for the header
                    var newGroupSettingsEx = EditorGUILayout.Toggle("Show Group Settings", aGroup.groupSettingsExpanded);
                    if (newGroupSettingsEx != aGroup.groupSettingsExpanded) {
                        UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Show Group Settings");
                        aGroup.groupSettingsExpanded = newGroupSettingsEx;
                    }
                    if (aGroup.groupSettingsExpanded) {
                        var newGroupName = EditorGUILayout.TextField("Group Name", aGroup.groupName);
                        if (newGroupName != aGroup.groupName) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Group Name");
                            aGroup.groupName = newGroupName;
                        }

                        var newGroupVol = EditorGUILayout.Slider("Group Master Volume", aGroup.groupMasterVolume, 0f, 1f);
                        if (newGroupVol != aGroup.groupMasterVolume) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Group Master Volume");
                            aGroup.groupMasterVolume = newGroupVol;
                        }

                        var newTrigger = EditorGUILayout.IntSlider("Retrigger Percentage", aGroup.retriggerPercentage, 0, 100);
                        if (newTrigger != aGroup.retriggerPercentage) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "Retrigger Percentage");
                            aGroup.retriggerPercentage = newTrigger;
                        }

                        var newVariationSeq = (MasterAudioGroup.VariationSequence) EditorGUILayout.EnumPopup("Variation Sequence", aGroup.curVariationSequence);
                        if (newVariationSeq != aGroup.curVariationSequence) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "Variation Sequence");
                            aGroup.curVariationSequence = newVariationSeq;
                        }

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

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

                            EditorGUILayout.EndToggleGroup();
                        }

                        EditorGUI.indentLevel = 0;

                        var newVarMode = (MasterAudioGroup.VariationMode) EditorGUILayout.EnumPopup("Variation Mode", aGroup.curVariationMode);
                        if (newVarMode != aGroup.curVariationMode) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Variation Mode");
                            aGroup.curVariationMode = newVarMode;
                        }

                        var newDuck = EditorGUILayout.Toggle("Duck Music?", aGroup.duckSound);
                        if (newDuck != aGroup.duckSound) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Duck Music");
                            aGroup.duckSound = newDuck;
                        }

                        if (aGroup.duckSound) {
                            var newRiseStart = EditorGUILayout.Slider("Begin Unduck", aGroup.riseVolStart, 0f, 1f);
                            if (newRiseStart != aGroup.riseVolStart) {
                                UndoHelper.RecordObjectPropertyForUndo(_creator, "change Begin Unduck");
                                aGroup.riseVolStart = newRiseStart;
                            }
                        }

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

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

                        var newLimitMode = (MasterAudioGroup.LimitMode) EditorGUILayout.EnumPopup("Replay Limit Mode", aGroup.limitMode);
                        if (newLimitMode != aGroup.limitMode) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Replay Limit Mode");
                            aGroup.limitMode = newLimitMode;
                        }
                        switch (aGroup.limitMode) {
                            case MasterAudioGroup.LimitMode.FrameBased:
                                var newFrameLimit = EditorGUILayout.IntSlider("Min Frames Between", aGroup.limitPerXFrames, 1, 120);
                                if (newFrameLimit != aGroup.limitPerXFrames) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Min Frames Between");
                                    aGroup.limitPerXFrames = newFrameLimit;
                                }
                                break;
                            case MasterAudioGroup.LimitMode.TimeBased:
                                var newTimeLimit = EditorGUILayout.Slider("Min Seconds Between", aGroup.minimumTimeBetween, 0.1f, 10f);
                                if (newTimeLimit != aGroup.minimumTimeBetween) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Min Seconds Between");
                                    aGroup.minimumTimeBetween = newTimeLimit;
                                }
                                break;
                        }

                        var newBusMode = (DynamicSoundGroupInfo.BusMode) EditorGUILayout.EnumPopup("Bus Mode", aGroup.busMode);
                        if (newBusMode != aGroup.busMode) {
                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bus Mode");
                            aGroup.busMode = newBusMode;
                        }
                        if (aGroup.busMode != DynamicSoundGroupInfo.BusMode.NoBus) {
                            var newBusName = EditorGUILayout.TextField("Bus Name", aGroup.busName);
                            if (newBusName != aGroup.busName) {
                                UndoHelper.RecordObjectPropertyForUndo(_creator, "change Bus Name");
                                aGroup.busName = newBusName;
                            }
                            GUIHelper.ShowColorWarning("*Bus will be created if it does not exist.");
                        }

                        EditorGUILayout.BeginHorizontal();
                        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 zero"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                            isDirty = true;
                            EqualizeWeights(aGroup);
                        }

                        GUILayout.Space(8);
                        GUI.contentColor = Color.green;
                        if (GUILayout.Button(new GUIContent("Alpha Sort Variations", "Sort Variations by name"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                            isDirty = true;
                            AlphaSortVariations(aGroup);
                        }

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

                    // create variations start
                    EditorGUILayout.BeginVertical();
                    var anEvent = Event.current;

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

                                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 j = 0; j < clips.Count; j++) {
                                    var aClip = clips[j];

                                    CreateVariation(aGroup, aClip);
                                    isDirty = true;

                                }
                            }
                            Event.current.Use();
                            break;
                    }
                    EditorGUILayout.EndVertical();
                    // create variations end

                    if (aGroup.variations.Count == 0) {
                        GUIHelper.ShowRedError("This Group has zero variations.");
                    } else {
                        for (var v = 0; v < aGroup.variations.Count; v++) {
                            EditorGUI.indentLevel = 2;  // Space will handle this for the header
                            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

                            aVar = aGroup.variations[v];
                            var newExpanded = GUIHelper.Foldout(aVar.isExpanded, aVar.clipName);
                            if (newExpanded != aVar.isExpanded) {
                                UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Variation");
                                aVar.isExpanded = newExpanded;
                            }

                            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));

                            var variationButtonPressed = GUIHelper.AddFoldOutListItemButtons(v, aGroup.variations.Count, "variation", false, true, true);
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndHorizontal();
                            if (aVar.isExpanded) {
                                EditorGUI.indentLevel = 0;  // Space will handle this for the header

                                var oldLocation = aVar.audLocation;
                                var newLocation = (MasterAudio.AudioLocation) EditorGUILayout.EnumPopup("Audio Origin", aVar.audLocation);
                                if (newLocation != aVar.audLocation) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Audio Origin");
                                    aVar.audLocation = newLocation;
                                }

                                switch (aVar.audLocation) {
                                    case MasterAudio.AudioLocation.Clip:
                                        var newClip = (AudioClip) EditorGUILayout.ObjectField("Audio Clip", aVar.clip, typeof(AudioClip), false);
                                        if (newClip != aVar.clip) {
                                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Audio Clip");
                                            aVar.clip = newClip;
                                        }
                                        break;
                                    case MasterAudio.AudioLocation.ResourceFile:
                                        if (oldLocation != aVar.audLocation) {
                                            if (aVar.clip != null) {
                                                Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file variation.");
                                            }
                                            aVar.clip = null;
                                        }

                                        EditorGUILayout.BeginVertical();
                                        var myEvent = Event.current;

                                        GUI.color = Color.yellow;
                                        var myDragArea = GUILayoutUtility.GetRect(0f, 20f,GUILayout.ExpandWidth(true));
                                        GUI.Box (myDragArea, "Drag Resource Audio clip here to use its name!");
                                        GUI.color = Color.white;

                                        switch (myEvent.type) {
                                            case EventType.DragUpdated:
                                            case EventType.DragPerform:
                                                if(!myDragArea.Contains(myEvent.mousePosition)) {
                                                    break;
                                                }

                                                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                                                if(myEvent.type == EventType.DragPerform) {
                                                    DragAndDrop.AcceptDrag();

                                                    foreach (var dragged in DragAndDrop.objectReferences) {
                                                        var aClip = dragged as AudioClip;
                                                        if(aClip == null) {
                                                            continue;
                                                        }

                                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Resource Filename");
                                                        aVar.resourceFileName = GUIHelper.GetResourcePath(aClip);
                                                    }
                                                }
                                                Event.current.Use();
                                                break;
                                        }
                                        EditorGUILayout.EndVertical();

                                        aVar.resourceFileName = EditorGUILayout.TextField("Resource Filename", aVar.resourceFileName);
                                        break;
                                }

                                var newVol = EditorGUILayout.Slider("Volume", aVar.volume, 0f, 1f);
                                if (newVol != aVar.volume) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Volume");
                                    aVar.volume = newVol;
                                }

                                var newPitch = EditorGUILayout.Slider("Pitch", aVar.pitch, -3f, 3f);
                                if (newPitch != aVar.pitch) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Pitch");
                                    aVar.pitch = newPitch;
                                }

                                var newClipName = EditorGUILayout.TextField("Variation Name", aVar.clipName);
                                if (newClipName != aVar.clipName) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Variation Name");
                                    aVar.clipName = newClipName;
                                }

                                var newLoop = EditorGUILayout.Toggle("Loop Clip", aVar.loopClip);
                                if (newLoop != aVar.loopClip) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Loop Clip");
                                    aVar.loopClip = newLoop;
                                }

                                var newRandPitch = EditorGUILayout.Slider("Random Pitch", aVar.randomPitch, 0f, 3f);
                                if (newRandPitch != aVar.randomPitch) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Random Pitch");
                                    aVar.randomPitch = newRandPitch;
                                }

                                var newRandVol = EditorGUILayout.Slider("Random Volume", aVar.randomVolume, 0f, 1f);
                                if (newRandVol != aVar.randomVolume) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Random Volume");
                                    aVar.randomVolume = newRandVol;
                                }

                                var newWeight = EditorGUILayout.IntSlider("Weight (Instances)", aVar.weight, 0, 100);
                                if (newWeight != aVar.weight) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "change Weight");
                                    aVar.weight = newWeight;
                                }

                                var newUseFade = EditorGUILayout.Toggle("Use Custom Fading?", aVar.useFades);
                                if (newUseFade != aVar.useFades) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Use Custom Fading");
                                    aVar.useFades = newUseFade;
                                }
                                if (aVar.useFades) {
                                    EditorGUI.indentLevel = 1;  // Space will handle this for the header
                                    var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", aVar.fadeInTime, 0f, 10f);
                                    if (newFadeIn != aVar.fadeInTime) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Fade In Time");
                                        aVar.fadeInTime = newFadeIn;
                                    }

                                    if (aVar.loopClip) {
                                        GUIHelper.ShowColorWarning("*Looped clips cannot have a custom fade out.");
                                    } else {
                                        var newFadeOut = EditorGUILayout.Slider("Fade Out Time (sec)", aVar.fadeOutTime, 0f, 10f);
                                        if (newFadeOut != aVar.fadeOutTime) {
                                            UndoHelper.RecordObjectPropertyForUndo(_creator, "change Fade Out Time");
                                            aVar.fadeOutTime = newFadeOut;
                                        }
                                    }
                                }

                                EditorGUI.indentLevel = 0;  // Space will handle this for the header

                                var newShow3D = EditorGUILayout.Toggle("Use 3D Settings?", aVar.showAudio3DSettings);
                                if (newShow3D != aVar.showAudio3DSettings) {
                                    UndoHelper.RecordObjectPropertyForUndo(_creator, "toggle Use 3D Settings");
                                    aVar.showAudio3DSettings = newShow3D;
                                }
                                if (aVar.showAudio3DSettings) {
                                    EditorGUI.indentLevel = 1;  // Space will handle this for the header

                                    var newDoppler = EditorGUILayout.Slider("Doppler Level", aVar.audDopplerLevel, 0f, 5f);
                                    if (newDoppler != aVar.audDopplerLevel) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Doppler Level");
                                        aVar.audDopplerLevel = newDoppler;
                                    }

                                    var newRolloffMode = (AudioRolloffMode) EditorGUILayout.EnumPopup("Volume Rolloff", aVar.audRollOffMode);
                                    if (newRolloffMode != aVar.audRollOffMode) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Volume Rolloff");
                                        aVar.audRollOffMode = newRolloffMode;
                                    }

                                    var newPan = EditorGUILayout.Slider("Pan Level", aVar.audPanLevel, 0f, 1f);
                                    if (newPan != aVar.audPanLevel) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Pan Level");
                                        aVar.audPanLevel = newPan;
                                    }

                                    var newMinDist = EditorGUILayout.FloatField("Min Distance", aVar.audMinDistance);
                                    if (newMinDist != aVar.audMinDistance) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Min Distance");
                                        aVar.audMinDistance = newMinDist;
                                    }

                                    var newSpread = EditorGUILayout.Slider("Spread", aVar.audSpread, 0f, 360f);
                                    if (newSpread != aVar.audSpread) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Spread");
                                        aVar.audSpread = newSpread;
                                    }

                                    var newMaxDist = EditorGUILayout.FloatField("Max Distance", aVar.audMaxDistance);
                                    if (newMaxDist != aVar.audMaxDistance) {
                                        UndoHelper.RecordObjectPropertyForUndo(_creator, "change Max Distance");
                                        aVar.audMaxDistance = newMaxDist;
                                    }

                                    if (_creator.audio == null) {
                                        GUIHelper.ShowRedError("You have no Audio Source in this prefab. Please delete prefab.");
                                        GUIHelper.ShowRedError("Then add a new Dyanmic SGC from the Audio Manager window.");
                                    } else {
                                        EditorGUILayout.BeginHorizontal();
                                        //GUILayout.Label("Actions", EditorStyles.wordWrappedLabel, GUILayout.Width(50f));
                                        GUILayout.Space(15);
                                        GUI.contentColor = Color.green;
                                        if (GUILayout.Button(new GUIContent("Copy 3D to Audio Source", "Copy the 3D settings to the Audio Source in this prefab for using the Unity widgets."), EditorStyles.toolbarButton, GUILayout.Width(160))) {
                                            isDirty = true;
                                            Copy3DSettingsToAudioSource(_creator.audio, aVar);
                                        }

                                        GUILayout.Space(10);

                                        if (GUILayout.Button(new GUIContent("Copy 3D from Audio Source", "Copy the 3D settings from the Audio Source in this prefab back into this section."), EditorStyles.toolbarButton, GUILayout.Width(160))) {
                                            isDirty = true;
                                            Copy3DSettingsFromAudioSource(_creator.audio, aVar);
                                        }
                                        GUI.contentColor = Color.white;
                                        EditorGUILayout.EndHorizontal();
                                    }
                                }
                            }

                            switch (variationButtonPressed) {
                                case GUIHelper.DTFunctionButtons.Add:
                                    addVariationIndex = v;
                                    break;
                                case GUIHelper.DTFunctionButtons.Remove:
                                    removeVariationIndex = v;
                                    break;
                                case GUIHelper.DTFunctionButtons.ShiftUp:
                                    variationIndextoShiftUp = v;
                                    break;
                                case GUIHelper.DTFunctionButtons.ShiftDown:
                                    variationIndextoShiftDown = v;
                                    break;
                                case GUIHelper.DTFunctionButtons.Play:
                                    _creator.audio.Stop();

                                    if (aVar.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                                        _creator.audio.PlayOneShot(Resources.Load(aVar.resourceFileName) as AudioClip, aVar.volume);
                                    } else {
                                        _creator.audio.PlayOneShot(aVar.clip, aVar.volume);
                                    }
                                    break;
                                case GUIHelper.DTFunctionButtons.Stop:
                                    _creator.audio.Stop();
                                    break;
                            }
                        }
                    }
                }

                if (addVariationIndex.HasValue) {
                    var newVar = new DynamicSoundGroupVariation();
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "add Variation");
                    aGroup.variations.Insert(addVariationIndex.Value + 1, newVar);
                } else if (removeVariationIndex.HasValue) {
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "remove Variation");
                    aGroup.variations.RemoveAt(removeVariationIndex.Value);
                } else if (variationIndextoShiftUp.HasValue) {
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "shift Variation Up");
                    var item = aGroup.variations[variationIndextoShiftUp.Value];
                    aGroup.variations.Insert(variationIndextoShiftUp.Value - 1, item);
                    aGroup.variations.RemoveAt(variationIndextoShiftUp.Value + 1);
                } else if (variationIndextoShiftDown.HasValue) {
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "shift Variation Down");

                    var index = variationIndextoShiftDown.Value + 1;

                    var item = aGroup.variations[index];
                    aGroup.variations.Insert(index - 1, item);
                    aGroup.variations.RemoveAt(index + 1);
                }

                switch (groupButtonPressed) {
                    case GUIHelper.DTFunctionButtons.Add:
                        addGroupIndex = i;
                        break;
                    case GUIHelper.DTFunctionButtons.Remove:
                        removeGroupIndex = i;
                        break;
                }

                EditorGUILayout.Separator();
            }

            if (addGroupIndex.HasValue) {
                var newGroup = new DynamicSoundGroupInfo();
                UndoHelper.RecordObjectPropertyForUndo(_creator, "add Group");
                _creator.soundGroupsToCreate.Insert(addGroupIndex.Value + 1, newGroup);
            } else if (removeGroupIndex.HasValue) {
                if (_creator.soundGroupsToCreate.Count <= 1) {
                    GUIHelper.ShowAlert("You cannot delete the last new Sound Group. You can delete the prefab if you don't need any.");
                } else {
                    UndoHelper.RecordObjectPropertyForUndo(_creator, "remove Group");
                    _creator.soundGroupsToCreate.RemoveAt(removeGroupIndex.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) {
                GUIHelper.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 = GUIHelper.AddCustomEventDeleteIcon(true);

                switch (buttonPressed) {
                    case GUIHelper.DTFunctionButtons.Remove:
                        indexToDelete = i;
                        break;
                    case GUIHelper.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();
    }
コード例 #7
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 1;
        var isDirty = false;

        _variation = (DynamicGroupVariation)target;

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

        EditorGUI.indentLevel = 0;  // Space will handle this for the header

        if (_variation.transform.parent != null && _variation.transform.parent.parent != null) {
            _creator = _variation.transform.parent.parent.GetComponent<DynamicSoundGroupCreator>();
        }

        if (_creator == null) {
            DTGUIHelper.ShowRedError("This prefab must have DynamicSoundGroupCreator 2 parents up.");
            return;
        }

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

        var buttonPressed = DTGUIHelper.AddDynamicVariationButtons();

        switch (buttonPressed) {
            case DTGUIHelper.DTFunctionButtons.Play:
                isDirty = true;
                var calcVolume = _variation.VarAudio.volume * _variation.ParentGroup.groupMasterVolume;

                if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                    _creator.PreviewerInstance.Stop();
                    var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(_creator, _variation.useLocalization, _variation.resourceFileName);

                    var clip = Resources.Load(fileName) as AudioClip;
                    if (clip != null) {
                        _creator.PreviewerInstance.PlayOneShot(clip, calcVolume);
                    } else {
                        DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName);
                    }
                } else {
                    _variation.VarAudio.PlayOneShot(_variation.VarAudio.clip, calcVolume);
                }
                break;
            case DTGUIHelper.DTFunctionButtons.Stop:
                if (_variation.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                    _creator.PreviewerInstance.Stop();
                } else {
                    _variation.VarAudio.Stop();
                }
                break;
        }

        EditorGUILayout.EndHorizontal();

        if (!Application.isPlaying) {
            DTGUIHelper.ShowColorWarning(MasterAudio.PREVIEW_TEXT);
        }

        var oldLocation = _variation.audLocation;
        var newLocation = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", _variation.audLocation);

        if (newLocation != oldLocation) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Audio Origin");
            _variation.audLocation = newLocation;
        }

        switch (_variation.audLocation) {
            case MasterAudio.AudioLocation.Clip:
                var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", _variation.VarAudio.clip, typeof(AudioClip), false);

                if (newClip != _variation.VarAudio.clip) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "assign Audio Clip");
                    _variation.VarAudio.clip = newClip;
                }
                break;
            case MasterAudio.AudioLocation.ResourceFile:
                if (oldLocation != _variation.audLocation) {
                    if (_variation.VarAudio.clip != null) {
                        Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation.");
                    }
                    _variation.VarAudio.clip = null;
                }

                EditorGUILayout.BeginVertical();
                var anEvent = Event.current;

                GUI.color = Color.yellow;
                var dragArea = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true));
                GUI.Box(dragArea, "Drag Resource Audio clip here to use its name!");
                GUI.color = Color.white;

                var newFilename = string.Empty;

                switch (anEvent.type) {
                    case EventType.DragUpdated:
                    case EventType.DragPerform:
                        if (!dragArea.Contains(anEvent.mousePosition)) {
                            break;
                        }

                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                        if (anEvent.type == EventType.DragPerform) {
                            DragAndDrop.AcceptDrag();

                            foreach (var dragged in DragAndDrop.objectReferences) {
                                var aClip = dragged as AudioClip;
                                if (aClip == null) {
                                    continue;
                                }

                                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename");

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

                                _variation.resourceFileName = newFilename;
                                _variation.useLocalization = useLocalization;
                                break;
                            }
                        }
                        Event.current.Use();
                        break;
                }
                EditorGUILayout.EndVertical();

                newFilename = EditorGUILayout.TextField("Resource Filename", _variation.resourceFileName);
                if (newFilename != _variation.resourceFileName) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Resource filename");
                    _variation.resourceFileName = newFilename;
                }

                EditorGUI.indentLevel = 1;

                var newLocal = EditorGUILayout.Toggle("Use Localized Folder", _variation.useLocalization);
                if (newLocal != _variation.useLocalization) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Localized Folder");
                    _variation.useLocalization = newLocal;
                }

                break;
        }

        EditorGUI.indentLevel = 0;

        var newVolume = EditorGUILayout.Slider("Volume", _variation.VarAudio.volume, 0f, 1f);
        if (newVolume != _variation.VarAudio.volume) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Volume");
            _variation.VarAudio.volume = newVolume;
        }

        var newPitch = EditorGUILayout.Slider("Pitch", _variation.VarAudio.pitch, -3f, 3f);
        if (newPitch != _variation.VarAudio.pitch) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "change Pitch");
            _variation.VarAudio.pitch = newPitch;
        }

        var newLoop = EditorGUILayout.Toggle("Loop Clip", _variation.VarAudio.loop);
        if (newLoop != _variation.VarAudio.loop) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation.VarAudio, "toggle Loop");
            _variation.VarAudio.loop = newLoop;
        }

        var newWeight = EditorGUILayout.IntSlider("Weight (Instances)", _variation.weight, 0, 100);
        if (newWeight != _variation.weight) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Weight");
            _variation.weight = newWeight;
        }

        var newFxTailTime = EditorGUILayout.Slider("FX Tail Time", _variation.fxTailTime, 0f, 10f);
        if (newFxTailTime != _variation.fxTailTime) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change FX Tail Time");
            _variation.fxTailTime = newFxTailTime;
        }

        var newUseRndPitch = EditorGUILayout.BeginToggleGroup("Use Random Pitch", _variation.useRandomPitch);
        if (newUseRndPitch != _variation.useRandomPitch) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Pitch");
            _variation.useRandomPitch = newUseRndPitch;
        }

        if (_variation.useRandomPitch) {
            var newMode = (SoundGroupVariation.RandomPitchMode)EditorGUILayout.EnumPopup("Pitch Compute Mode", _variation.randomPitchMode);
            if (newMode != _variation.randomPitchMode) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Pitch Compute Mode");
                _variation.randomPitchMode = newMode;
            }

            var newPitchMin = EditorGUILayout.Slider("Random Pitch Min", _variation.randomPitchMin, -3f, 3f);
            if (newPitchMin != _variation.randomPitchMin) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Min");
                _variation.randomPitchMin = newPitchMin;
                if (_variation.randomPitchMax <= _variation.randomPitchMin) {
                    _variation.randomPitchMax = _variation.randomPitchMin;
                }
            }

            var newPitchMax = EditorGUILayout.Slider("Random Pitch Max", _variation.randomPitchMax, -3f, 3f);
            if (newPitchMax != _variation.randomPitchMax) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Pitch Max");
                _variation.randomPitchMax = newPitchMax;
                if (_variation.randomPitchMin > _variation.randomPitchMax) {
                    _variation.randomPitchMin = _variation.randomPitchMax;
                }
            }
        }

        EditorGUILayout.EndToggleGroup();

        var newUseRndVol = EditorGUILayout.BeginToggleGroup("Use Random Volume", _variation.useRandomVolume);
        if (newUseRndVol != _variation.useRandomVolume) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Volume");
            _variation.useRandomVolume = newUseRndVol;
        }

        if (_variation.useRandomVolume) {
            var newMode = (SoundGroupVariation.RandomVolumeMode)EditorGUILayout.EnumPopup("Volume Compute Mode", _variation.randomVolumeMode);
            if (newMode != _variation.randomVolumeMode) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Volume Compute Mode");
                _variation.randomVolumeMode = newMode;
            }

            var volMin = 0f;
            if (_variation.randomVolumeMode == SoundGroupVariation.RandomVolumeMode.AddToClipVolume) {
                volMin = -1f;
            }

            var newVolMin = EditorGUILayout.Slider("Random Volume Min", _variation.randomVolumeMin, volMin, 1f);
            if (newVolMin != _variation.randomVolumeMin) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Min");
                _variation.randomVolumeMin = newVolMin;
                if (_variation.randomVolumeMax <= _variation.randomVolumeMin) {
                    _variation.randomVolumeMax = _variation.randomVolumeMin;
                }
            }

            var newVolMax = EditorGUILayout.Slider("Random Volume Max", _variation.randomVolumeMax, volMin, 1f);
            if (newVolMax != _variation.randomVolumeMax) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Random Volume Max");
                _variation.randomVolumeMax = newVolMax;
                if (_variation.randomVolumeMin > _variation.randomVolumeMax) {
                    _variation.randomVolumeMin = _variation.randomVolumeMax;
                }
            }
        }

        EditorGUILayout.EndToggleGroup();

        var newSilence = EditorGUILayout.BeginToggleGroup("Use Random Delay", _variation.useIntroSilence);
        if (newSilence != _variation.useIntroSilence) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Random Delay");
            _variation.useIntroSilence = newSilence;
        }

        if (_variation.useIntroSilence) {
            var newSilenceMin = EditorGUILayout.Slider("Delay Min (sec)", _variation.introSilenceMin, 0f, 100f);
            if (newSilenceMin != _variation.introSilenceMin) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Min (sec)");
                _variation.introSilenceMin = newSilenceMin;
                if (_variation.introSilenceMin > _variation.introSilenceMax) {
                    _variation.introSilenceMax = newSilenceMin;
                }
            }

            var newSilenceMax = EditorGUILayout.Slider("Delay Max (sec)", _variation.introSilenceMax, 0f, 100f);
            if (newSilenceMax != _variation.introSilenceMax) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Delay Max (sec)");
                _variation.introSilenceMax = newSilenceMax;
                if (_variation.introSilenceMax < _variation.introSilenceMin) {
                    _variation.introSilenceMin = newSilenceMax;
                }
            }
        }
        EditorGUILayout.EndToggleGroup();

        var newUseFades = EditorGUILayout.BeginToggleGroup("Use Custom Fading", _variation.useFades);
        if (newUseFades != _variation.useFades) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "toggle Use Custom Fading");
            _variation.useFades = newUseFades;
        }

        if (_variation.useFades) {
            var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", _variation.fadeInTime, 0f, 10f);
            if (newFadeIn != _variation.fadeInTime) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade In Time");
                _variation.fadeInTime = newFadeIn;
            }

            if (_variation.VarAudio.loop) {
                DTGUIHelper.ShowColorWarning("*Looped clips cannot have a custom fade out.");
            } else {
                var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", _variation.fadeOutTime, 0f, 10f);
                if (newFadeOut != _variation.fadeOutTime) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _variation, "change Fade Out Time");
                    _variation.fadeOutTime = newFadeOut;
                }
            }
        }

        EditorGUILayout.EndToggleGroup();

        var filterList = new List<string>() {
            MasterAudio.NO_GROUP_NAME,
            "Low Pass",
            "High Pass",
            "Distortion",
            "Chorus",
            "Echo",
            "Reverb"
        };

        var newFilterIndex = EditorGUILayout.Popup("Add Filter Effect", 0, filterList.ToArray());
        switch (newFilterIndex) {
            case 1:
                AddFilterComponent(typeof(AudioLowPassFilter));
                break;
            case 2:
                AddFilterComponent(typeof(AudioHighPassFilter));
                break;
            case 3:
                AddFilterComponent(typeof(AudioDistortionFilter));
                break;
            case 4:
                AddFilterComponent(typeof(AudioChorusFilter));
                break;
            case 5:
                AddFilterComponent(typeof(AudioEchoFilter));
                break;
            case 6:
                AddFilterComponent(typeof(AudioReverbFilter));
                break;
        }

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

        //DrawDefaultInspector();
    }
コード例 #8
0
    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();
    }
コード例 #9
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 1;
        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 maInScene = ma != null;

        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

        if (MasterAudio.Instance == null) {
            var newLang = (SystemLanguage) EditorGUILayout.EnumPopup(new GUIContent("Preview Language", "This setting is only used (and visible) to choose the previewing language when there's no Master Audio prefab in the Scene (language settings are grabbed from there normally). This should only happen when you're using a Master Audio prefab from a previous Scene in persistent mode."), _creator.previewLanguage);
            if (newLang != _creator.previewLanguage) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Preview Language");
                _creator.previewLanguage = newLang;
            }
        }

        EditorGUILayout.Separator();

        var newAwake = EditorGUILayout.Toggle("Auto-create Items", _creator.createOnAwake);
        if (newAwake != _creator.createOnAwake) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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.ShowLargeBarAlert("You will need to call this object's CreateItems method manually to create the items.");
        }

        var newRemove = EditorGUILayout.Toggle("Auto-remove Items", _creator.removeGroupsOnSceneChange);
        if (newRemove != _creator.removeGroupsOnSceneChange) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Auto-remove Items");
            _creator.removeGroupsOnSceneChange = newRemove;
        }

        if (_creator.removeGroupsOnSceneChange) {
            DTGUIHelper.ShowColorWarning("*Items will be deleted when the Scene changes.");
        } else {
            DTGUIHelper.ShowLargeBarAlert("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(ref isDirty, _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(ref isDirty, _creator, "Add Duck Group");

                var defaultBeginUnduck = 0.5f;
                if (maInScene) {
                    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.ShowLargeBarAlert("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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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(ref isDirty, _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 (_groups.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("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];

                var groupDirty = false;

                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(ref groupDirty, 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(ref groupDirty, 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 (groupDirty) {
                    EditorUtility.SetDirty(aGroup);
                }
            }

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

                var oneVoiceBuses = _creator.groupBuses.FindAll(delegate(GroupBus obj) {
                    return obj.voiceLimit == 1;
                }).Count;

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Bus Control", EditorStyles.miniBoldLabel, GUILayout.Width(100));
                if (oneVoiceBuses > 0) {
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Dialog Mode", EditorStyles.miniBoldLabel, GUILayout.Width(100));
                    GUILayout.Space(230);
                }
                EditorGUILayout.EndHorizontal();

                GroupBus aBus = null;
                int? busToDelete = null;

                for (var i = 0; i < _creator.groupBuses.Count; i++) {
                    aBus = _creator.groupBuses[i];

                    EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);

                    var newBusName = EditorGUILayout.TextField("", aBus.busName, GUILayout.MaxWidth(170));
                    if (newBusName != aBus.busName) {
                        UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Bus Name");
                        aBus.busName = newBusName;
                    }

                    GUILayout.FlexibleSpace();

                    if (!aBus.isExisting) {
                        if (aBus.voiceLimit == 1) {
                            GUI.color = Color.yellow;
                            var newMono = GUILayout.Toggle(aBus.isMonoBus, new GUIContent("", "Dialog Bus Mode"));
                            if (newMono != aBus.isMonoBus) {
                                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Dialog Bus Mode");
                                aBus.isMonoBus = newMono;
                            }
                        }

                        GUI.color = Color.white;
                        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(ref isDirty, _creator, "change Bus Voice Limit");
                            aBus.voiceLimit = busVoiceLimitIndex <= 0 ? -1 : busVoiceLimitIndex;
                        }

                        GUI.color = Color.green;

                        GUILayout.TextField("V " + aBus.volume.ToString("N2"), 6, EditorStyles.miniLabel);

                        GUI.color = Color.white;
                        var newBusVol = GUILayout.HorizontalSlider(aBus.volume, 0f, 1f, GUILayout.Width(86));
                        if (newBusVol != aBus.volume) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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();
        // Music playlist Start
        EditorGUILayout.BeginHorizontal();
        EditorGUI.indentLevel = 0;  // Space will handle this for the header

        GUI.color = _creator.playListExpanded ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr;
        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        var isExp = EditorGUILayout.Toggle("Dynamic Playlist Settings", _creator.playListExpanded);
        if (isExp != _creator.playListExpanded) {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Dynamic Playlist Settings");
            _creator.playListExpanded = isExp;
        }

        EditorGUILayout.EndHorizontal();
        GUI.color = Color.white;

        EditorGUILayout.EndHorizontal();

        if (_creator.playListExpanded) {
            EditorGUI.indentLevel = 0;  // Space will handle this for the header

            if (_creator.musicPlaylists.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You currently have no Playlists set up.");
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            var oldPlayExpanded = DTGUIHelper.Foldout(_creator.playlistEditorExp, string.Format("Playlists ({0})", _creator.musicPlaylists.Count));
            if (oldPlayExpanded != _creator.playlistEditorExp) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Playlists");
                _creator.playlistEditorExp = oldPlayExpanded;
            }

            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));

            GUIContent content;
            var buttonText = "Click to add new Playlist at the end";
            bool addPressed = false;

            // Add button - Process presses later
            GUI.contentColor = Color.green;
            addPressed = GUILayout.Button(new GUIContent("Add", buttonText),
                                               EditorStyles.toolbarButton);

            content = new GUIContent("Collapse", "Click to collapse all");
            var masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton);

            content = new GUIContent("Expand", "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton);
            if (masterExpand) {
                ExpandCollapseAllPlaylists(true);
            }
            if (masterCollapse) {
                ExpandCollapseAllPlaylists(false);
            }
            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndHorizontal();

            if (_creator.playlistEditorExp) {
                int? playlistToRemove = null;
                int? playlistToInsertAt = null;
                int? playlistToMoveUp = null;
                int? playlistToMoveDown = null;

                for (var i = 0; i < _creator.musicPlaylists.Count; i++) {
                    EditorGUILayout.Separator();
                    var aList = _creator.musicPlaylists[i];

                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
                    aList.isExpanded = DTGUIHelper.Foldout(aList.isExpanded, "Playlist: " + aList.playlistName);

                    var playlistButtonPressed = DTGUIHelper.AddFoldOutListItemButtons(i, _creator.musicPlaylists.Count, "playlist", false, true);

                    EditorGUILayout.EndHorizontal();

                    if (aList.isExpanded) {
                        EditorGUI.indentLevel = 0;
                        var newPlaylist = EditorGUILayout.TextField("Name", aList.playlistName);
                        if (newPlaylist != aList.playlistName) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Name");
                            aList.playlistName = newPlaylist;
                        }

                        var crossfadeMode = (MasterAudio.Playlist.CrossfadeTimeMode)EditorGUILayout.EnumPopup("Crossfade Mode", aList.crossfadeMode);
                        if (crossfadeMode != aList.crossfadeMode) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Crossfade Mode");
                            aList.crossfadeMode = crossfadeMode;
                        }
                        if (aList.crossfadeMode == MasterAudio.Playlist.CrossfadeTimeMode.Override) {
                            var newCF = EditorGUILayout.Slider("Crossfade time (sec)", aList.crossFadeTime, 0f, 10f);
                            if (newCF != aList.crossFadeTime) {
                                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Crossfade time (sec)");
                                aList.crossFadeTime = newCF;
                            }
                        }

                        var newFadeIn = EditorGUILayout.Toggle("Fade In First Song", aList.fadeInFirstSong);
                        if (newFadeIn != aList.fadeInFirstSong) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Fade In First Song");
                            aList.fadeInFirstSong = newFadeIn;
                        }

                        var newFadeOut = EditorGUILayout.Toggle("Fade Out Last Song", aList.fadeOutLastSong);
                        if (newFadeOut != aList.fadeOutLastSong) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Fade Out Last Song");
                            aList.fadeOutLastSong = newFadeOut;
                        }

                        var newTransType = (MasterAudio.SongFadeInPosition)EditorGUILayout.EnumPopup("Song Transition Type", aList.songTransitionType);
                        if (newTransType != aList.songTransitionType) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Song Transition Type");
                            aList.songTransitionType = newTransType;
                        }
                        if (aList.songTransitionType == MasterAudio.SongFadeInPosition.SynchronizeClips) {
                            DTGUIHelper.ShowColorWarning("*All clips must be of exactly the same length in this mode.");
                        }

                        EditorGUI.indentLevel = 0;
                        var newBulkMode = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Clip Create Mode", aList.bulkLocationMode);
                        if (newBulkMode != aList.bulkLocationMode) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Bulk Clip Mode");
                            aList.bulkLocationMode = newBulkMode;
                        }

                        var playlistHasResource = false;
                        for (var s = 0; s < aList.MusicSettings.Count; s++) {
                            if (aList.MusicSettings[s].audLocation == MasterAudio.AudioLocation.ResourceFile) {
                                playlistHasResource = true;
                                break;
                            }
                        }

                        if (MasterAudio.HasAsyncResourceLoaderFeature() && playlistHasResource) {
                            if (!maInScene || !ma.resourceClipsAllLoadAsync) {
                                var newAsync = EditorGUILayout.Toggle(new GUIContent("Load Resources Async", "Checking this means Resource files in this Playlist will be loaded asynchronously."), aList.resourceClipsAllLoadAsync);
                                if (newAsync != aList.resourceClipsAllLoadAsync) {
                                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Load Resources Async");
                                    aList.resourceClipsAllLoadAsync = newAsync;
                                }
                            }
                        }
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(10);
                        GUI.contentColor = Color.green;
                        if (GUILayout.Button(new GUIContent("Equalize Song Volumes"), EditorStyles.toolbarButton)) {
                            EqualizePlaylistVolumes(aList.MusicSettings);
                        }

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

                        EditorGUILayout.BeginVertical();
                        var anEvent = Event.current;

                        GUI.color = Color.yellow;

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

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

                                        AddSongToPlaylist(aList, aClip);
                                    }
                                }
                                Event.current.Use();
                                break;
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUI.indentLevel = 2;

                        int? addIndex = null;
                        int? removeIndex = null;
                        int? moveUpIndex = null;
                        int? moveDownIndex = null;

                        if (aList.MusicSettings.Count == 0) {
                            EditorGUI.indentLevel = 0;
                            DTGUIHelper.ShowLargeBarAlert("You currently have no songs in this Playlist.");
                        }

                        EditorGUI.indentLevel = 2;

                        for (var j = 0; j < aList.MusicSettings.Count; j++) {
                            var aSong = aList.MusicSettings[j];
                            var clipName = "Empty";
                            switch (aSong.audLocation) {
                                case MasterAudio.AudioLocation.Clip:
                                    if (aSong.clip != null) {
                                        clipName = aSong.clip.name;
                                    }
                                    break;
                                case MasterAudio.AudioLocation.ResourceFile:
                                    if (!string.IsNullOrEmpty(aSong.resourceFileName)) {
                                        clipName = aSong.resourceFileName;
                                    }
                                    break;
                            }
                            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                            EditorGUI.indentLevel = 2;

                            if (!string.IsNullOrEmpty(clipName) && string.IsNullOrEmpty(aSong.songName)) {
                                switch (aSong.audLocation) {
                                    case MasterAudio.AudioLocation.Clip:
                                        aSong.songName = clipName;
                                        break;
                                    case MasterAudio.AudioLocation.ResourceFile:
                                        aSong.songName = clipName;
                                        break;
                                }
                            }

                            var newSongExpanded = DTGUIHelper.Foldout(aSong.isExpanded, aSong.songName);
                            if (newSongExpanded != aSong.isExpanded) {
                                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Song expand");
                                aSong.isExpanded = newSongExpanded;
                            }
                            var songButtonPressed = DTGUIHelper.AddFoldOutListItemButtons(j, aList.MusicSettings.Count, "clip", false, true, true);
                            EditorGUILayout.EndHorizontal();

                            if (aSong.isExpanded) {
                                EditorGUI.indentLevel = 0;

                                var oldLocation = aSong.audLocation;
                                var newClipSource = (MasterAudio.AudioLocation)EditorGUILayout.EnumPopup("Audio Origin", aSong.audLocation);
                                if (newClipSource != aSong.audLocation) {
                                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Audio Origin");
                                    aSong.audLocation = newClipSource;
                                }

                                switch (aSong.audLocation) {
                                    case MasterAudio.AudioLocation.Clip:
                                        var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", aSong.clip, typeof(AudioClip), true);
                                        if (newClip != aSong.clip) {
                                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Clip");
                                            aSong.clip = newClip;
                                            var cName = newClip == null ? "Empty" : newClip.name;
                                            aSong.songName = cName;
                                        }
                                        break;
                                    case MasterAudio.AudioLocation.ResourceFile:
                                        if (oldLocation != aSong.audLocation) {
                                            if (aSong.clip != null) {
                                                Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Playlist clip.");
                                            }
                                            aSong.clip = null;
                                            aSong.songName = string.Empty;
                                        }

                                        EditorGUILayout.BeginVertical();
                                        anEvent = Event.current;

                                        GUI.color = Color.yellow;
                                        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(ref isDirty, _creator, "change Resource Filename");

                                                        var unused = false;
                                                        var resourceFileName = DTGUIHelper.GetResourcePath(aClip, ref unused);
                                                        if (string.IsNullOrEmpty(resourceFileName)) {
                                                            resourceFileName = aClip.name;
                                                        }

                                                        aSong.resourceFileName = resourceFileName;
                                                        aSong.songName = aClip.name;
                                                    }
                                                }
                                                Event.current.Use();
                                                break;
                                        }
                                        EditorGUILayout.EndVertical();

                                        var newFilename = EditorGUILayout.TextField("Resource Filename", aSong.resourceFileName);
                                        if (newFilename != aSong.resourceFileName) {
                                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Resource Filename");
                                            aSong.resourceFileName = newFilename;
                                        }

                                        break;
                                }

                                var newVol = EditorGUILayout.Slider("Volume", aSong.volume, 0f, 1f);
                                if (newVol != aSong.volume) {
                                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Volume");
                                    aSong.volume = newVol;
                                }

                                var newPitch = EditorGUILayout.Slider("Pitch", aSong.pitch, -3f, 3f);
                                if (newPitch != aSong.pitch) {
                                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Pitch");
                                    aSong.pitch = newPitch;
                                }

                                var newLoop = EditorGUILayout.Toggle("Loop Clip", aSong.isLoop);
                                if (newLoop != aSong.isLoop) {
                                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle Loop Clip");
                                    aSong.isLoop = newLoop;
                                }
                            }

                            switch (songButtonPressed) {
                                case DTGUIHelper.DTFunctionButtons.Add:
                                    addIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Remove:
                                    removeIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.ShiftUp:
                                    moveUpIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.ShiftDown:
                                    moveDownIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Play:
                                    MasterAudio.PreviewerInstance.Stop();
                                    MasterAudio.PreviewerInstance.PlayOneShot(aSong.clip, aSong.volume);
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Stop:
                                    MasterAudio.PreviewerInstance.clip = null;
                                    MasterAudio.PreviewerInstance.Stop();
                                    break;
                            }
                        }

                        if (addIndex.HasValue) {
                            var mus = new MusicSetting();
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "add song");
                            aList.MusicSettings.Insert(addIndex.Value + 1, mus);
                        } else if (removeIndex.HasValue) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "delete song");
                            aList.MusicSettings.RemoveAt(removeIndex.Value);
                        } else if (moveUpIndex.HasValue) {
                            var item = aList.MusicSettings[moveUpIndex.Value];

                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "shift up song");

                            aList.MusicSettings.Insert(moveUpIndex.Value - 1, item);
                            aList.MusicSettings.RemoveAt(moveUpIndex.Value + 1);
                        } else if (moveDownIndex.HasValue) {
                            var index = moveDownIndex.Value + 1;
                            var item = aList.MusicSettings[index];

                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "shift down song");

                            aList.MusicSettings.Insert(index - 1, item);
                            aList.MusicSettings.RemoveAt(index + 1);
                        }
                    }

                    switch (playlistButtonPressed) {
                        case DTGUIHelper.DTFunctionButtons.Remove:
                            playlistToRemove = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.Add:
                            playlistToInsertAt = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.ShiftUp:
                            playlistToMoveUp = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.ShiftDown:
                            playlistToMoveDown = i;
                            break;
                    }
                }

                if (playlistToRemove.HasValue) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "delete Playlist");

                    _creator.musicPlaylists.RemoveAt(playlistToRemove.Value);
                }
                if (playlistToInsertAt.HasValue) {
                    var pl = new MasterAudio.Playlist();
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "add Playlist");
                    _creator.musicPlaylists.Insert(playlistToInsertAt.Value + 1, pl);
                }
                if (playlistToMoveUp.HasValue) {
                    var item = _creator.musicPlaylists[playlistToMoveUp.Value];
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "shift up Playlist");
                    _creator.musicPlaylists.Insert(playlistToMoveUp.Value - 1, item);
                    _creator.musicPlaylists.RemoveAt(playlistToMoveUp.Value + 1);
                }
                if (playlistToMoveDown.HasValue) {
                    var index = playlistToMoveDown.Value + 1;
                    var item = _creator.musicPlaylists[index];

                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "shift down Playlist");

                    _creator.musicPlaylists.Insert(index - 1, item);
                    _creator.musicPlaylists.RemoveAt(index + 1);
                }
            }

            if (addPressed) {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "add Playlist");
                _creator.musicPlaylists.Add(new MasterAudio.Playlist());
            }
        }
        // Music playlist End

        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(ref isDirty, _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(ref isDirty, _creator, "change New Event Name");
                _creator.newEventName = newEvent;
            }

            GUI.contentColor = Color.green;

            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(10);
            if (GUILayout.Button("Create New Event", EditorStyles.toolbarButton, GUILayout.Width(100))) {
                CreateCustomEvent(_creator.newEventName);
            }
            GUI.contentColor = Color.white;

            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = 0;
            if (_creator.customEventsToCreate.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("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++) {
                EditorGUI.indentLevel = 0;
                var anEvent = _creator.customEventsToCreate[i];

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                var exp =  DTGUIHelper.Foldout(anEvent.eventExpanded, anEvent.EventName);
                if (exp != anEvent.eventExpanded) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "toggle expand Custom Event");
                    anEvent.eventExpanded = exp;
                }

                GUILayout.FlexibleSpace();
                var newName = GUILayout.TextField(anEvent.ProspectiveName, GUILayout.Width(170));
                if (newName != anEvent.ProspectiveName) {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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 (anEvent.eventExpanded) {
                    EditorGUI.indentLevel = 1;
                    var rcvMode = (MasterAudio.CustomEventReceiveMode) EditorGUILayout.EnumPopup("Send To Receivers", anEvent.eventReceiveMode);
                    if (rcvMode != anEvent.eventReceiveMode) {
                        UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Send To Receivers");
                        anEvent.eventReceiveMode = rcvMode;
                    }

                    if (rcvMode == MasterAudio.CustomEventReceiveMode.WhenDistanceLessThan || rcvMode == MasterAudio.CustomEventReceiveMode.WhenDistanceMoreThan) {
                        var newDist = EditorGUILayout.Slider("Distance Threshold", anEvent.distanceThreshold, 0f, float.MaxValue);
                        if (newDist != anEvent.distanceThreshold) {
                            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, _creator, "change Distance Threshold");
                            anEvent.distanceThreshold = newDist;
                        }
                    }

                    EditorGUILayout.Separator();
                }
            }

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

        //DrawDefaultInspector();
    }
コード例 #10
0
    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();
    }
コード例 #11
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI() {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 0;
        var isDirty = false;
        _isValid = true;

        _group = (DynamicSoundGroup)target;

        _group = RescanChildren(_group);

        if (_group == null) {
            return;
        }

        var theParent = _group.transform.parent;
        if (theParent != null) {
            _previewer = theParent.gameObject;
        }

        if (_previewer == null) {
            DTGUIHelper.ShowRedError("This prefab must have a GameObject above it. Prefab broken.");
            _isValid = false;
        }

        var previewLang = SystemLanguage.English;

        if (!_isValid) {
            return;
        }

        _dgsc = _previewer.GetComponent<DynamicSoundGroupCreator>();
        if (_dgsc != null) {
            previewLang = _dgsc.previewLanguage;
        }

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

        if (maInScene) {
            _groupNames = ma.GroupNames;
            _groupNames.Remove(_group.name);
            _customEventNames = ma.CustomEventNames;
        }

        var isInProjectView = DTGUIHelper.IsPrefabInProjectView(_group);

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

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        if (GUILayout.Button(new GUIContent("Up to Parent", "Select Group in Hierarchy"), EditorStyles.toolbarButton, GUILayout.Width(100))) {
            Selection.activeObject = _group.transform.parent.gameObject;
        }
        GUI.contentColor = Color.white;
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        var newVol = DTGUIHelper.DisplayVolumeField(_group.groupMasterVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Group Master Volume");
        if (newVol != _group.groupMasterVolume) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Group Master Volume");
            _group.groupMasterVolume = newVol;
        }

        var newTargetGone = (MasterAudioGroup.TargetDespawnedBehavior)EditorGUILayout.EnumPopup("Caller Despawned Mode", _group.targetDespawnedBehavior);
        if (newTargetGone != _group.targetDespawnedBehavior) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "Change Caller Despawned Mode");
            _group.targetDespawnedBehavior = newTargetGone;
        }

        if (_group.targetDespawnedBehavior == MasterAudioGroup.TargetDespawnedBehavior.FadeOut) {
            EditorGUI.indentLevel = 1;
            var newFade = EditorGUILayout.Slider("Fade Out Time", _group.despawnFadeTime, .1f, 20f);
            if (newFade != _group.despawnFadeTime) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "Change Called Despawned Fade Out Time");
                _group.despawnFadeTime = newFade;
            }
        }

        var groupHasResource = false;
        foreach (var t in _group.groupVariations) {
            if (t.audLocation != MasterAudio.AudioLocation.ResourceFile) {
                continue;
            }

            groupHasResource = true;
            break;
        }

        if (MasterAudio.HasAsyncResourceLoaderFeature() && groupHasResource) {
            if ((maInScene && !ma.resourceClipsAllLoadAsync) || !maInScene) {
                var newAsync = EditorGUILayout.Toggle(new GUIContent("Load Resources Async", "Checking this means Resource files in this Sound Group will be loaded asynchronously."), _group.resourceClipsAllLoadAsync);
                if (newAsync != _group.resourceClipsAllLoadAsync) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Load Resources Async");
                    _group.resourceClipsAllLoadAsync = newAsync;
                }
            }
        }

        if (!maInScene || ma.prioritizeOnDistance) {
            var hiPri = EditorGUILayout.Toggle("Always Highest Priority", _group.alwaysHighestPriority);
            if (hiPri != _group.alwaysHighestPriority) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Always Highest Priority");
                _group.alwaysHighestPriority = hiPri;
            }
        }

        var newLog = EditorGUILayout.Toggle("Log Sounds", _group.logSound);
        if (newLog != _group.logSound) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Log Sounds");
            _group.logSound = newLog;
        }

#if UNITY_5
        DTGUIHelper.ShowLargeBarAlert("The Spatial Blend Rule below will only be used if the Master Audio prefab allows.");

        DTGUIHelper.StartGroupHeader();
        var newSpatialType = (MasterAudio.ItemSpatialBlendType)EditorGUILayout.EnumPopup("Spatial Blend Rule", _group.spatialBlendType);
        if (newSpatialType != _group.spatialBlendType) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Spatial Blend Rule");
            _group.spatialBlendType = newSpatialType;
        }
        EditorGUILayout.EndVertical();

        switch (_group.spatialBlendType) {
            case MasterAudio.ItemSpatialBlendType.ForceToCustom:
                EditorGUI.indentLevel = 0;
                DTGUIHelper.ShowLargeBarAlert(MasterAudioInspector.SpatialBlendSliderText);
                var newBlend = EditorGUILayout.Slider("Spatial Blend", _group.spatialBlend, 0f, 1f);
                if (newBlend != _group.spatialBlend) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Spatial Blend");
                    _group.spatialBlend = newBlend;
                }
                break;
        }
        EditorGUILayout.EndVertical();
#endif

        EditorGUI.indentLevel = 0;

        DTGUIHelper.StartGroupHeader();

        var newVarSequence = (MasterAudioGroup.VariationSequence)EditorGUILayout.EnumPopup("Variation Sequence", _group.curVariationSequence);
        if (newVarSequence != _group.curVariationSequence) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Variation Sequence");
            _group.curVariationSequence = newVarSequence;
        }

        EditorGUILayout.EndVertical();

        if (_group.curVariationSequence == MasterAudioGroup.VariationSequence.TopToBottom) {
            var newUseInactive = EditorGUILayout.BeginToggleGroup(" Refill Variation Pool After Inactive Time", _group.useInactivePeriodPoolRefill);
            if (newUseInactive != _group.useInactivePeriodPoolRefill) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Inactive Time");
                _group.inactivePeriodSeconds = newInactivePeriod;
            }

            EditorGUILayout.EndToggleGroup();
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        DTGUIHelper.AddSpaceForNonU5(2);
        DTGUIHelper.StartGroupHeader();
        var newVarMode = (MasterAudioGroup.VariationMode)EditorGUILayout.EnumPopup("Variation Mode", _group.curVariationMode);
        if (newVarMode != _group.curVariationMode) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Variation Mode");
            _group.curVariationMode = newVarMode;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        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) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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;
                    }
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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;
                    }
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Retrigger Percentage");
                    _group.retriggerPercentage = newRetrigger;
                }

                var newLimitPoly = EditorGUILayout.Toggle("Limit Polyphony", _group.limitPolyphony);
                if (newLimitPoly != _group.limitPolyphony) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Limit Polyphony");
                    _group.limitPolyphony = newLimitPoly;
                }
                if (_group.limitPolyphony) {
                    var maxVoices = 0;
                    foreach (var variation in _group.groupVariations) {
                        maxVoices += variation.weight;
                    }

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

                var newLimitMode = (MasterAudioGroup.LimitMode)EditorGUILayout.EnumPopup("Replay Limit Mode", _group.limitMode);
                if (newLimitMode != _group.limitMode) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Custom Fade Out Time");
                        _group.dialogFadeOutTime = newFadeTime;
                    }
                }
                break;
        }
        EditorGUILayout.EndVertical();

        DTGUIHelper.AddSpaceForNonU5(2);
        DTGUIHelper.StartGroupHeader();
        EditorGUI.indentLevel = 0;

        var canCopy = false;

        var newChildMode = (MasterAudioGroup.ChildGroupMode)EditorGUILayout.EnumPopup(new GUIContent("Linked Group Mode", "Groups you set up in this section will also get played automatically when this Group plays."), _group.childGroupMode);
        if (newChildMode != _group.childGroupMode) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Linked Group Mode");
            _group.childGroupMode = newChildMode;
        }
        EditorGUILayout.EndVertical();

        if (_group.childGroupMode != MasterAudioGroup.ChildGroupMode.None) {
            if (_group.childSoundGroups.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You have no other Groups set up to trigger.");
                EditorGUILayout.Separator();
            }

            EditorGUI.indentLevel = 1;
            for (var i = 0; i < _group.childSoundGroups.Count; i++) {
                var aGroup = _group.childSoundGroups[i];
                if (maInScene) {
                    var existingIndex = _groupNames.IndexOf(aGroup);

                    int? groupIndex = null;

                    EditorGUI.indentLevel = 0;

                    var noGroup = false;
                    var noMatch = false;

                    if (existingIndex >= 1) {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                        if (existingIndex == 1) {
                            noGroup = true;
                        }
                    } else if (existingIndex == -1 && aGroup == MasterAudio.NoGroupName) {
                        groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                    } else { // non-match
                        noMatch = true;
                        var newSound = EditorGUILayout.TextField("Sound Group", aGroup);
                        if (newSound != aGroup) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                            _group.childSoundGroups[i] = newSound;
                        }

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

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

                    if (!groupIndex.HasValue) {
                        continue;
                    }
                    if (existingIndex != groupIndex.Value) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                    }
                    if (groupIndex.Value == -1) {
                        _group.childSoundGroups[i] = MasterAudio.NoGroupName;
                    } else {
                        _group.childSoundGroups[i] = _groupNames[groupIndex.Value];
                    }
                } else {
                    var newSType = EditorGUILayout.TextField("Sound Group", aGroup);
                    if (newSType == aGroup) {
                        continue;
                    }
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Sound Group");
                    _group.childSoundGroups[i] = newSType;
                }
            }

            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Add Trigger Group"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                _group.childSoundGroups.Add(string.Empty);
            }
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Delete Trigger Group", "Delete the last Trigger Group"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                _group.childSoundGroups.RemoveAt(_group.childSoundGroups.Count - 1);
            }
            EditorGUILayout.EndHorizontal();
            GUI.contentColor = Color.white;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;

        DTGUIHelper.StartGroupHeader();
        var newUse = EditorGUILayout.BeginToggleGroup(" Group Played Event", _group.soundPlayedEventActive);
        if (newUse != _group.soundPlayedEventActive) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle expand Group Played Event");
            _group.soundPlayedEventActive = newUse;
        }
        DTGUIHelper.EndGroupHeader();

        GUI.color = Color.white;

        if (_group.soundPlayedEventActive) {
            DTGUIHelper.ShowColorWarning("When this Group plays, fire Custom Event below.");

            if (maInScene) {
                var existingIndex = _customEventNames.IndexOf(_group.soundPlayedCustomEvent);

                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 && _group.soundPlayedCustomEvent == MasterAudio.NoGroupName) {
                    customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                } else { // non-match
                    noMatch = true;
                    var newEventName = EditorGUILayout.TextField("Custom Event Name", _group.soundPlayedCustomEvent);
                    if (newEventName != _group.soundPlayedCustomEvent) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Custom Event Name");
                        _group.soundPlayedCustomEvent = 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, _group, "change Custom Event");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (customEventIndex.Value == -1) {
                        _group.soundPlayedCustomEvent = MasterAudio.NoGroupName;
                    } else {
                        _group.soundPlayedCustomEvent = _customEventNames[customEventIndex.Value];
                    }
                }
            } else {
                var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", _group.soundPlayedCustomEvent);
                if (newCustomEvent != _group.soundPlayedCustomEvent) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "Custom Event Name");
                    _group.soundPlayedCustomEvent = newCustomEvent;
                }
            }
        }
        EditorGUILayout.EndToggleGroup();

        if (!Application.isPlaying) {
            DTGUIHelper.AddSpaceForNonU5(2);
            DTGUIHelper.StartGroupHeader();
            EditorGUI.indentLevel = 1;
            var newBulk = DTGUIHelper.Foldout(_group.copySettingsExpanded, "Copy Settings");
            if (newBulk != _group.copySettingsExpanded) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "toggle Copy Settings");
                _group.copySettingsExpanded = newBulk;
            }
            EditorGUILayout.EndVertical();
            EditorGUI.indentLevel = 0;
            GUI.color = Color.white;

            if (_group.copySettingsExpanded) {
                if (_group.groupVariations.Count == 0) {
                    DTGUIHelper.ShowLargeBarAlert("You currently have no Variations in this Group.");
                } else if (_group.groupVariations.Count == 1) {
                    DTGUIHelper.ShowLargeBarAlert("You only have a single Variation in this Group. Nothing to copy to.");
                } else {
                    canCopy = true;

                    var varNames = new List<string>(_group.groupVariations.Count);
                    foreach (var t in _group.groupVariations) {
                        varNames.Add(t.name);
                    }

                    if (_group.selectedVariationIndex >= varNames.Count) {
                        _group.selectedVariationIndex = 0;
                    }

                    var newVar = EditorGUILayout.Popup("Source Variation", _group.selectedVariationIndex,
                        varNames.ToArray());
                    if (newVar != _group.selectedVariationIndex) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _group, "change Source Variation");
                        _group.selectedVariationIndex = newVar;
                    }

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Target Variations");

                    GUILayout.Space(44);
                    GUI.contentColor = DTGUIHelper.BrightButtonColor;
                    if (GUILayout.Button("Check All", EditorStyles.toolbarButton, GUILayout.Width(80))) {
                        CheckAll();
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Uncheck All", EditorStyles.toolbarButton, GUILayout.Width(80))) {
                        UncheckAll();
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Separator();

                    DTGUIHelper.ShowColorWarning(
                        "Click buttons below to copy from Source to checked Variations.");

                    var hasSelected = GetNonMatchingVariations().Count > 0;
                    if (!hasSelected) {
                        DTGUIHelper.ShowRedError(
                            "You have no Variations checked. Please use the checkboxes.");
                        EditorGUILayout.Separator();
                    }

                    var sourceVar = _group.groupVariations[_group.selectedVariationIndex];
                    const int btnWidth = 96;

                    GUI.contentColor = DTGUIHelper.BrightButtonColor;
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    if (GUILayout.Button("Volume", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyVolumes(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Pitch", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyPitches(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Loop", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyLoops(sourceVar);
                        isDirty = true;
                    }
                    EditorGUILayout.EndHorizontal();
                    DTGUIHelper.VerticalSpace(2);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    if (GUILayout.Button("FX Tail Time", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyFxTail(sourceVar);
                        isDirty = true;
                    }

                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Pitch", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyRandomPitch(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Volume", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyRandomVolume(sourceVar);
                        isDirty = true;
                    }
                    EditorGUILayout.EndHorizontal();
                    DTGUIHelper.VerticalSpace(2);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    if (GUILayout.Button("Rand. Delay", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyRandomDelay(sourceVar);
                        isDirty = true;
                    }
                    GUILayout.Space(10);
                    if (GUILayout.Button("Custom Fade", EditorStyles.toolbarButton, GUILayout.Width(btnWidth))) {
                        CopyCustomFade(sourceVar);
                        isDirty = true;
                    }

                    EditorGUILayout.EndHorizontal();

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

        EditorGUI.indentLevel = 0;

        int? deadChildIndex = null;

        if (!Application.isPlaying) {
            DTGUIHelper.AddSpaceForNonU5(2);
            DTGUIHelper.StartGroupHeader();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Actions", EditorStyles.wordWrappedLabel, GUILayout.Width(50f));
            GUILayout.Space(30);
            GUI.contentColor = DTGUIHelper.BrightButtonColor;

            var buttonText = "Collapse All";
            var allCollapsed = true;

            foreach (var t in _group.groupVariations) {
                if (!t.isExpanded) {
                    continue;
                }

                allCollapsed = false;
                break;
            }

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

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

            if (GUILayout.Button(new GUIContent("Eq. Voices", "Reset Voices to one"), EditorStyles.toolbarButton, GUILayout.Width(80))) {
                isDirty = true;
                EqualizeWeights(_group);
            }

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

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

            DTGUIHelper.VerticalSpace(1);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Localization", EditorStyles.wordWrappedLabel, GUILayout.Width(80f));
            GUILayout.FlexibleSpace();
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("All Use Loc.", "Check the 'Use Localized Folder' checkbox for all Variations."), EditorStyles.toolbarButton, GUILayout.Width(125))) {
                isDirty = true;
                BulkUseLocalization(_group.groupVariations, true);
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("None Use Loc.", "Uncheck the 'Use Localized Folder' checkbox for all Variations."), EditorStyles.toolbarButton, GUILayout.Width(125))) {
                isDirty = true;
                BulkUseLocalization(_group.groupVariations, false);
            }

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

            var newBulkMode = DTGUIHelper.GetRestrictedAudioLocation("Variation Create Mode", _group.bulkVariationMode);
            if (newBulkMode != _group.bulkVariationMode) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, _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.");
            }

            DTGUIHelper.EndGroupHeader();
        }

        DTGUIHelper.VerticalSpace(2);

        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 = DTGUIHelper.DragAreaColor;

                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 {
            for (var i = 0; i < _group.groupVariations.Count; i++) {
                var variation = _group.groupVariations[i];

                var isNotSource = _group.selectedVariationIndex != i;

                var state = variation.isExpanded;
                var text = variation.name;

                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (!state) {
                    GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
                } else {
                    GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
                }

                GUILayout.BeginHorizontal();

#if UNITY_3_5_7
				if (!state) {
					text += " (Click to expand)";
				}
#else
                text = "<b><size=11>" + text + "</size></b>";
#endif
                if (state) {
                    text = "\u25BC " + text;
                } else {
                    text = "\u25BA " + text;
                }
                if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
                    state = !state;
                }

                GUI.backgroundColor = Color.white;
                if (!state) {
                    GUILayout.Space(3f);
                }

                if (state != variation.isExpanded) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, variation, "toggle Expand Variation");
                    variation.isExpanded = state;
                }

                EditorGUI.indentLevel = 0;

                if (canCopy) {
                    if (isNotSource) {
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        var newChecked = EditorGUILayout.Toggle(variation.isChecked, GUILayout.Width(16), GUILayout.Height(16));
                        if (newChecked != variation.isChecked) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, variation, "toggle check Variation");
                            variation.isChecked = newChecked;
                        }
                        EditorGUILayout.EndHorizontal();
                    } else {
                        GUI.contentColor = DTGUIHelper.BrightTextColor;
                        GUILayout.Label("SOURCE", GUILayout.Width(54));
                        GUI.contentColor = Color.white;
                    }
                }

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

                if (!Application.isPlaying && !DTGUIHelper.IsPrefabInProjectView(_group)) {
                    if (GUILayout.Button(new GUIContent(MasterAudioInspectorResources.CopyTexture, "Click to clone Variation"), EditorStyles.toolbarButton, GUILayout.Height(16), GUILayout.Width(40))) {
                        CloneVariation(i);
                    }
                }

                var varIsDirty = false;

                var buttonPressed = DTGUIHelper.AddDynamicGroupButtons(_group);

                if (!Application.isPlaying && !DTGUIHelper.IsPrefabInProjectView(_group)) {
                    if (GUILayout.Button(new GUIContent(MasterAudioInspectorResources.DeleteTexture, "Click to delete this Variation"), EditorStyles.toolbarButton, GUILayout.Height(16), GUILayout.Width(40))) {
                        deadChildIndex = i;
                        isDirty = true;
                    }
                }
                GUILayout.Space(4);

                switch (buttonPressed) {
                    case DTGUIHelper.DTFunctionButtons.Play:
                        var calcVolume = variation.VarAudio.volume * _group.groupMasterVolume;

                        switch (variation.audLocation) {
                            case MasterAudio.AudioLocation.ResourceFile:
                                StopPreviewer();
                                var fileName = AudioResourceOptimizer.GetLocalizedDynamicSoundGroupFileName(previewLang, variation.useLocalization, variation.resourceFileName);
                                var clip = Resources.Load(fileName) as AudioClip;
                                if (clip != null) {
                                    GetPreviewer().PlayOneShot(clip, calcVolume);
                                } else {
                                    DTGUIHelper.ShowAlert("Could not find Resource file: " + fileName);
                                }
                                break;
                            case MasterAudio.AudioLocation.Clip:
                                variation.VarAudio.PlayOneShot(variation.VarAudio.clip, calcVolume);
                                break;
                            case MasterAudio.AudioLocation.FileOnInternet:
                                if (!string.IsNullOrEmpty(variation.internetFileUrl)) {
                                    Application.OpenURL(variation.internetFileUrl);
                                }

                                break;
                        }
                        isDirty = true;
                        break;
                    case DTGUIHelper.DTFunctionButtons.Stop:
                        if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile) {
                            StopPreviewer();
                        } else {
                            variation.VarAudio.Stop();
                        }
                        isDirty = true;
                        break;
                }
                EditorGUILayout.EndHorizontal();

                GUI.backgroundColor = Color.white;

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

                DTGUIHelper.BeginGroupedControls();

                if (!Application.isPlaying) {
                    DTGUIHelper.ShowColorWarning(MasterAudio.PreviewText);
                }
                if (variation.VarAudio == 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) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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 varIsDirty, variation.VarAudio, "change 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 varIsDirty, 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;
                            varIsDirty = true;
                        }

                        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;

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

                                        var useLocalization = false;
                                        AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Resource Filename");

                                        var newsFilename = DTGUIHelper.GetResourcePath(aClip, ref useLocalization);

                                        variation.resourceFileName = newsFilename;
                                        variation.useLocalization = useLocalization;
                                    }
                                }
                                Event.current.Use();
                                break;
                        }
                        EditorGUILayout.EndVertical();

                        var newFilename = EditorGUILayout.TextField("Resource Filename", variation.resourceFileName);
                        if (newFilename != variation.resourceFileName) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "change Resource Filename");
                            variation.resourceFileName = newFilename;
                        }

                        EditorGUI.indentLevel = 1;

                        var newLocal = EditorGUILayout.Toggle("Use Localized Folder", variation.useLocalization);
                        if (newLocal != variation.useLocalization) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref isDirty, variation, "toggle Use Localized Folder");
                            variation.useLocalization = newLocal;
                        }

                        break;
                }

                EditorGUI.indentLevel = 0;

                var newVolume = DTGUIHelper.DisplayVolumeField(variation.VarAudio.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
                if (newVolume != variation.VarAudio.volume) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "change Volume");
                    variation.VarAudio.volume = newVolume;
                }

                var newPitch = DTGUIHelper.DisplayPitchField(variation.VarAudio.pitch);
                if (newPitch != variation.VarAudio.pitch) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation.VarAudio, "change Pitch");
                    variation.VarAudio.pitch = newPitch;
                }

                if (_group.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 varIsDirty, variation.VarAudio, "toggle Loop Clip");
                        variation.VarAudio.loop = newLoop;
                    }
                }

                var newWeight = EditorGUILayout.IntSlider("Voices (Weight)", variation.weight, 0, 100);
                if (newWeight != variation.weight) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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 varIsDirty, variation, "change FX Tail Time");
                    variation.fxTailTime = newFxTailTime;
                }

                DTGUIHelper.StartGroupHeader();

                var newUseRndPitch = EditorGUILayout.BeginToggleGroup(" Use Random Pitch", variation.useRandomPitch);
                if (newUseRndPitch != variation.useRandomPitch) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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 varIsDirty, variation, "change Pitch Compute Mode");
                        variation.randomPitchMode = newMode;
                    }

                    var newPitchMin = DTGUIHelper.DisplayPitchField(variation.randomPitchMin, "Random Pitch Min");
                    if (newPitchMin != variation.randomPitchMin) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, 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 varIsDirty, variation, "toggle Start Max (%)");
                        variation.randomStartMaxPercent = newMax;
                        if (variation.randomStartMinPercent > variation.randomStartMaxPercent) {
                            variation.randomStartMinPercent = variation.randomStartMaxPercent;
                        }
                    }
                }

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

                DTGUIHelper.StartGroupHeader();
                var newFades = EditorGUILayout.BeginToggleGroup(" Use Custom Fading", variation.useFades);
                if (newFades != variation.useFades) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, variation, "toggle Use Custom Fading");
                    variation.useFades = newFades;
                }
                DTGUIHelper.EndGroupHeader();

                if (variation.useFades) {
                    var newFadeIn = EditorGUILayout.Slider("Fade In Time (sec)", variation.fadeInTime, 0f, 10f);
                    if (newFadeIn != variation.fadeInTime) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref varIsDirty, 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 varIsDirty, variation, "change Fade Out Time");
                        variation.fadeOutTime = newFadeOut;
                    }
                }
                EditorGUILayout.EndToggleGroup();
                DTGUIHelper.EndGroupedControls();

                DTGUIHelper.VerticalSpace(3);

                if (!varIsDirty) {
                    continue;
                }
                EditorUtility.SetDirty(variation.VarAudio);
                EditorUtility.SetDirty(variation);
            }
        }

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

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

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


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

        //DrawDefaultInspector();
    }
コード例 #12
0
    public override void OnInspectorGUI() {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 1;
        _isDirty = false;

        _creator = (DynamicSoundGroupCreator)target;

        var isInProjectView = DTGUIHelper.IsPrefabInProjectView(_creator);

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

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

        if (maInScene) {
            _customEventNames = ma.CustomEventNames;
        }

        _previewer = _creator.gameObject;
        var allowPreview = !DTGUIHelper.IsPrefabInProjectView(_creator);

        var sliderIndicatorChars = 6;
        var sliderWidth = 40;

        if (MasterAudio.UseDbScaleForVolume) {
            sliderIndicatorChars = 9;
            sliderWidth = 56;
        }

        var busVoiceLimitList = new List<string> { MasterAudio.NoVoiceLimitName };

        for (var i = 1; i <= 32; i++) {
            busVoiceLimitList.Add(i.ToString());
        }

        var busList = new List<string> { MasterAudioGroup.NoBus, MasterAudioInspector.NewBusName, ExistingBus };

        var maxChars = 12;

        foreach (var t in _creator.groupBuses) {
            var bus = t;
            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

        if (MasterAudio.Instance == null) {
            var newLang = (SystemLanguage)EditorGUILayout.EnumPopup(new GUIContent("Preview Language", "This setting is only used (and visible) to choose the previewing language when there's no Master Audio prefab in the Scene (language settings are grabbed from there normally). This should only happen when you're using a Master Audio prefab from a previous Scene in persistent mode."), _creator.previewLanguage);
            if (newLang != _creator.previewLanguage) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Preview Language");
                _creator.previewLanguage = newLang;
            }
        }

        EditorGUILayout.Separator();

        var newAllow = (DynamicSoundGroupCreator.CreateItemsWhen)EditorGUILayout.EnumPopup("Items Created When?", _creator.reUseMode);
        if (newAllow != _creator.reUseMode) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Items Created When?");
            _creator.reUseMode = newAllow;
        }

        var newIgnore = EditorGUILayout.Toggle("Error On Duplicate Items", _creator.errorOnDuplicates);
        if (newIgnore != _creator.errorOnDuplicates) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Error On Duplicate Items");
            _creator.errorOnDuplicates = newIgnore;
        }
        if (_creator.errorOnDuplicates) {
            DTGUIHelper.ShowColorWarning("An error will be logged if your Dynamic items already exist in the MA prefab.");
        } else {
            DTGUIHelper.ShowLargeBarAlert("Dynamic items that already exist in the MA prefab will be ignored and not created.");
        }


        var newAwake = EditorGUILayout.Toggle("Auto-create Items", _creator.createOnAwake);
        if (newAwake != _creator.createOnAwake) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _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.ShowLargeBarAlert("You will need to call this object's CreateItems method manually to create the items.");
        }

        var newRemove = EditorGUILayout.Toggle("Auto-remove Items", _creator.removeGroupsOnSceneChange);
        if (newRemove != _creator.removeGroupsOnSceneChange) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Auto-remove Items");
            _creator.removeGroupsOnSceneChange = newRemove;
        }

        if (_creator.removeGroupsOnSceneChange) {
            DTGUIHelper.ShowColorWarning("Items will be deleted when the Scene changes.");
        } else {
            DTGUIHelper.ShowLargeBarAlert("Items created by this will persist across Scenes if MasterAudio does.");
        }

        // custom event
        DTGUIHelper.StartGroupHeader();
        GUI.color = Color.white;
        var exp = EditorGUILayout.BeginToggleGroup("Fire 'Items Created' Event", _creator.itemsCreatedEventExpanded);
        if (exp != _creator.itemsCreatedEventExpanded) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle expand Fire 'Items Created' Event");
            _creator.itemsCreatedEventExpanded = exp;
        }
        GUI.color = Color.white;
        DTGUIHelper.EndGroupHeader();

        if (_creator.itemsCreatedEventExpanded) {
            EditorGUI.indentLevel = 0;
            DTGUIHelper.ShowColorWarning("When items are created, fire Custom Event below.");

            var existingIndex = _customEventNames.IndexOf(_creator.itemsCreatedCustomEvent);

            int? customEventIndex = null;

            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 && _creator.itemsCreatedCustomEvent == MasterAudio.NoGroupName) {
                customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
            } else { // non-match
                noMatch = true;
                var newEventName = EditorGUILayout.TextField("Custom Event Name", _creator.itemsCreatedCustomEvent);
                if (newEventName != _creator.itemsCreatedCustomEvent) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Custom Event Name");
                    _creator.itemsCreatedCustomEvent = 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, _creator, "change Custom Event");
                }
                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (customEventIndex.Value == -1) {
                    _creator.itemsCreatedCustomEvent = MasterAudio.NoGroupName;
                } else {
                    _creator.itemsCreatedCustomEvent = _customEventNames[customEventIndex.Value];
                }
            }
        }
        EditorGUILayout.EndToggleGroup();

        _groups = ScanForGroups();
        var groupNameList = GroupNameList;

        EditorGUI.indentLevel = 0;

        var state = _creator.showMusicDucking;
        var text = "Dynamic Music Ducking";

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state) {
            GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
        } else {
            GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
        }

        DTGUIHelper.AddSpaceForNonU5(2);

        GUILayout.BeginHorizontal();

#if UNITY_3_5_7
        if (!state) {
            text += " (Click to expand)";
        }
#else
        text = "<b><size=11>" + text + "</size></b>";
#endif
        if (state) {
            text = "\u25BC " + text;
        } else {
            text = "\u25BA " + text;
        }
        if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
            state = !state;
        }

        GUILayout.Space(2f);



        if (state != _creator.showMusicDucking) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Dynamic Music Ducking");
            _creator.showMusicDucking = state;
        }
        EditorGUILayout.EndHorizontal();
        GUI.color = Color.white;

        if (_creator.showMusicDucking) {
            DTGUIHelper.BeginGroupedControls();
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(10);

            if (GUILayout.Button(new GUIContent("Add Duck Group"), EditorStyles.toolbarButton, GUILayout.Width(100))) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "Add Duck Group");

                var defaultBeginUnduck = 0.5f;
                if (maInScene) {
                    defaultBeginUnduck = ma.defaultRiseVolStart;
                }

                _creator.musicDuckingSounds.Add(new DuckGroupInfo {
                    soundType = MasterAudio.NoGroupName,
                    riseVolStart = defaultBeginUnduck
                });
            }

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

            if (_creator.musicDuckingSounds.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("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;
                    }

                    DTGUIHelper.StartGroupHeader();
                    EditorGUILayout.BeginHorizontal();
                    var newIndex = EditorGUILayout.Popup(index, groupNameList.ToArray(), GUILayout.MaxWidth(200));
                    if (newIndex >= 0) {
                        if (index != newIndex) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Duck Group");
                        }
                        duckSound.soundType = groupNameList[newIndex];
                    }

                    GUI.contentColor = DTGUIHelper.BrightButtonColor;
                    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) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _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();
                    DTGUIHelper.EndGroupHeader();
                    DTGUIHelper.AddSpaceForNonU5(2);
                }

                if (duckSoundToRemove.HasValue) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "delete Duck Group");
                    _creator.musicDuckingSounds.RemoveAt(duckSoundToRemove.Value);
                }
            }

            DTGUIHelper.EndGroupedControls();
        }

        DTGUIHelper.ResetColors();


        DTGUIHelper.VerticalSpace(3);

        state = _creator.soundGroupsAreExpanded;
        text = "Dynamic Group Mixer";

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state) {
            GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
        } else {
            GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
        }

        GUILayout.BeginHorizontal();

#if UNITY_3_5_7
        if (!state) {
            text += " (Click to expand)";
        }
#else
        text = "<b><size=11>" + text + "</size></b>";
#endif
        if (state) {
            text = "\u25BC " + text;
        } else {
            text = "\u25BA " + text;
        }
        if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
            state = !state;
        }

        GUILayout.Space(2f);


        if (state != _creator.soundGroupsAreExpanded) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Dynamic Group Mixer");
            _creator.soundGroupsAreExpanded = state;
        }

        var applyTemplateToAll = false;
        EditorGUILayout.EndHorizontal();
        GUI.color = Color.white;

        if (_creator.soundGroupsAreExpanded) {
            DTGUIHelper.BeginGroupedControls();

            DTGUIHelper.StartGroupHeader();
            EditorGUILayout.LabelField("Group Control");

            EditorGUILayout.EndVertical();

            _audioSourceTemplateNames = new List<string>();

            foreach (var temp in _creator.audioSourceTemplates) {
                if (temp == null) {
                    continue;
                }
                _audioSourceTemplateNames.Add(temp.name);
            }

            var audTemplatesMissing = false;

            if (Directory.Exists(MasterAudio.AudioSourceTemplateFolder)) {
                var audioSrcTemplates = Directory.GetFiles(MasterAudio.AudioSourceTemplateFolder, "*.prefab").Length;
                if (audioSrcTemplates > _creator.audioSourceTemplates.Count) {
                    audTemplatesMissing = true;
                    DTGUIHelper.ShowLargeBarAlert("There's " + (audioSrcTemplates - _creator.audioSourceTemplates.Count) + " Audio Source Template(s) that aren't set up in this MA prefab. Locate them");
                    DTGUIHelper.ShowLargeBarAlert("in DarkTonic/MasterAudio/Sources/Prefabs/AudioSourceTemplates and drag them in below.");
                }
            }

            Event aEvent;
            if (audTemplatesMissing) {
                // create groups start
                EditorGUILayout.BeginVertical();
                aEvent = Event.current;

                GUI.color = DTGUIHelper.DragAreaColor;

                var dragArea = GUILayoutUtility.GetRect(0f, 35f, GUILayout.ExpandWidth(true));
                GUI.Box(dragArea, "Drag prefabs here from Project View to create Group Templates!");

                GUI.color = Color.white;

                switch (aEvent.type) {
                    case EventType.DragUpdated:
                    case EventType.DragPerform:
                        if (!dragArea.Contains(aEvent.mousePosition)) {
                            break;
                        }

                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                        if (aEvent.type == EventType.DragPerform) {
                            DragAndDrop.AcceptDrag();

                            foreach (var dragged in DragAndDrop.objectReferences) {
                                var temp = dragged as GameObject;
                                if (temp == null) {
                                    continue;
                                }

                                AddAudioSourceTemplate(temp);
                            }
                        }
                        Event.current.Use();
                        break;
                }
                EditorGUILayout.EndVertical();
                // create groups end
            }

            if (_audioSourceTemplateNames.Count == 0) {
                DTGUIHelper.ShowRedError("You have no Audio Source Templates. Drag them in to create them.");
            } else {
                var audSrcTemplateIndex = _audioSourceTemplateNames.IndexOf(_creator.audioSourceTemplateName);
                if (audSrcTemplateIndex < 0) {
                    audSrcTemplateIndex = 0;
                    _creator.audioSourceTemplateName = _audioSourceTemplateNames[0];
                }

                var newIndex = EditorGUILayout.Popup("Audio Source Template", audSrcTemplateIndex, _audioSourceTemplateNames.ToArray());
                if (newIndex != audSrcTemplateIndex) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Audio Source Template");
                    _creator.audioSourceTemplateName = _audioSourceTemplateNames[newIndex];
                }
            }

            var newDragMode = (MasterAudio.DragGroupMode)EditorGUILayout.EnumPopup("Bulk Creation Mode", _creator.curDragGroupMode);
            if (newDragMode != _creator.curDragGroupMode) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Bulk Creation Mode");
                _creator.curDragGroupMode = newDragMode;
            }

            var bulkMode = DTGUIHelper.GetRestrictedAudioLocation("Variation Create Mode", _creator.bulkVariationMode);
            if (bulkMode != _creator.bulkVariationMode) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Variation Mode");
                _creator.bulkVariationMode = bulkMode;
            }

            // create groups start
            EditorGUILayout.BeginVertical();
            aEvent = Event.current;

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

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

                            foreach (var aClip in clips) {
                                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 (_groups.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You currently have no Dynamic Sound Groups created.");
            }

            int? indexToDelete = null;
            DTGUIHelper.ResetColors();

            GUI.color = Color.white;
            int? busToCreate = null;
            var isExistingBus = false;

            for (var i = 0; i < _groups.Count; i++) {
                var aGroup = _groups[i];

                var groupDirty = false;

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                GUILayout.Label(aGroup.name, GUILayout.MinWidth(150));

                GUILayout.FlexibleSpace();

                // find bus.
                var selectedBusIndex = aGroup.busIndex == -1 ? 0 : aGroup.busIndex;

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

                var busIndex = EditorGUILayout.Popup("", selectedBusIndex, busList.ToArray(), GUILayout.Width(busListWidth));
                if (busIndex == -1) {
                    busIndex = 0;
                }

                if (aGroup.busIndex != busIndex && busIndex != 1) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref groupDirty, 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 = DTGUIHelper.BrightTextColor;
                GUILayout.TextField(DTGUIHelper.DisplayVolumeNumber(aGroup.groupMasterVolume, sliderIndicatorChars), sliderIndicatorChars, EditorStyles.miniLabel, GUILayout.Width(sliderWidth));

                var newVol = DTGUIHelper.DisplayVolumeField(aGroup.groupMasterVolume, DTGUIHelper.VolumeFieldType.DynamicMixerGroup, MasterAudio.MixerWidthMode.Normal);
                if (newVol != aGroup.groupMasterVolume) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref groupDirty, aGroup, "change Group Volume");
                    aGroup.groupMasterVolume = newVol;
                }

                GUI.contentColor = Color.white;

                var buttonPressed = DTGUIHelper.AddDynamicGroupButtons(_creator);
                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 (groupDirty) {
                    EditorUtility.SetDirty(aGroup);
                }
            }

            if (busToCreate.HasValue) {
                CreateBus(busToCreate.Value, isExistingBus);
            }

            if (indexToDelete.HasValue) {
                AudioUndoHelper.DestroyForUndo(_groups[indexToDelete.Value].gameObject);
            }

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(10);

            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            if (GUILayout.Button(new GUIContent("Max Group Volumes", "Reset all group volumes to full"), EditorStyles.toolbarButton, GUILayout.Width(120))) {
                AudioUndoHelper.RecordObjectsForUndo(_groups.ToArray(), "Max Group Volumes");

                foreach (var aGroup in _groups) {
                    aGroup.groupMasterVolume = 1f;
                }
            }

            if (_creator.audioSourceTemplates.Count > 0 && !Application.isPlaying && _creator.transform.childCount > 0) {
                GUILayout.Space(10);

                GUI.contentColor = DTGUIHelper.BrightButtonColor;

                if (GUILayout.Button("Apply Audio Source Template to All", EditorStyles.toolbarButton, GUILayout.Width(190))) {
                    applyTemplateToAll = true;
                }

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

            //buses
            if (_creator.groupBuses.Count > 0) {
                DTGUIHelper.VerticalSpace(3);

                var voiceLimitedBuses = _creator.groupBuses.FindAll(delegate(GroupBus obj) {
                    return obj.voiceLimit >= 0;
                });

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Bus Control", GUILayout.Width(100));
                if (voiceLimitedBuses.Count > 0) {
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Stop Oldest", GUILayout.Width(100));
                    GUILayout.Space(234);
                }
                EditorGUILayout.EndHorizontal();

                int? busToDelete = null;

                for (var i = 0; i < _creator.groupBuses.Count; i++) {
                    DTGUIHelper.StartGroupHeader(1, false);
                    var aBus = _creator.groupBuses[i];

                    var showingMixer = _creator.ShouldShowUnityAudioMixerGroupAssignments && !aBus.isExisting;

                    if (showingMixer) {
                        EditorGUILayout.BeginVertical();
                        EditorGUILayout.BeginHorizontal();
                    } else {
                        EditorGUILayout.BeginHorizontal();
                    }

                    var newBusName = EditorGUILayout.TextField("", aBus.busName, GUILayout.MaxWidth(170));
                    if (newBusName != aBus.busName) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Bus Name");
                        aBus.busName = newBusName;
                    }

                    GUILayout.FlexibleSpace();

                    if (!aBus.isExisting) {
                        if (voiceLimitedBuses.Contains(aBus)) {
                            GUI.color = DTGUIHelper.BrightButtonColor;
                            var newMono = GUILayout.Toggle(aBus.stopOldest, new GUIContent("", "Stop Oldest"));
                            if (newMono != aBus.stopOldest) {
                                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Stop Oldest");
                                aBus.stopOldest = newMono;
                            }
                        }

                        GUI.color = Color.white;
                        GUILayout.Label("Voices");
                        GUI.color = DTGUIHelper.BrightButtonColor;

                        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) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Bus Voice Limit");
                            aBus.voiceLimit = busVoiceLimitIndex <= 0 ? -1 : busVoiceLimitIndex;
                        }

                        GUI.color = DTGUIHelper.BrightTextColor;

                        GUILayout.TextField(DTGUIHelper.DisplayVolumeNumber(aBus.volume, sliderIndicatorChars), sliderIndicatorChars, EditorStyles.miniLabel, GUILayout.Width(sliderWidth));

                        GUI.color = Color.white;
                        var newBusVol = DTGUIHelper.DisplayVolumeField(aBus.volume, DTGUIHelper.VolumeFieldType.Bus, MasterAudio.MixerWidthMode.Normal);
                        if (newBusVol != aBus.volume) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _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();
                    EditorGUILayout.EndVertical();
#if UNITY_5
                    if (!showingMixer) {
                        //EditorGUILayout.EndVertical();
                        continue;
                    }

                    var newChan = (AudioMixerGroup)EditorGUILayout.ObjectField(aBus.mixerChannel, typeof(AudioMixerGroup), false);
                    if (newChan != aBus.mixerChannel) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Bus Mixer Group");
                        aBus.mixerChannel = newChan;
                    }
                    EditorGUILayout.EndVertical();
#endif
                    //EditorGUILayout.EndVertical();
                    DTGUIHelper.AddSpaceForNonU5(2);
                }

                if (busToDelete.HasValue) {
                    DeleteBus(busToDelete.Value);
                }

#if UNITY_5
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(6);

                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                var buttonText = "Show Unity Mixer Groups";
                if (_creator.showUnityMixerGroupAssignment) {
                    buttonText = "Hide Unity Mixer Groups";
                }
                if (GUILayout.Button(new GUIContent(buttonText), EditorStyles.toolbarButton, GUILayout.Width(140))) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, buttonText);
                    _creator.showUnityMixerGroupAssignment = !_creator.showUnityMixerGroupAssignment;
                }

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

            DTGUIHelper.EndGroupedControls();
        }

        if (applyTemplateToAll) {
            AudioUndoHelper.RecordObjectsForUndo(_groups.ToArray(), "Apply Audio Source Template to All");

            foreach (var myGroup in _groups) {
                for (var v = 0; v < myGroup.transform.childCount; v++) {
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
                        Debug.LogError("This feature requires Unity 4 or higher.");
#else
                    var aVar = myGroup.transform.GetChild(v);
                    var oldAudio = aVar.GetComponent<AudioSource>();
                    CopyFromAudioSourceTemplate(_creator, oldAudio, true);
#endif
                }
            }
        }

        DTGUIHelper.VerticalSpace(3);
        DTGUIHelper.ResetColors();

        // Music playlist Start		
        EditorGUILayout.BeginHorizontal();
        EditorGUI.indentLevel = 0;  // Space will handle this for the header

        state = _creator.playListExpanded;
        text = "Dynamic Playlist Settings";

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state) {
            GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
        } else {
            GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
        }

        GUILayout.BeginHorizontal();

#if UNITY_3_5_7
        if (!state) {
            text += " (Click to expand)";
        }
#else
        text = "<b><size=11>" + text + "</size></b>";
#endif
        if (state) {
            text = "\u25BC " + text;
        } else {
            text = "\u25BA " + text;
        }
        if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
            state = !state;
        }

        GUILayout.Space(2f);


        if (state != _creator.playListExpanded) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Dynamic Playlist Settings");
            _creator.playListExpanded = state;
        }

        EditorGUILayout.EndHorizontal();
        GUI.color = Color.white;

        EditorGUILayout.EndHorizontal();

        if (_creator.playListExpanded) {
            DTGUIHelper.BeginGroupedControls();
            EditorGUI.indentLevel = 0;  // Space will handle this for the header

            if (_creator.musicPlaylists.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You currently have no Playlists set up.");
            }

            EditorGUI.indentLevel = 1;
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            var oldPlayExpanded = DTGUIHelper.Foldout(_creator.playlistEditorExp, string.Format("Playlists ({0})", _creator.musicPlaylists.Count));
            if (oldPlayExpanded != _creator.playlistEditorExp) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Playlists");
                _creator.playlistEditorExp = oldPlayExpanded;
            }

            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));

            const string buttonText = "Click to add new Playlist at the end";

            // Add button - Process presses later
            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            var addPressed = GUILayout.Button(new GUIContent("Add", buttonText),
                EditorStyles.toolbarButton);

            GUI.contentColor = DTGUIHelper.BrightButtonColor;
            var content = new GUIContent("Collapse", "Click to collapse all");
            var masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton);

            content = new GUIContent("Expand", "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton);
            if (masterExpand) {
                ExpandCollapseAllPlaylists(true);
            }
            if (masterCollapse) {
                ExpandCollapseAllPlaylists(false);
            }
            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndHorizontal();

            if (_creator.playlistEditorExp) {
                int? playlistToRemove = null;
                int? playlistToInsertAt = null;
                int? playlistToMoveUp = null;
                int? playlistToMoveDown = null;

                for (var i = 0; i < _creator.musicPlaylists.Count; i++) {
                    DTGUIHelper.StartGroupHeader();

                    var aList = _creator.musicPlaylists[i];

                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.BeginHorizontal();
                    aList.isExpanded = DTGUIHelper.Foldout(aList.isExpanded, "Playlist: " + aList.playlistName);

                    var playlistButtonPressed = DTGUIHelper.AddFoldOutListItemButtons(i, _creator.musicPlaylists.Count, "playlist", false, true);

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();

                    if (aList.isExpanded) {
                        EditorGUI.indentLevel = 0;
                        var newPlaylist = EditorGUILayout.TextField("Name", aList.playlistName);
                        if (newPlaylist != aList.playlistName) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Name");
                            aList.playlistName = newPlaylist;
                        }

                        var crossfadeMode = (MasterAudio.Playlist.CrossfadeTimeMode)EditorGUILayout.EnumPopup("Crossfade Mode", aList.crossfadeMode);
                        if (crossfadeMode != aList.crossfadeMode) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Crossfade Mode");
                            aList.crossfadeMode = crossfadeMode;
                        }
                        if (aList.crossfadeMode == MasterAudio.Playlist.CrossfadeTimeMode.Override) {
                            var newCf = EditorGUILayout.Slider("Crossfade time (sec)", aList.crossFadeTime, 0f, 10f);
                            // ReSharper disable once CompareOfFloatsByEqualityOperator
                            if (newCf != aList.crossFadeTime) {
                                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Crossfade time (sec)");
                                aList.crossFadeTime = newCf;
                            }
                        }

                        var newFadeIn = EditorGUILayout.Toggle("Fade In First Song", aList.fadeInFirstSong);
                        if (newFadeIn != aList.fadeInFirstSong) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Fade In First Song");
                            aList.fadeInFirstSong = newFadeIn;
                        }

                        var newFadeOut = EditorGUILayout.Toggle("Fade Out Last Song", aList.fadeOutLastSong);
                        if (newFadeOut != aList.fadeOutLastSong) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Fade Out Last Song");
                            aList.fadeOutLastSong = newFadeOut;
                        }

                        var newTransType = (MasterAudio.SongFadeInPosition)EditorGUILayout.EnumPopup("Song Transition Type", aList.songTransitionType);
                        if (newTransType != aList.songTransitionType) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Song Transition Type");
                            aList.songTransitionType = newTransType;
                        }
                        if (aList.songTransitionType == MasterAudio.SongFadeInPosition.SynchronizeClips) {
                            DTGUIHelper.ShowColorWarning("All clips must be of exactly the same length in this mode.");
                        }

                        EditorGUI.indentLevel = 0;
                        var newBulkMode = DTGUIHelper.GetRestrictedAudioLocation("Clip Create Mode", aList.bulkLocationMode);
                        if (newBulkMode != aList.bulkLocationMode) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Bulk Clip Mode");
                            aList.bulkLocationMode = newBulkMode;
                        }

                        var playlistHasResource = false;
                        foreach (var t in aList.MusicSettings) {
                            if (t.audLocation != MasterAudio.AudioLocation.ResourceFile) {
                                continue;
                            }
                            playlistHasResource = true;
                            break;
                        }

                        if (MasterAudio.HasAsyncResourceLoaderFeature() && playlistHasResource) {
                            if (!maInScene || !ma.resourceClipsAllLoadAsync) {
                                var newAsync = EditorGUILayout.Toggle(new GUIContent("Load Resources Async", "Checking this means Resource files in this Playlist will be loaded asynchronously."), aList.resourceClipsAllLoadAsync);
                                if (newAsync != aList.resourceClipsAllLoadAsync) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Load Resources Async");
                                    aList.resourceClipsAllLoadAsync = newAsync;
                                }
                            }
                        }
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(10);
                        GUI.contentColor = DTGUIHelper.BrightButtonColor;
                        if (GUILayout.Button(new GUIContent("Eq. Song Volumes"), EditorStyles.toolbarButton, GUILayout.Width(110))) {
                            EqualizePlaylistVolumes(aList.MusicSettings);
                        }

                        var hasExpanded = false;
                        foreach (var t in aList.MusicSettings) {
                            if (!t.isExpanded) {
                                continue;
                            }
                            hasExpanded = true;
                            break;
                        }

                        var theButtonText = hasExpanded ? "Collapse All" : "Expand All";

                        GUILayout.Space(10);
                        GUI.contentColor = DTGUIHelper.BrightButtonColor;
                        if (GUILayout.Button(new GUIContent(theButtonText), EditorStyles.toolbarButton, GUILayout.Width(100))) {
                            ExpandCollapseSongs(aList, !hasExpanded);
                        }
                        GUILayout.Space(10);
                        if (GUILayout.Button(new GUIContent("Sort Alpha"), EditorStyles.toolbarButton, GUILayout.Width(100))) {
                            SortSongsAlpha(aList);
                        }

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

                        EditorGUILayout.BeginVertical();
                        var anEvent = Event.current;

                        GUI.color = DTGUIHelper.DragAreaColor;

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

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

                                        AddSongToPlaylist(aList, aClip);
                                    }
                                }
                                Event.current.Use();
                                break;
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUI.indentLevel = 2;

                        int? addIndex = null;
                        int? removeIndex = null;
                        int? moveUpIndex = null;
                        int? moveDownIndex = null;

                        if (aList.MusicSettings.Count == 0) {
                            EditorGUI.indentLevel = 0;
                            DTGUIHelper.ShowLargeBarAlert("You currently have no songs in this Playlist.");
                        }

                        EditorGUI.indentLevel = 0;

                        for (var j = 0; j < aList.MusicSettings.Count; j++) {
                            DTGUIHelper.StartGroupHeader(1);
                            var aSong = aList.MusicSettings[j];
                            var clipName = "Empty";
                            switch (aSong.audLocation) {
                                case MasterAudio.AudioLocation.Clip:
                                    if (aSong.clip != null) {
                                        clipName = aSong.clip.name;
                                    }
                                    break;
                                case MasterAudio.AudioLocation.ResourceFile:
                                    if (!string.IsNullOrEmpty(aSong.resourceFileName)) {
                                        clipName = aSong.resourceFileName;
                                    }
                                    break;
                            }
                            EditorGUILayout.BeginHorizontal();
                            EditorGUI.indentLevel = 1;

                            aSong.songName = aSong.alias;
                            if (!string.IsNullOrEmpty(clipName) && string.IsNullOrEmpty(aSong.songName)) {
                                switch (aSong.audLocation) {
                                    case MasterAudio.AudioLocation.Clip:
                                        aSong.songName = clipName;
                                        break;
                                    case MasterAudio.AudioLocation.ResourceFile:
                                        aSong.songName = clipName;
                                        break;
                                }
                            }

                            var newSongExpanded = DTGUIHelper.Foldout(aSong.isExpanded, aSong.songName);
                            if (newSongExpanded != aSong.isExpanded) {
                                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Song expand");
                                aSong.isExpanded = newSongExpanded;
                            }

                            var songButtonPressed = DTGUIHelper.AddFoldOutListItemButtons(j, aList.MusicSettings.Count, "clip", false, true, allowPreview);
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndVertical();

                            if (aSong.isExpanded) {
                                EditorGUI.indentLevel = 0;

                                var newName = EditorGUILayout.TextField(new GUIContent("Song Alias (optional)", "When you 'Play song by name', Song Aliases will be searched first before audio file name."), aSong.alias);
                                if (newName != aSong.alias) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Song Id");
                                    aSong.alias = newName;
                                }

                                var oldLocation = aSong.audLocation;
                                var newClipSource = DTGUIHelper.GetRestrictedAudioLocation("Audio Origin", aSong.audLocation);
                                if (newClipSource != aSong.audLocation) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Audio Origin");
                                    aSong.audLocation = newClipSource;
                                }

                                switch (aSong.audLocation) {
                                    case MasterAudio.AudioLocation.Clip:
                                        var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", aSong.clip, typeof(AudioClip), true);
                                        if (newClip != aSong.clip) {
                                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Clip");
                                            aSong.clip = newClip;
                                            var cName = newClip == null ? "Empty" : newClip.name;
                                            aSong.songName = cName;
                                        }
                                        break;
                                    case MasterAudio.AudioLocation.ResourceFile:
                                        if (oldLocation != aSong.audLocation) {
                                            if (aSong.clip != null) {
                                                Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Playlist clip.");
                                            }
                                            aSong.clip = null;
                                            aSong.songName = string.Empty;
                                        }

                                        EditorGUILayout.BeginVertical();
                                        anEvent = Event.current;

                                        GUI.color = DTGUIHelper.DragAreaColor;
                                        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;
                                                        }

                                                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Resource Filename");

                                                        var unused = false;
                                                        var resourceFileName = DTGUIHelper.GetResourcePath(aClip, ref unused);
                                                        if (string.IsNullOrEmpty(resourceFileName)) {
                                                            resourceFileName = aClip.name;
                                                        }

                                                        aSong.resourceFileName = resourceFileName;
                                                        aSong.songName = aClip.name;
                                                    }
                                                }
                                                Event.current.Use();
                                                break;
                                        }
                                        EditorGUILayout.EndVertical();

                                        var newFilename = EditorGUILayout.TextField("Resource Filename", aSong.resourceFileName);
                                        if (newFilename != aSong.resourceFileName) {
                                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Resource Filename");
                                            aSong.resourceFileName = newFilename;
                                        }

                                        break;
                                }

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

                                var newPitch = DTGUIHelper.DisplayPitchField(aSong.pitch);
                                if (newPitch != aSong.pitch) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Pitch");
                                    aSong.pitch = newPitch;
                                }

                                if (aList.songTransitionType == MasterAudio.SongFadeInPosition.SynchronizeClips) {
                                    DTGUIHelper.ShowLargeBarAlert("All songs must loop in Synchronized Playlists when crossfade time is not zero. Auto-advance is disabled.");
                                } else {
                                    var newLoop = EditorGUILayout.Toggle("Loop Clip", aSong.isLoop);
                                    if (newLoop != aSong.isLoop) {
                                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Loop Clip");
                                        aSong.isLoop = newLoop;
                                    }
                                }

                                if (aList.songTransitionType == MasterAudio.SongFadeInPosition.NewClipFromBeginning) {
                                    var newStart = EditorGUILayout.FloatField("Start Time (seconds)", aSong.customStartTime, GUILayout.Width(300));
                                    if (newStart < 0) {
                                        newStart = 0f;
                                    }
                                    if (newStart != aSong.customStartTime) {
                                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Start Time (seconds)");
                                        aSong.customStartTime = newStart;
                                    }
                                }


                                EditorGUI.indentLevel = 0;
                                exp = EditorGUILayout.BeginToggleGroup("Song Started Event", aSong.songStartedEventExpanded);
                                if (exp != aSong.songStartedEventExpanded) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle expand Song Started Event");
                                    aSong.songStartedEventExpanded = exp;
                                }
                                GUI.color = Color.white;

                                if (aSong.songStartedEventExpanded) {
                                    EditorGUI.indentLevel = 1;
                                    DTGUIHelper.ShowColorWarning("When song starts, fire Custom Event below.");

                                    if (maInScene) {
                                        var existingIndex = _customEventNames.IndexOf(aSong.songStartedCustomEvent);

                                        int? customEventIndex = null;

                                        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 && aSong.songStartedCustomEvent == MasterAudio.NoGroupName) {
                                            customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                                        } else { // non-match
                                            noMatch = true;
                                            var newEventName = EditorGUILayout.TextField("Custom Event Name", aSong.songStartedCustomEvent);
                                            if (newEventName != aSong.songStartedCustomEvent) {
                                                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Custom Event Name");
                                                aSong.songStartedCustomEvent = 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, _creator, "change Custom Event");
                                            }
                                            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                                            if (customEventIndex.Value == -1) {
                                                aSong.songStartedCustomEvent = MasterAudio.NoGroupName;
                                            } else {
                                                aSong.songStartedCustomEvent = _customEventNames[customEventIndex.Value];
                                            }
                                        }
                                    } else {
                                        var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", aSong.songStartedCustomEvent);
                                        if (newCustomEvent != aSong.songStartedCustomEvent) {
                                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "Custom Event Name");
                                            aSong.songStartedCustomEvent = newCustomEvent;
                                        }
                                    }
                                }
                                EditorGUILayout.EndToggleGroup();

                                EditorGUI.indentLevel = 0;
                                exp = EditorGUILayout.BeginToggleGroup("Song Changed Event", aSong.songChangedEventExpanded);
                                if (exp != aSong.songChangedEventExpanded) {
                                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle expand Song Changed Event");
                                    aSong.songChangedEventExpanded = exp;
                                }
                                GUI.color = Color.white;

                                if (aSong.songChangedEventExpanded) {
                                    EditorGUI.indentLevel = 1;
                                    DTGUIHelper.ShowColorWarning("When song changes to another, fire Custom Event below.");
                                    DTGUIHelper.ShowLargeBarAlert("If you are using gapless transitions, Song Changed Event cannot be used.");

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

                                        int? customEventIndex = null;


                                        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 && aSong.songChangedCustomEvent == MasterAudio.NoGroupName) {
                                            customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray());
                                        } else { // non-match
                                            noMatch = true;
                                            var newEventName = EditorGUILayout.TextField("Custom Event Name", aSong.songChangedCustomEvent);
                                            if (newEventName != aSong.songChangedCustomEvent) {
                                                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Custom Event Name");
                                                aSong.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, _creator, "change Custom Event");
                                            }
                                            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                                            if (customEventIndex.Value == -1) {
                                                aSong.songChangedCustomEvent = MasterAudio.NoGroupName;
                                            } else {
                                                aSong.songChangedCustomEvent = _customEventNames[customEventIndex.Value];
                                            }
                                        }
                                    } else {
                                        var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", aSong.songChangedCustomEvent);
                                        if (newCustomEvent != aSong.songChangedCustomEvent) {
                                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "Custom Event Name");
                                            aSong.songChangedCustomEvent = newCustomEvent;
                                        }
                                    }
                                }
                                EditorGUILayout.EndToggleGroup();
                            }

                            switch (songButtonPressed) {
                                case DTGUIHelper.DTFunctionButtons.Add:
                                    addIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Remove:
                                    removeIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.ShiftUp:
                                    moveUpIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.ShiftDown:
                                    moveDownIndex = j;
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Play:
                                    StopPreviewer();
                                    switch (aSong.audLocation) {
                                        case MasterAudio.AudioLocation.Clip:
                                            GetPreviewer().PlayOneShot(aSong.clip, aSong.volume);
                                            break;
                                        case MasterAudio.AudioLocation.ResourceFile:
                                            GetPreviewer().PlayOneShot(Resources.Load(aSong.resourceFileName) as AudioClip, aSong.volume);
                                            break;
                                    }
                                    break;
                                case DTGUIHelper.DTFunctionButtons.Stop:
                                    GetPreviewer().clip = null;
                                    StopPreviewer();
                                    break;
                            }

                            EditorGUILayout.EndVertical();
                            DTGUIHelper.AddSpaceForNonU5(2);
                        }

                        if (addIndex.HasValue) {
                            var mus = new MusicSetting();
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "add song");
                            aList.MusicSettings.Insert(addIndex.Value + 1, mus);
                        } else if (removeIndex.HasValue) {
                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "delete song");
                            aList.MusicSettings.RemoveAt(removeIndex.Value);
                        } else if (moveUpIndex.HasValue) {
                            var item = aList.MusicSettings[moveUpIndex.Value];

                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "shift up song");

                            aList.MusicSettings.Insert(moveUpIndex.Value - 1, item);
                            aList.MusicSettings.RemoveAt(moveUpIndex.Value + 1);
                        } else if (moveDownIndex.HasValue) {
                            var index = moveDownIndex.Value + 1;
                            var item = aList.MusicSettings[index];

                            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "shift down song");

                            aList.MusicSettings.Insert(index - 1, item);
                            aList.MusicSettings.RemoveAt(index + 1);
                        }
                    }

                    switch (playlistButtonPressed) {
                        case DTGUIHelper.DTFunctionButtons.Remove:
                            playlistToRemove = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.Add:
                            playlistToInsertAt = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.ShiftUp:
                            playlistToMoveUp = i;
                            break;
                        case DTGUIHelper.DTFunctionButtons.ShiftDown:
                            playlistToMoveDown = i;
                            break;
                    }

                    EditorGUILayout.EndVertical();
                    DTGUIHelper.AddSpaceForNonU5(4);
                }


                if (playlistToRemove.HasValue) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "delete Playlist");

                    _creator.musicPlaylists.RemoveAt(playlistToRemove.Value);
                }
                if (playlistToInsertAt.HasValue) {
                    var pl = new MasterAudio.Playlist();
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "add Playlist");
                    _creator.musicPlaylists.Insert(playlistToInsertAt.Value + 1, pl);
                }
                if (playlistToMoveUp.HasValue) {
                    var item = _creator.musicPlaylists[playlistToMoveUp.Value];
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "shift up Playlist");
                    _creator.musicPlaylists.Insert(playlistToMoveUp.Value - 1, item);
                    _creator.musicPlaylists.RemoveAt(playlistToMoveUp.Value + 1);
                }
                if (playlistToMoveDown.HasValue) {
                    var index = playlistToMoveDown.Value + 1;
                    var item = _creator.musicPlaylists[index];

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "shift down Playlist");

                    _creator.musicPlaylists.Insert(index - 1, item);
                    _creator.musicPlaylists.RemoveAt(index + 1);
                }
            }

            if (addPressed) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "add Playlist");
                _creator.musicPlaylists.Add(new MasterAudio.Playlist());
            }

            DTGUIHelper.EndGroupedControls();
        }
        // Music playlist End

        EditorGUI.indentLevel = 0;
        // Show Custom Events

        DTGUIHelper.VerticalSpace(3);
        DTGUIHelper.ResetColors();

        state = _creator.showCustomEvents;
        text = "Dynamic Custom Events";

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state) {
            GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
        } else {
            GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
        }

        GUILayout.BeginHorizontal();

#if UNITY_3_5_7
        if (!state) {
            text += " (Click to expand)";
        }
#else
        text = "<b><size=11>" + text + "</size></b>";
#endif
        if (state) {
            text = "\u25BC " + text;
        } else {
            text = "\u25BA " + text;
        }
        if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
            state = !state;
        }

        GUILayout.Space(2f);

        if (_creator.showCustomEvents != state) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle Dynamic Custom Events");
            _creator.showCustomEvents = state;
        }

        EditorGUILayout.EndHorizontal();
        GUI.color = Color.white;

        if (_creator.showCustomEvents) {
            DTGUIHelper.BeginGroupedControls();
            var newEvent = EditorGUILayout.TextField("New Event Name", _creator.newEventName);
            if (newEvent != _creator.newEventName) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change New Event Name");
                _creator.newEventName = newEvent;
            }

            GUI.contentColor = DTGUIHelper.BrightButtonColor;

            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(10);
            if (GUILayout.Button("Create New Event", EditorStyles.toolbarButton, GUILayout.Width(100))) {
                CreateCustomEvent(_creator.newEventName);
            }

            GUILayout.Space(10);
            GUI.contentColor = DTGUIHelper.BrightButtonColor;

            var hasExpanded = false;
            foreach (var t in _creator.customEventsToCreate) {
                if (!t.eventExpanded) {
                    continue;
                }
                hasExpanded = true;
                break;
            }

            var buttonText = hasExpanded ? "Collapse All" : "Expand All";

            if (GUILayout.Button(buttonText, EditorStyles.toolbarButton, GUILayout.Width(100))) {
                ExpandCollapseCustomEvents(!hasExpanded);
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Sort Alpha", EditorStyles.toolbarButton, GUILayout.Width(100))) {
                SortCustomEvents();
            }

            GUI.contentColor = Color.white;

            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = 0;
            if (_creator.customEventsToCreate.Count == 0) {
                DTGUIHelper.ShowLargeBarAlert("You currently have no custom events defined here.");
            }

            int? indexToDelete = null;
            int? indexToRename = null;

            for (var i = 0; i < _creator.customEventsToCreate.Count; i++) {
                DTGUIHelper.AddSpaceForNonU5(2);
                DTGUIHelper.StartGroupHeader();
                EditorGUI.indentLevel = 1;
                var anEvent = _creator.customEventsToCreate[i];

                EditorGUILayout.BeginHorizontal();
                exp = DTGUIHelper.Foldout(anEvent.eventExpanded, anEvent.EventName);
                if (exp != anEvent.eventExpanded) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "toggle expand Custom Event");
                    anEvent.eventExpanded = exp;
                }

                GUILayout.FlexibleSpace();
                var newName = GUILayout.TextField(anEvent.ProspectiveName, GUILayout.Width(170));
                if (newName != anEvent.ProspectiveName) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Proposed Event Name");
                    anEvent.ProspectiveName = newName;
                }

                var buttonPressed = DTGUIHelper.AddDeleteIcon(true, "Custom Event");

                switch (buttonPressed) {
                    case DTGUIHelper.DTFunctionButtons.Remove:
                        indexToDelete = i;
                        break;
                    case DTGUIHelper.DTFunctionButtons.Rename:
                        indexToRename = i;
                        break;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                if (!anEvent.eventExpanded) {
                    EditorGUILayout.EndVertical();
                    continue;
                }

                EditorGUI.indentLevel = 0;
                var rcvMode = (MasterAudio.CustomEventReceiveMode)EditorGUILayout.EnumPopup("Send To Receivers", anEvent.eventReceiveMode);
                if (rcvMode != anEvent.eventReceiveMode) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Send To Receivers");
                    anEvent.eventReceiveMode = rcvMode;
                }

                if (rcvMode == MasterAudio.CustomEventReceiveMode.WhenDistanceLessThan || rcvMode == MasterAudio.CustomEventReceiveMode.WhenDistanceMoreThan) {
                    var newDist = EditorGUILayout.Slider("Distance Threshold", anEvent.distanceThreshold, 0f, float.MaxValue);
                    if (newDist != anEvent.distanceThreshold) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _creator, "change Distance Threshold");
                        anEvent.distanceThreshold = newDist;
                    }
                }

                EditorGUILayout.EndVertical();
            }

            if (indexToDelete.HasValue) {
                _creator.customEventsToCreate.RemoveAt(indexToDelete.Value);
            }
            if (indexToRename.HasValue) {
                RenameEvent(_creator.customEventsToCreate[indexToRename.Value]);
            }

            DTGUIHelper.EndGroupedControls();
        }

        // End Show Custom Events

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

        //DrawDefaultInspector();
    }
コード例 #13
0
    // ReSharper disable once UnusedMember.Local
    private static GameObject SelectedAudioSourceTemplate(DynamicSoundGroupCreator creator) {
        if (creator.audioSourceTemplates.Count == 0) {
            return null;
        }

        var selTemplate = creator.audioSourceTemplates.Find(delegate(GameObject obj) {
            return obj.name == creator.audioSourceTemplateName;
        });

        return selTemplate;
    }
コード例 #14
0
    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();
    }
コード例 #15
0
 public void ExpandCollapseAllSoundGroups(DynamicSoundGroupCreator _creator, bool shouldExpand)
 {
     for (var i = 0; i < _creator.soundGroupsToCreate.Count; i++) {
         _creator.soundGroupsToCreate[i].isExpanded = shouldExpand;
     }
 }
コード例 #16
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 1;
        var isDirty = false;

        _creator = (DynamicSoundGroupCreator)target;

        var isInProjectView = GUIHelper.IsPrefabInProjectView(_creator);

        if (_creator.logoTexture != null) {
            GUIHelper.ShowHeaderTexture(_creator.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) {
            GUIHelper.ShowColorWarning("*Items will be created as soon as this object is in the Scene.");
        } else {
            GUIHelper.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) {
            GUIHelper.ShowColorWarning("*Items will be deleted when the Scene changes.");
        } else {
            GUIHelper.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) {
                GUIHelper.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 (GUIHelper.AddDynamicDeleteIcon(_creator, "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) {
                GUIHelper.ShowLargeBarAlert("*You are in Project View and cannot create or navigate Groups.");
                GUIHelper.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) {
                    GUIHelper.ShowLargeBarAlert("You have data in an old format. Pull this prefab into the Scene, then Upgrade Data.");
                } else {
                    GUIHelper.ShowRedError("You have data in an old format. It will not be used as is.");
                    GUIHelper.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)
            {
                GUIHelper.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 = GUIHelper.AddDynamicGroupButtons(_creator);
                EditorGUILayout.EndHorizontal();

                switch (buttonPressed)
                {
                    case GUIHelper.DTFunctionButtons.Go:
                        Selection.activeGameObject = aGroup.gameObject;
                        break;
                    case GUIHelper.DTFunctionButtons.Remove:
                        indexToDelete = i;
                        break;
                    case GUIHelper.DTFunctionButtons.Play:
                        PreviewGroup(aGroup);
                        break;
                    case GUIHelper.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 {
                        GUIHelper.ShowColorWarning("Existing bus. No control.");
                    }

                    if (GUIHelper.AddDynamicDeleteIcon(_creator, "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) {
                GUIHelper.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 = GUIHelper.AddCustomEventDeleteIcon(true);

                switch (buttonPressed) {
                    case GUIHelper.DTFunctionButtons.Remove:
                        indexToDelete = i;
                        break;
                    case GUIHelper.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();
    }