Exemplo n.º 1
0
    private void CreateCategory()
    {
        if (string.IsNullOrEmpty(_pool.newCategoryName))
        {
            DTInspectorUtility.ShowAlert("You cannot have a blank Category name.");
            return;
        }

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var c = 0; c < _pool._categories.Count; c++)
        {
            var cat = _pool._categories[c];
            // ReSharper disable once InvertIf
            if (cat.CatName == _pool.newCategoryName)
            {
                DTInspectorUtility.ShowAlert("You already have a Category named '" + _pool.newCategoryName + "'. Category names must be unique.");
                return;
            }
        }

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "Create New Category");

        var newCat = new PoolBossCategory {
            CatName         = _pool.newCategoryName,
            ProspectiveName = _pool.newCategoryName,
        };

        _pool._categories.Add(newCat);
    }
Exemplo n.º 2
0
    private void CreateCategory()
    {
        if (string.IsNullOrEmpty(_pool.newCategoryName))
        {
            DTPoolBossInspectorUtility.ShowAlert(PoolBossLang.ErrorBlankCategoryName);
            return;
        }

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var c = 0; c < _pool._categories.Count; c++)
        {
            var cat = _pool._categories[c];
            // ReSharper disable once InvertIf
            if (cat.CatName == _pool.newCategoryName)
            {
                DTPoolBossInspectorUtility.ShowAlert(string.Format(PoolBossLang.ErrorDuplicateCategoryName, _pool.newCategoryName));
                return;
            }
        }

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.CreateNewCategory);

        var newCat = new PoolBossCategory
        {
            CatName         = _pool.newCategoryName,
            ProspectiveName = _pool.newCategoryName,
        };

        _pool._categories.Add(newCat);
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 0;

        var kill = (KillableChildVisibility)target;

        var isDirty = false;

        WorldVariableTracker.ClearInGamePlayerStats();

        LevelSettings.Instance = null;         // clear cached version
        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        var newKillableToAlert = (Killable)EditorGUILayout.ObjectField("Killable To Alert", kill.killableWithRenderer, typeof(Killable), true);

        if (newKillableToAlert != kill.killableWithRenderer)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, kill, "change Killable To Alert");
            kill.killableWithRenderer = newKillableToAlert;
        }

        if (GUI.changed || isDirty)
        {
            EditorUtility.SetDirty(target);             // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 4
0
    private void AddPoolItem(Object o)
    {
        // ReSharper disable once PossibleNullReferenceException
        var go = (o as GameObject);

        if (go == null)
        {
            DTPoolBossInspectorUtility.ShowAlert(PoolBossLang.DraggedNotGameObject);
            return;
        }

        var newItem = new PoolBossItem
        {
            categoryName = _pool.addToCategoryName,
            prefabSource = _pool.newItemPrefabSource
        };

        switch (_pool.newItemPrefabSource)
        {
        case PoolBoss.PrefabSource.Prefab:
            newItem.prefabTransform = go.transform;
            break;

#if ADDRESSABLES_ENABLED
        case PoolBoss.PrefabSource.Addressable:
            newItem.prefabAddressable =
                PoolBossAddressableEditorHelper.CreateAssetReferenceFromObject(go.transform);
            break;
#endif
        }

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.AddPoolIem);

        _pool.poolItems.Add(newItem);
    }
    public override void OnInspectorGUI()
    {
        _settings = (TriggeredDespawner)target;
        LevelSettings.Instance = null;         // clear cached version

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        _isDirty = false;

        EditorGUI.indentLevel = 0;

        var hadNoListener = _settings.listener == null;
        var newListener   = (TriggeredDespawnerListener)EditorGUILayout.ObjectField("Listener", _settings.listener, typeof(TriggeredDespawnerListener), true);

        if (newListener != _settings.listener)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "assign Listener");
            _settings.listener = newListener;

            if (hadNoListener && _settings.listener != null)
            {
                _settings.listener.sourceDespawnerName = _settings.transform.name;
            }
        }

        var changedList = new List <bool>
        {
            RenderEventTypeControls(_settings.invisibleSpec, "Invisible Event", TriggeredSpawner.EventType.Invisible),
            RenderEventTypeControls(_settings.mouseOverSpec, "Mouse Over (Legacy) Event",
                                    TriggeredSpawner.EventType.MouseOver_Legacy),
            RenderEventTypeControls(_settings.mouseClickSpec, "Mouse Click (Legacy) Event",
                                    TriggeredSpawner.EventType.MouseClick_Legacy),
            RenderEventTypeControls(_settings.collisionSpec, "Collision Enter Event",
                                    TriggeredSpawner.EventType.OnCollision),
            RenderEventTypeControls(_settings.triggerEnterSpec, "Trigger Enter Event",
                                    TriggeredSpawner.EventType.OnTriggerEnter),
            RenderEventTypeControls(_settings.triggerExitSpec, "Trigger Exit Event",
                                    TriggeredSpawner.EventType.OnTriggerExit),
            RenderEventTypeControls(_settings.onClickSpec, "NGUI OnClick Event", TriggeredSpawner.EventType.OnClick_NGUI),
            RenderEventTypeControls(_settings.collision2dSpec, "2D Collision Enter Event",
                                    TriggeredSpawner.EventType.OnCollision2D),
            RenderEventTypeControls(_settings.triggerEnter2dSpec, "2D Trigger Enter Event",
                                    TriggeredSpawner.EventType.OnTriggerEnter2D),
            RenderEventTypeControls(_settings.triggerExit2dSpec, "2D Trigger Exit Event",
                                    TriggeredSpawner.EventType.OnTriggerExit2D)
        };

#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2
        // not supported
#else
#endif

        if (GUI.changed || _isDirty || changedList.Contains(true))
        {
            EditorUtility.SetDirty(target);             // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 6
0
    private void ExpandCollapseAll(WavePrefabPool pool, bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand / collapse all");

        foreach (var poolItem in pool.poolItems)
        {
            poolItem.isExpanded = isExpand;
        }
    }
Exemplo n.º 7
0
    private void ExpandCollapseAll(bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "toggle expand / collapse all World Variables");

        foreach (var variable in _stats)
        {
            variable.isExpanded = isExpand;
        }
    }
Exemplo n.º 8
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 0;

        var settings = (TimedDespawner)target;

        LevelSettings.Instance = null;         // clear cached version

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        var isDirty = false;

        EditorGUILayout.Separator();

        var newStartTimer = EditorGUILayout.Toggle("Start Timer On Awake", settings.StartTimerOnSpawn);

        if (newStartTimer != settings.StartTimerOnSpawn)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, settings, "toggle Start Timer On Awake");
            settings.StartTimerOnSpawn = newStartTimer;
        }

        var newLifeSeconds = EditorGUILayout.Slider("Despawn Timer (sec)", settings.LifeSeconds, .1f, 50f);

        if (newLifeSeconds != settings.LifeSeconds)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, settings, "change Despawn Timer");
            settings.LifeSeconds = newLifeSeconds;
        }

        var hadNoListener = settings.listener == null;
        var newListener   = (TimedDespawnerListener)EditorGUILayout.ObjectField("Listener", settings.listener, typeof(TimedDespawnerListener), true);

        if (newListener != settings.listener)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, settings, "assign Listener");
            settings.listener = newListener;

            if (hadNoListener && settings.listener != null)
            {
                settings.listener.sourceDespawnerName = settings.transform.name;
            }
        }

        if (GUI.changed || isDirty)
        {
            EditorUtility.SetDirty(target);             // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 0;

        var ma = MasterAudio.Instance;

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

        ButtonClicker sounds = (ButtonClicker)target;

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

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

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

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

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

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

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

        this.Repaint();

        //DrawDefaultInspector();
    }
Exemplo n.º 10
0
    private void ExpandCollapseAll(bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand / collapse all Pool Boss Items");

        if (isExpand)
        {
            _pool.poolItemsExpanded = true;
        }

        foreach (var item in _pool.poolItems)
        {
            item.isExpanded = isExpand;
        }
    }
Exemplo n.º 11
0
    private void AddActiveLimit(string modifierName, WavePrefabPoolItem spec)
    {
        if (spec.activeItemCriteria.HasKey(modifierName))
        {
            DTInspectorUtility.ShowAlert("This item already has a Active Limit for World Variable: " + modifierName + ". Please modify the existing one instead.");
            return;
        }

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Active Limit");

        var myVar = WorldVariableTracker.GetWorldVariableScript(modifierName);

        spec.activeItemCriteria.statMods.Add(new WorldVariableRange(modifierName, myVar.varType));
    }
Exemplo n.º 12
0
    private void ExpandCollapseCategory(string category, bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand / collapse all items in Category");

        foreach (var item in _pool.poolItems)
        {
            if (item.categoryName != category)
            {
                continue;
            }

            item.isExpanded = isExpand;
        }
    }
Exemplo n.º 13
0
    private void ExpandCollapseAll(bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleItems);

        foreach (var cat in _pool._categories)
        {
            cat.IsExpanded = isExpand;
        }

        foreach (var item in _pool.poolItems)
        {
            item.isExpanded = isExpand;
        }
    }
Exemplo n.º 14
0
    private void AddPoolItem(Object o)
    {
        // ReSharper disable once PossibleNullReferenceException
        var go = (o as GameObject);

        if (go == null)
        {
            DTInspectorUtility.ShowAlert("You dragged an object which was not a Game Object. Not adding to Prefab Pool.");
            return;
        }

        var newItem = new WavePrefabPoolItem();

        newItem.prefabToSpawn = go.transform;

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Prefab Pool Item");
        _settings.poolItems.Add(newItem);
    }
Exemplo n.º 15
0
    private void AddPoolItem(Object o)
    {
        // ReSharper disable once PossibleNullReferenceException
        var go = (o as GameObject);

        if (go == null)
        {
            DTPoolBossInspectorUtility.ShowAlert("You dragged an object which was not a Game Object. Not adding to Pool Boss.");
            return;
        }

        var newItem = new PoolBossItem {
            prefabTransform = go.transform
        };

        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "add Pool Boss Item");

        _pool.poolItems.Add(newItem);
    }
Exemplo n.º 16
0
    private void ExpandCollapseCategory(string category, bool isExpand)
    {
        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleItemsInCategory);

        foreach (var cat in _pool._categories)
        {
            if (cat.CatName != category)
            {
                continue;
            }

            cat.IsExpanded = isExpand;
        }

        foreach (var item in _pool.poolItems)
        {
            if (item.categoryName != category)
            {
                continue;
            }

            item.isExpanded = isExpand;
        }
    }
Exemplo n.º 17
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        _pool = (PoolBoss)target;

        _isDirty = false;
        LevelSettings.Instance = null; // clear cached version

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        var isInProjectView = DTInspectorUtility.IsPrefabInProjectView(_pool);

        if (isInProjectView)
        {
            DTInspectorUtility.ShowRedErrorBox("You have selected the PoolBoss prefab in Project View. Please select the one in your Scene to edit.");
            return;
        }

        var catNames = new List <string>(_pool._categories.Count);

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < _pool._categories.Count; i++)
        {
            catNames.Add(_pool._categories[i].CatName);
        }

        if (!Application.isPlaying)
        {
            DTInspectorUtility.StartGroupHeader();
            var newCat = EditorGUILayout.TextField("New Category Name", _pool.newCategoryName);
            if (newCat != _pool.newCategoryName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change New Category Name");
                _pool.newCategoryName = newCat;
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginHorizontal();
            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            GUILayout.Space(10);
            if (GUILayout.Button("Create New Category", EditorStyles.toolbarButton, GUILayout.Width(130)))
            {
                CreateCategory();
            }
            GUI.contentColor = Color.white;

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            DTInspectorUtility.AddSpaceForNonU5();
            DTInspectorUtility.ResetColors();

            var selCatIndex = catNames.IndexOf(_pool.addToCategoryName);

            if (selCatIndex == -1)
            {
                selCatIndex = 0;
                _isDirty    = true;
            }

            GUI.backgroundColor = DTInspectorUtility.BrightButtonColor;

            var newIndex = EditorGUILayout.Popup("Default Item Category", selCatIndex, catNames.ToArray());
            if (newIndex != selCatIndex)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Default Item Category");
                _pool.addToCategoryName = catNames[newIndex];
            }
            GUI.backgroundColor = Color.white;
            GUI.contentColor    = Color.white;
        }

        GUI.contentColor = Color.white;

        if (!Application.isPlaying)
        {
            var maxFrames = Math.Min(100, _pool.poolItems.Count);
            maxFrames = Math.Max(1, maxFrames);
            var newFrames = EditorGUILayout.IntSlider(new GUIContent("Initialize Time (Frames)", "You can increase this value to make the initial pool creation take more frames. Defaults to 1. Max of the 100 or number of different prefabs, whichever is less."), _pool.framesForInit, 1, maxFrames);
            if (newFrames != _pool.framesForInit)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Initialize Time (Frames)");
                _pool.framesForInit = newFrames;
            }
        }

        PoolBossItem     itemToRemove     = null;
        int?             indexToInsertAt  = null;
        PoolBossCategory selectedCategory = null;
        PoolBossItem     itemToClone      = null;

        PoolBossCategory catEditing  = null;
        PoolBossCategory catRenaming = null;

        PoolBossCategory catToDelete = null;
        int?indexToShiftUp           = null;
        int?indexToShiftDown         = null;

        var visiblePoolItems = _pool.poolItems;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < visiblePoolItems.Count; i++)
        {
            var item = visiblePoolItems[i];
            if (catNames.Contains(item.categoryName))
            {
                continue;
            }

            item.categoryName = catNames[0];
            _isDirty          = true;
        }

        var newAutoAdd = EditorGUILayout.Toggle(new GUIContent("Auto-Add Missing Items", "Auto-Add Missing Items to top Category"), _pool.autoAddMissingPoolItems);

        if (newAutoAdd != _pool.autoAddMissingPoolItems)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Auto-Add Missing Items");
            _pool.autoAddMissingPoolItems = newAutoAdd;
        }

        var newLog = EditorGUILayout.Toggle("Log Messages", _pool.logMessages);

        if (newLog != _pool.logMessages)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Log Messages");
            _pool.logMessages = newLog;
        }

        var newFilter = EditorGUILayout.Toggle("Use Text Item Filter", _pool.useTextFilter);

        if (newFilter != _pool.useTextFilter)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Use Text Item Filter");
            _pool.useTextFilter = newFilter;
        }

        bool hasFiltered = false;

        if (_pool.useTextFilter)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.Label("Text Group Filter", GUILayout.Width(140));
            var newTextFilter = GUILayout.TextField(_pool.textFilter, GUILayout.Width(180));
            if (newTextFilter != _pool.textFilter)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Text Item Filter");
                _pool.textFilter = newTextFilter;
            }
            GUILayout.Space(10);
            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(70)))
            {
                _pool.textFilter = string.Empty;
            }
            GUI.contentColor = Color.white;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            var unfilteredCount = visiblePoolItems.Count;

            if (!string.IsNullOrEmpty(_pool.textFilter))
            {
                visiblePoolItems = visiblePoolItems.FindAll(delegate(PoolBossItem x) {
                    return(x.prefabTransform != null && x.prefabTransform.name.IndexOf(_pool.textFilter, StringComparison.OrdinalIgnoreCase) >= 0);
                });
            }

            var hiddenCount = unfilteredCount - visiblePoolItems.Count;
            if (hiddenCount > 0)
            {
                DTInspectorUtility.ShowLargeBarAlertBox(string.Format("{0}/{1} item(s) filtered out.", hiddenCount, unfilteredCount));
                hasFiltered = true;
            }
        }

        var hadNoListener = _pool.listener == null;
        var newListener   = (PoolBossListener)EditorGUILayout.ObjectField("Listener", _pool.listener, typeof(PoolBossListener), true);

        if (newListener != _pool.listener)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "assign Listener");
            _pool.listener = newListener;
            if (hadNoListener && _pool.listener != null)
            {
                _pool.listener.sourceTransName = _pool.transform.name;
            }
        }

        var newShow = EditorGUILayout.Toggle("Show Legend", _pool.showLegend);

        if (newShow != _pool.showLegend)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Show Legend");
            _pool.showLegend = newShow;
        }

        if (_pool.showLegend)
        {
            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            DTInspectorUtility.BeginGroupedControls();

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(6);
            GUILayout.Button(
                new GUIContent(CoreGameKitInspectorResources.DamageTexture,
                               "Click to deal 1 damage to all Killables"), EditorStyles.toolbarButton, GUILayout.Width(24));
            GUILayout.Label("Deal 1 Damage To All");

            GUILayout.Space(6);
            GUILayout.Button(
                new GUIContent(CoreGameKitInspectorResources.KillTexture, "Click to kill all Killables"),
                EditorStyles.toolbarButton, GUILayout.Width(24));
            GUILayout.Label("Kill All");

            GUILayout.Space(6);
            GUILayout.Button(
                new GUIContent(CoreGameKitInspectorResources.DespawnTexture, "Click to despawn prefabs"),
                EditorStyles.toolbarButton, GUILayout.Width(24));
            GUILayout.Label("Despawn All");

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            DTInspectorUtility.EndGroupedControls();
            EditorGUILayout.Separator();
        }

        EditorGUI.indentLevel = 0;
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Actions", GUILayout.Width(100));
        GUI.contentColor = DTInspectorUtility.BrightButtonColor;

        GUILayout.FlexibleSpace();

        var allExpanded = true;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < _pool._categories.Count; i++)
        {
            if (_pool._categories[i].IsExpanded)
            {
                continue;
            }
            allExpanded = false;
            break;
        }

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < visiblePoolItems.Count; i++)
        {
            if (visiblePoolItems[i].isExpanded)
            {
                continue;
            }
            allExpanded = false;
            break;
        }

        if (Application.isPlaying)
        {
            if (GUILayout.Button(new GUIContent("Clear Peaks"), EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                ClearAllPeaks();
                _isDirty = true;
            }

            GUILayout.Space(6);
        }

        var buttonTooltip = allExpanded ? "Click to collapse all categories and items" : "Click to expand all categories and items";
        var buttonText    = allExpanded ? "Collapse All" : "Expand All";

        if (GUILayout.Button(new GUIContent(buttonText, buttonTooltip), EditorStyles.toolbarButton, GUILayout.Width(80)))
        {
            ExpandCollapseAll(!allExpanded);
        }

        if (Application.isPlaying)
        {
            if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DamageTexture, "Click to deal 1 damage to all Killables"), EditorStyles.toolbarButton, GUILayout.Width(24)))
            {
                SpawnUtility.DamageAllPrefabs(1);
                _isDirty = true;
            }

            if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.KillTexture, "Click to kill all Killables"), EditorStyles.toolbarButton, GUILayout.Width(24)))
            {
                SpawnUtility.KillAllPrefabs();
                _isDirty = true;
            }

            if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DespawnTexture, "Click to despawn prefabs"), EditorStyles.toolbarButton, GUILayout.Width(24)))
            {
                SpawnUtility.DespawnAllPrefabs();
                _isDirty = true;
            }
            GUILayout.Space(6);
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();

        GUI.backgroundColor = Color.white;

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUI.color = DTInspectorUtility.DragAreaColor;
            var dragArea = GUILayoutUtility.GetRect(0f, 30f, GUILayout.ExpandWidth(true));
            GUI.Box(dragArea, "Drag prefabs here in bulk to add them to the Pool!");
            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)
                    {
                        AddPoolItem(dragged);
                    }
                }
                Event.current.Use();
                break;
            }
            GUILayout.Space(4);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            DTInspectorUtility.VerticalSpace(4);
        }

        GUI.backgroundColor = Color.white;
        GUI.contentColor    = Color.white;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var c = 0; c < _pool._categories.Count; c++)
        {
            var cat = _pool._categories[c];

            EditorGUI.indentLevel = 0;

            var matchingItems = new List <PoolBossItem>();
            matchingItems.AddRange(visiblePoolItems);
            matchingItems.RemoveAll(delegate(PoolBossItem x) {
                return(x.categoryName != cat.CatName);
            });

            var hasItems = matchingItems.Count > 0;

            EditorGUILayout.BeginHorizontal();

            if (!cat.IsEditing || Application.isPlaying)
            {
                var catName = cat.CatName;

                catName += ": " + matchingItems.Count + " item" + ((matchingItems.Count != 1) ? "s" : "");

                var state = cat.IsExpanded;
                var text  = catName;

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

                text = "<b><size=11>" + text + "</size></b>";

                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 != cat.IsExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand Pool Boss Category");
                    cat.IsExpanded = state;
                }

                var catItemsCollapsed = true;

                for (var i = 0; i < visiblePoolItems.Count; i++)
                {
                    var item = visiblePoolItems[i];
                    if (item.categoryName != cat.CatName)
                    {
                        continue;
                    }

                    if (!item.isExpanded)
                    {
                        continue;
                    }
                    catItemsCollapsed = false;
                    break;
                }

                GUI.backgroundColor = Color.white;

                var tooltip = catItemsCollapsed ? "Click to expand all items in this category" : "Click to collapse all items in this category";
                var btnText = catItemsCollapsed ? "Expand" : "Collapse";

                GUI.contentColor = DTInspectorUtility.BrightButtonColor;
                if (GUILayout.Button(new GUIContent(btnText, tooltip), EditorStyles.toolbarButton, GUILayout.Width(60), GUILayout.Height(16)))
                {
                    ExpandCollapseCategory(cat.CatName, catItemsCollapsed);
                }
                GUI.contentColor = Color.white;

                if (!Application.isPlaying)
                {
                    if (c > 0)
                    {
                        // the up arrow.
                        var upArrow = CoreGameKitInspectorResources.UpArrowTexture;
                        if (GUILayout.Button(new GUIContent(upArrow, "Click to shift Category up"),
                                             EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16)))
                        {
                            indexToShiftUp = c;
                        }
                    }
                    else
                    {
                        GUILayout.Button("", EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16));
                    }

                    if (c < _pool._categories.Count - 1)
                    {
                        // The down arrow will move things towards the end of the List
                        var dnArrow = CoreGameKitInspectorResources.DownArrowTexture;
                        if (GUILayout.Button(new GUIContent(dnArrow, "Click to shift Category down"),
                                             EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16)))
                        {
                            indexToShiftDown = c;
                        }
                    }
                    else
                    {
                        GUILayout.Button("", EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16));
                    }

                    var settingsIcon = new GUIContent(CoreGameKitInspectorResources.SettingsTexture,
                                                      "Click to edit Category");

                    GUI.backgroundColor = Color.white;
                    if (GUILayout.Button(settingsIcon, EditorStyles.toolbarButton, GUILayout.Width(24),
                                         GUILayout.Height(16)))
                    {
                        catEditing = cat;
                    }
                    GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
                    if (GUILayout.Button(new GUIContent("Delete", "Click to delete Category"),
                                         EditorStyles.miniButton, GUILayout.MaxWidth(45)))
                    {
                        catToDelete = cat;
                    }
                    GUILayout.Space(15);
                }
                else
                {
                    GUI.contentColor = DTInspectorUtility.BrightButtonColor;

                    if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DamageTexture, "Click to damage all Killables in this Category"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                    {
                        SpawnUtility.DamageAllPrefabsInCategory(cat.CatName, 1);
                        _isDirty = true;
                    }
                    if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.KillTexture, "Click to kill all Killables in this Category"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                    {
                        SpawnUtility.KillAllPrefabsInCategory(cat.CatName);
                        _isDirty = true;
                    }
                    if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DespawnTexture, "Click to despawn all prefabs in this Category"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                    {
                        SpawnUtility.DespawnAllPrefabsInCategory(cat.CatName);
                        _isDirty = true;
                    }

                    var itemsSpawned            = PoolBoss.CategoryItemsSpawned(cat.CatName);
                    var categoryHasItemsSpawned = itemsSpawned > 0;
                    var theBtnText = itemsSpawned.ToString();
                    var btnColor   = categoryHasItemsSpawned ? DTInspectorUtility.BrightTextColor : DTInspectorUtility.DeleteButtonColor;
                    GUI.backgroundColor = btnColor;

                    var btnWidth = 32;
                    if (theBtnText.Length > 3)
                    {
                        btnWidth = 11 * theBtnText.Length;
                    }
                    if (GUILayout.Button(theBtnText, EditorStyles.miniButtonRight, GUILayout.MaxWidth(btnWidth)) && categoryHasItemsSpawned)
                    {
                        var catItems = PoolBoss.CategoryActiveItems(cat.CatName);

                        if (catItems.Count > 0)
                        {
                            var gos = new List <GameObject>(catItems.Count);
                            for (var i = 0; i < catItems.Count; i++)
                            {
                                gos.Add(catItems[i].gameObject);
                            }

                            Selection.objects = gos.ToArray();
                        }
                    }

                    GUI.backgroundColor = Color.white;
                    GUI.contentColor    = Color.white;
                    GUILayout.Space(4);
                }
            }
            else
            {
                GUI.backgroundColor = DTInspectorUtility.BrightTextColor;
                var tex = EditorGUILayout.TextField("", cat.ProspectiveName);
                if (tex != cat.ProspectiveName)
                {
                    cat.ProspectiveName = tex;
                    _isDirty            = true;
                }

                var buttonPressed = DTInspectorUtility.AddCancelSaveButtons("category");

                switch (buttonPressed)
                {
                case DTInspectorUtility.FunctionButtons.Cancel:
                    cat.IsEditing       = false;
                    cat.ProspectiveName = cat.CatName;
                    _isDirty            = true;
                    break;

                case DTInspectorUtility.FunctionButtons.Save:
                    catRenaming = cat;
                    break;
                }

                GUILayout.Space(15);
            }

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

            if (cat.IsEditing)
            {
                DTInspectorUtility.VerticalSpace(2);
            }

            matchingItems.Sort(delegate(PoolBossItem x, PoolBossItem y) {
                if (x.prefabTransform == null && y.prefabTransform != null)
                {
                    return(-1);
                }
                if (y.prefabTransform == null && x.prefabTransform != null)
                {
                    return(1);
                }
                if (y.prefabTransform == null && x.prefabTransform == null)
                {
                    return(0);
                }

                // ReSharper disable PossibleNullReferenceException
                return(String.Compare(x.prefabTransform.name, y.prefabTransform.name, StringComparison.Ordinal));
                // ReSharper restore PossibleNullReferenceException
            });

            var catItemsFiltered = 0;
            if (hasFiltered)
            {
                var totalCount = _pool.poolItems.FindAll(delegate(PoolBossItem x) {
                    return(cat.CatName == x.categoryName);
                }).Count;

                catItemsFiltered = totalCount - matchingItems.Count;
            }

            bool hasOpenBox = false;

            if (catItemsFiltered > 0)
            {
                DTInspectorUtility.BeginGroupedControls();
                DTInspectorUtility.ShowLargeBarAlertBox(string.Format("This Category has {0} items filtered out.", catItemsFiltered));
                hasOpenBox = true;
            }
            else if (!hasItems)
            {
                DTInspectorUtility.BeginGroupedControls();
                DTInspectorUtility.ShowLargeBarAlertBox("This Category is empty. Add / move some items or you may delete it.");
                DTInspectorUtility.EndGroupedControls();
            }

            if (cat.IsExpanded)
            {
                if (matchingItems.Count > 0 && !hasOpenBox)
                {
                    DTInspectorUtility.BeginGroupedControls();
                }

                for (var i = 0; i < matchingItems.Count; i++)
                {
                    var poolItem = matchingItems[i];

                    DTInspectorUtility.StartGroupHeader();

                    if (poolItem.prefabTransform != null)
                    {
                        var rend = poolItem.prefabTransform.GetComponent <TrailRenderer>();
                        if (rend != null && rend.autodestruct)
                        {
                            DTInspectorUtility.ShowRedErrorBox(
                                "This prefab contains a Trail Renderer with auto-destruct enabled. " + DoNotDestroyPoolItem);
                        }
                        else
                        {
#if UNITY_5_4_OR_NEWER
                            // nothing to check
#else
                            var partAnim = poolItem.prefabTransform.GetComponent <ParticleAnimator>();
                            if (partAnim != null && partAnim.autodestruct)
                            {
                                DTInspectorUtility.ShowRedErrorBox(
                                    "This prefab contains a Particle Animator with auto-destruct enabled. " + DoNotDestroyPoolItem);
                            }
#endif
                        }
                    }

                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.BeginHorizontal();
                    var itemName = poolItem.prefabTransform == null ? "[NO PREFAB]" : poolItem.prefabTransform.name;
                    var state    = DTInspectorUtility.Foldout(poolItem.isExpanded, itemName);
                    if (state != poolItem.isExpanded)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand Pool Item");
                        poolItem.isExpanded = state;
                    }

                    if (Application.isPlaying)
                    {
                        GUILayout.FlexibleSpace();

                        if (poolItem.prefabTransform != null)
                        {
                            var itemInfo = PoolBoss.PoolItemInfoByName(itemName);
                            GUI.contentColor = DTInspectorUtility.BrightButtonColor;

                            if (itemInfo != null && itemInfo.SpawnedClones.Count > 0)
                            {
                                if (poolItem.prefabTransform.GetComponent <Killable>() != null)
                                {
                                    if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DamageTexture, "Click to damage all of this prefab"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                                    {
                                        SpawnUtility.DamageAllOfPrefab(poolItem.prefabTransform, 1);
                                        _isDirty = true;
                                    }
                                    if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.KillTexture, "Click to kill all of this prefab"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                                    {
                                        SpawnUtility.KillAllOfPrefab(poolItem.prefabTransform);
                                        _isDirty = true;
                                    }
                                }
                                if (GUILayout.Button(new GUIContent(CoreGameKitInspectorResources.DespawnTexture, "Click to despawn all of this prefab"),
                                                     EditorStyles.toolbarButton, GUILayout.Width(24)))
                                {
                                    SpawnUtility.DespawnAllOfPrefab(poolItem.prefabTransform);
                                    _isDirty = true;
                                }
                            }

                            GUI.contentColor = DTInspectorUtility.BrightTextColor;
                            if (itemInfo != null)
                            {
                                var spawnedCount   = itemInfo.SpawnedClones.Count;
                                var despawnedCount = itemInfo.DespawnedClones.Count;
                                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                                if (spawnedCount == 0)
                                {
                                    GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
                                }
                                else
                                {
                                    GUI.backgroundColor = DTInspectorUtility.BrightTextColor;
                                }
                                var content = new GUIContent(string.Format("{0} / {1} Spawned", spawnedCount, despawnedCount + spawnedCount),
                                                             "Click here to select all spawned items.");
                                if (GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(110)))
                                {
                                    var obj = new List <GameObject>();
                                    foreach (var t in itemInfo.SpawnedClones)
                                    {
                                        if (t == null)
                                        {
                                            LevelSettings.LogIfNew("1 of more of your pooled Game Object has been destroyed! Please check for any scripts that destroy Game Objects. Pool Boss cannot recover from this.");
                                            continue;
                                        }
                                        obj.Add(t.gameObject);
                                    }

                                    if (obj.Count > 0)
                                    {
                                        Selection.objects = obj.ToArray();
                                    }
                                }

                                content = new GUIContent("Pk: " + itemInfo.Peak, "Click to reset peak to zero.");
                                if (Time.realtimeSinceStartup - itemInfo.PeakTime < .2f)
                                {
                                    GUI.backgroundColor = DTInspectorUtility.AddButtonColor;
                                }
                                else if (itemInfo.Peak == 0)
                                {
                                    GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
                                }
                                else
                                {
                                    GUI.backgroundColor = DTInspectorUtility.BrightTextColor;
                                }

                                if (GUILayout.Button(content, EditorStyles.miniButton, GUILayout.Width(64)))
                                {
                                    itemInfo.Peak     = Math.Max(0, itemInfo.SpawnedClones.Count);
                                    itemInfo.PeakTime = Time.realtimeSinceStartup;
                                    _isDirty          = true;
                                    _pool._changes++;
                                }
                                GUI.backgroundColor = Color.white;
                            }
                        }
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUI.backgroundColor = DTInspectorUtility.BrightButtonColor;
                        var selCatIndex = catNames.IndexOf(poolItem.categoryName);
                        var newCat      = EditorGUILayout.Popup(selCatIndex, catNames.ToArray(), GUILayout.Width(130));
                        if (newCat != selCatIndex)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Pool Item Category");
                            poolItem.categoryName = catNames[newCat];
                        }
                        GUI.backgroundColor = Color.white;

                        DTInspectorUtility.FocusInProjectViewButton("Pool Item prefab", poolItem.prefabTransform == null ? null : poolItem.prefabTransform.gameObject);
                    }

                    var buttonPressed = DTInspectorUtility.AddFoldOutListItemButtons(i, matchingItems.Count,
                                                                                     "Pool Item", false, null, true, false, true);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();

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

                        var newPrefab =
                            (Transform)
                            EditorGUILayout.ObjectField("Prefab", poolItem.prefabTransform, typeof(Transform),
                                                        false);
                        if (newPrefab != poolItem.prefabTransform)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Pool Item Prefab");
                            poolItem.prefabTransform = newPrefab;
                        }

                        var newPreloadQty = EditorGUILayout.IntSlider("Preload Qty", poolItem.instancesToPreload, 0,
                                                                      10000);
                        if (newPreloadQty != poolItem.instancesToPreload)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool,
                                                                   "change Pool Item Preload Qty");
                            poolItem.instancesToPreload = newPreloadQty;
                        }
                        if (poolItem.instancesToPreload == 0)
                        {
                            DTInspectorUtility.ShowColorWarningBox(
                                "You have set the Preload Qty to 0. This prefab will not be in the Pool.");
                        }

                        var newAllow = EditorGUILayout.Toggle("Allow Instantiate More",
                                                              poolItem.allowInstantiateMore);
                        if (newAllow != poolItem.allowInstantiateMore)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool,
                                                                   "toggle Allow Instantiate More");
                            poolItem.allowInstantiateMore = newAllow;
                        }

                        if (poolItem.allowInstantiateMore)
                        {
                            var newLimit = EditorGUILayout.IntSlider("Item Limit", poolItem.itemHardLimit,
                                                                     poolItem.instancesToPreload, 10000);
                            if (newLimit != poolItem.itemHardLimit)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Item Limit");
                                poolItem.itemHardLimit = newLimit;
                            }
                        }
                        else
                        {
                            var newRecycle = EditorGUILayout.Toggle("Recycle Oldest", poolItem.allowRecycle);
                            if (newRecycle != poolItem.allowRecycle)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Recycle Oldest");
                                poolItem.allowRecycle = newRecycle;
                            }
                        }

                        newLog = EditorGUILayout.Toggle("Log Messages", poolItem.logMessages);
                        if (newLog != poolItem.logMessages)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Log Messages");
                            poolItem.logMessages = newLog;
                        }
                    }

                    switch (buttonPressed)
                    {
                    case DTInspectorUtility.FunctionButtons.Remove:
                        itemToRemove = poolItem;
                        break;

                    case DTInspectorUtility.FunctionButtons.Add:
                        indexToInsertAt  = _pool.poolItems.IndexOf(poolItem);
                        selectedCategory = cat;
                        break;

                    case DTInspectorUtility.FunctionButtons.DespawnAll:
                        PoolBoss.DespawnAllOfPrefab(poolItem.prefabTransform);
                        break;

                    case DTInspectorUtility.FunctionButtons.Copy:
                        itemToClone = poolItem;
                        break;
                    }

                    EditorGUILayout.EndVertical();
                    DTInspectorUtility.AddSpaceForNonU5();
                }

                if (matchingItems.Count > 0 && !hasOpenBox)
                {
                    DTInspectorUtility.EndGroupedControls();
                    DTInspectorUtility.VerticalSpace(2);
                }
            }

            if (hasOpenBox)
            {
                DTInspectorUtility.EndGroupedControls();
            }

            DTInspectorUtility.VerticalSpace(2);
        }

        if (indexToShiftUp.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "shift up Category");
            var item = _pool._categories[indexToShiftUp.Value];
            _pool._categories.Insert(indexToShiftUp.Value - 1, item);
            _pool._categories.RemoveAt(indexToShiftUp.Value + 1);
            _isDirty = true;
        }

        if (indexToShiftDown.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "shift down Category");
            var index = indexToShiftDown.Value + 1;
            var item  = _pool._categories[index];
            _pool._categories.Insert(index - 1, item);
            _pool._categories.RemoveAt(index + 1);
            _isDirty = true;
        }

        if (catToDelete != null)
        {
            if (_pool.poolItems.FindAll(delegate(PoolBossItem x) {
                return(x.categoryName == catToDelete.CatName);
            }).Count > 0)
            {
                DTInspectorUtility.ShowAlert("You cannot delete a Category with Pool Items in it. Move or delete the items first.");
            }
            else if (_pool._categories.Count <= 1)
            {
                DTInspectorUtility.ShowAlert("You cannot delete the last Category.");
            }
            else
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "Delete Category");
                _pool._categories.Remove(catToDelete);
                _isDirty = true;
            }
        }

        if (catRenaming != null)
        {
            // ReSharper disable once ForCanBeConvertedToForeach
            var isValidName = true;

            if (string.IsNullOrEmpty(catRenaming.ProspectiveName))
            {
                isValidName = false;
                DTInspectorUtility.ShowAlert("You cannot have a blank Category name.");
            }

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var c = 0; c < _pool._categories.Count; c++)
            {
                var cat = _pool._categories[c];
                // ReSharper disable once InvertIf
                if (cat != catRenaming && cat.CatName == catRenaming.ProspectiveName)
                {
                    isValidName = false;
                    DTInspectorUtility.ShowAlert("You already have a Category named '" + catRenaming.ProspectiveName + "'. Category names must be unique.");
                }
            }

            if (isValidName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "Undo change Category name.");

                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < _pool.poolItems.Count; i++)
                {
                    var item = _pool.poolItems[i];
                    if (item.categoryName == catRenaming.CatName)
                    {
                        item.categoryName = catRenaming.ProspectiveName;
                    }
                }

                catRenaming.CatName   = catRenaming.ProspectiveName;
                catRenaming.IsEditing = false;
                _isDirty = true;
            }
        }

        if (catEditing != null)
        {
            // ReSharper disable once ForCanBeConvertedToForeach
            for (var c = 0; c < _pool._categories.Count; c++)
            {
                var cat = _pool._categories[c];
                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (catEditing == cat)
                {
                    cat.IsEditing = true;
                }
                else
                {
                    cat.IsEditing = false;
                }

                _isDirty = true;
            }
        }

        if (itemToRemove != null)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "remove Pool Item");
            _pool.poolItems.Remove(itemToRemove);
        }
        if (itemToClone != null)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "clone Pool Item");
            var newItem = itemToClone.Clone();

            var oldIndex = _pool.poolItems.IndexOf(itemToClone);

            _pool.poolItems.Insert(oldIndex, newItem);
        }

        if (indexToInsertAt.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "insert Pool Item");
            _pool.poolItems.Insert(indexToInsertAt.Value, new PoolBossItem {
                categoryName = selectedCategory.CatName
            });
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);     // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 18
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        _holder = (WorldVariableTracker)target;

        LevelSettings.Instance = null; // clear cached version
        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        _isDirty = false;

        var isInProjectView = DTInspectorUtility.IsPrefabInProjectView(_holder);

        if (isInProjectView)
        {
            DTInspectorUtility.ShowRedErrorBox("You have selected the WorldVariableTracker prefab in Project View. Please select the one in your Scene to edit.");
            return;
        }


        _stats = GetPlayerStatsFromChildren(_holder.transform);

        Transform statToRemove = null;

        _stats.Sort(delegate(WorldVariable x, WorldVariable y) {
            return(x.name.CompareTo(y.name));
        });

        DTInspectorUtility.StartGroupHeader();
        EditorGUI.indentLevel = 1;
        var newShowNewVar = DTInspectorUtility.Foldout(_holder.showNewVarSection, "Create New");

        EditorGUI.indentLevel = 0;
        if (newShowNewVar != _holder.showNewVarSection)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "toggle Create New");
            _holder.showNewVarSection = newShowNewVar;
        }
        EditorGUILayout.EndVertical();

        if (_holder.showNewVarSection)
        {
            var newVarName = EditorGUILayout.TextField("New Variable Name", _holder.newVariableName);
            if (newVarName != _holder.newVariableName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "change New Variable Name");
                _holder.newVariableName = newVarName;
            }

            var newVarType = (WorldVariableTracker.VariableType)EditorGUILayout.EnumPopup("New Variable Type", _holder.newVarType);
            if (newVarType != _holder.newVarType)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "change New Variable Type");
                _holder.newVarType = newVarType;
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Actions");
            GUI.contentColor = DTInspectorUtility.AddButtonColor;
            GUILayout.Space(101);
            if (GUILayout.Button("Create Variable", EditorStyles.toolbarButton, GUILayout.MaxWidth(100)))
            {
                CreateNewVariable(_holder.newVariableName, _holder.newVarType);
                _isDirty = true;
            }
            GUILayout.FlexibleSpace();
            GUI.contentColor = Color.white;

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

        DTInspectorUtility.AddSpaceForNonU5();

        DTInspectorUtility.StartGroupHeader();
        EditorGUILayout.LabelField("All World Variables");
        EditorGUILayout.EndVertical();

        var totalInt = _stats.FindAll(delegate(WorldVariable obj) {
            return(obj.varType == WorldVariableTracker.VariableType._integer);
        });
        var totalFloat = _stats.FindAll(delegate(WorldVariable obj) {
            return(obj.varType == WorldVariableTracker.VariableType._float);
        });

        var showIntVariable = EditorGUILayout.Toggle("Show Integers (" + totalInt.Count + ")", _holder.showIntVars);

        if (showIntVariable != _holder.showIntVars)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "toggle Show Integers");
            _holder.showIntVars = showIntVariable;
        }

        var showFloatVariable = EditorGUILayout.Toggle("Show Floats (" + totalFloat.Count + ")", _holder.showFloatVars);

        if (showFloatVariable != _holder.showFloatVars)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "toggle Show Floats");
            _holder.showFloatVars = showFloatVariable;
        }

        var filteredStats = new List <WorldVariable>();

        filteredStats.AddRange(_stats);
        if (!_holder.showIntVars)
        {
            filteredStats.RemoveAll(delegate(WorldVariable obj) {
                return(obj.varType == WorldVariableTracker.VariableType._integer);
            });
        }
        if (!_holder.showFloatVars)
        {
            filteredStats.RemoveAll(delegate(WorldVariable obj) {
                return(obj.varType == WorldVariableTracker.VariableType._float);
            });
        }

        if (filteredStats.Count == 0)
        {
            DTInspectorUtility.ShowColorWarningBox("You have no World Variables of the selected type(s).");
        }
        EditorGUILayout.EndVertical();

        DTInspectorUtility.AddSpaceForNonU5();

        var state = _holder.worldVariablesExpanded;
        var text  = string.Format("World Variables ({0})", filteredStats.Count);

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

        GUILayout.BeginHorizontal();

        text = "<b><size=11>" + text + "</size></b>";

        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 != _holder.worldVariablesExpanded)
        {
            _holder.worldVariablesExpanded = state;
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _holder, "toggle World Variables");
        }

        // Add expand/collapse buttons if there are items in the list
        if (_stats.Count > 0)
        {
            GUI.backgroundColor = Color.white;

            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));
            const string collapseIcon   = "Collapse";
            var          content        = new GUIContent(collapseIcon, "Click to collapse all");
            var          masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Height(16));

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

        GUILayout.Space(4);
        EditorGUILayout.EndHorizontal();

        if (_holder.worldVariablesExpanded)
        {
            if (filteredStats.Count > 0)
            {
                DTInspectorUtility.BeginGroupedControls();
            }
            for (var i = 0; i < filteredStats.Count; i++)
            {
                var aStat = filteredStats[i];

                var varDirty = false;

                DTInspectorUtility.StartGroupHeader();
                EditorGUI.indentLevel = 1;
                EditorGUILayout.BeginHorizontal();
                var newExpand = DTInspectorUtility.Foldout(aStat.isExpanded, aStat.name);
                if (newExpand != aStat.isExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "toggle expand Variables");
                    aStat.isExpanded = newExpand;
                }

                GUILayout.FlexibleSpace();

                if (Application.isPlaying)
                {
                    GUI.contentColor = DTInspectorUtility.BrightTextColor;
                    var sValue = "";

                    switch (aStat.varType)
                    {
                    case WorldVariableTracker.VariableType._integer:
                        var _int = WorldVariableTracker.GetExistingWorldVariableIntValue(aStat.name, aStat.startingValue);
                        sValue = _int.HasValue ? _int.Value.ToString() : "";
                        break;

                    case WorldVariableTracker.VariableType._float:
                        var _float = WorldVariableTracker.GetExistingWorldVariableFloatValue(aStat.name, aStat.startingValueFloat);
                        sValue = _float.HasValue ? _float.Value.ToString(CultureInfo.InvariantCulture) : "";
                        break;

                    default:
                        Debug.Log("add code for varType: " + aStat.varType);
                        break;
                    }

                    EditorGUILayout.LabelField("Value: " + sValue, GUILayout.Width(120));
                    GUI.contentColor = Color.white;
                    GUILayout.Space(10);
                }

                GUI.contentColor = DTInspectorUtility.BrightTextColor;
                GUILayout.Label(WorldVariableTracker.GetVariableTypeFriendlyString(aStat.varType));
                switch (aStat.varType)
                {
                case WorldVariableTracker.VariableType._float:
                    GUILayout.Space(15);
                    break;
                }
                GUI.contentColor = Color.white;
                var functionPressed = DTInspectorUtility.AddFoldOutListItemButtons(i, _stats.Count, "variable", false, null, false);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

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

                    var newName = EditorGUILayout.TextField("Name", aStat.transform.name);
                    if (newName != aStat.transform.name)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat.gameObject, "change Name");
                        aStat.transform.name = newName;
                    }

                    if (Application.isPlaying)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Change Value", GUILayout.Width(100));
                        GUILayout.FlexibleSpace();
                        switch (aStat.varType)
                        {
                        case WorldVariableTracker.VariableType._integer:
                            aStat.prospectiveValue = EditorGUILayout.IntField("", aStat.prospectiveValue, GUILayout.Width(120));
                            break;

                        case WorldVariableTracker.VariableType._float:
                            aStat.prospectiveFloatValue = EditorGUILayout.FloatField("", aStat.prospectiveFloatValue, GUILayout.Width(120));
                            break;

                        default:
                            Debug.LogError("Add code for varType: " + aStat.varType.ToString());
                            break;
                        }

                        GUI.contentColor = DTInspectorUtility.BrightButtonColor;
                        if (GUILayout.Button("Change Value", EditorStyles.toolbarButton, GUILayout.Width(80)))
                        {
                            var variable = WorldVariableTracker.GetWorldVariable(aStat.name);

                            switch (aStat.varType)
                            {
                            case WorldVariableTracker.VariableType._integer:
                                variable.CurrentIntValue = aStat.prospectiveValue;
                                break;

                            case WorldVariableTracker.VariableType._float:
                                variable.CurrentFloatValue = aStat.prospectiveFloatValue;
                                break;

                            default:
                                Debug.LogError("Add code for varType: " + aStat.varType.ToString());
                                break;
                            }
                        }
                        GUI.contentColor = Color.white;

                        GUILayout.Space(10);

                        EditorGUILayout.EndHorizontal();
                    }


                    var newPersist = (WorldVariable.StatPersistanceMode)EditorGUILayout.EnumPopup("Persistence mode", aStat.persistanceMode);
                    if (newPersist != aStat.persistanceMode)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Persistence mode");
                        aStat.persistanceMode = newPersist;
                    }

                    var newChange = (WorldVariable.VariableChangeMode)EditorGUILayout.EnumPopup("Modifications allowed", aStat.changeMode);
                    if (newChange != aStat.changeMode)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Modifications allowed");
                        aStat.changeMode = newChange;
                    }

                    switch (aStat.varType)
                    {
                    case WorldVariableTracker.VariableType._integer:
                        var newStart = EditorGUILayout.IntField("Starting value", aStat.startingValue);
                        if (newStart != aStat.startingValue)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Starting value");
                            aStat.startingValue = newStart;
                        }
                        break;

                    case WorldVariableTracker.VariableType._float:
                        var newStartFloat = EditorGUILayout.FloatField("Starting value", aStat.startingValueFloat);
                        if (newStartFloat != aStat.startingValueFloat)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Starting value");
                            aStat.startingValueFloat = newStartFloat;
                        }
                        break;

                    default:
                        Debug.Log("add code for varType: " + aStat.varType);
                        break;
                    }

                    var newNeg = EditorGUILayout.Toggle("Allow negative?", aStat.allowNegative);
                    if (newNeg != aStat.allowNegative)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "toggle Allow negative");
                        aStat.allowNegative = newNeg;
                    }

                    DTInspectorUtility.StartGroupHeader(1);

                    var newTopLimit = GUILayout.Toggle(aStat.hasMaxValue, "Has max value?");
                    if (newTopLimit != aStat.hasMaxValue)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "toggle Has max value");
                        aStat.hasMaxValue = newTopLimit;
                    }
                    EditorGUILayout.EndVertical();

                    if (aStat.hasMaxValue)
                    {
                        EditorGUI.indentLevel = 0;
                        switch (aStat.varType)
                        {
                        case WorldVariableTracker.VariableType._integer:
                            var newMax = EditorGUILayout.IntField("Max Value", aStat.intMaxValue);
                            if (newMax != aStat.intMaxValue)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Max Value");
                                aStat.intMaxValue = newMax;
                            }
                            break;

                        case WorldVariableTracker.VariableType._float:
                            var newFloatMax = EditorGUILayout.FloatField("Max Value", aStat.floatMaxValue);
                            if (newFloatMax != aStat.floatMaxValue)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change Max Value");
                                aStat.floatMaxValue = newFloatMax;
                            }
                            break;

                        default:
                            Debug.Log("add code for varType: " + aStat.varType);
                            break;
                        }
                    }
                    EditorGUILayout.EndVertical();
                    DTInspectorUtility.AddSpaceForNonU5(1);

                    DTInspectorUtility.StartGroupHeader(1);
                    EditorGUI.indentLevel = 0;
                    var newCanEnd = GUILayout.Toggle(aStat.canEndGame, "Triggers game over?");
                    if (newCanEnd != aStat.canEndGame)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "toggle Triggers game over");
                        aStat.canEndGame = newCanEnd;
                    }
                    EditorGUILayout.EndVertical();
                    if (aStat.canEndGame)
                    {
                        EditorGUI.indentLevel = 0;
                        switch (aStat.varType)
                        {
                        case WorldVariableTracker.VariableType._integer:
                            var newMin = EditorGUILayout.IntField("G.O. min value", aStat.endGameMinValue);
                            if (newMin != aStat.endGameMinValue)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change G.O. min value");
                                aStat.endGameMinValue = newMin;
                            }

                            var newMax = EditorGUILayout.IntField("G.O. max value", aStat.endGameMaxValue);
                            if (newMax != aStat.endGameMaxValue)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change G.O. max value");
                                aStat.endGameMaxValue = newMax;
                            }
                            break;

                        case WorldVariableTracker.VariableType._float:
                            var newMinFloat = EditorGUILayout.FloatField("G.O. min value", aStat.endGameMinValueFloat);
                            if (newMinFloat != aStat.endGameMinValueFloat)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change G.O. min value");
                                aStat.endGameMinValueFloat = newMinFloat;
                            }

                            var newMaxFloat = EditorGUILayout.FloatField("G.O. max value", aStat.endGameMaxValueFloat);
                            if (newMaxFloat != aStat.endGameMaxValueFloat)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "change G.O. max value");
                                aStat.endGameMaxValueFloat = newMaxFloat;
                            }
                            break;

                        default:
                            Debug.Log("add code for varType: " + aStat.varType);
                            break;
                        }
                    }
                    EditorGUILayout.EndVertical();

                    DTInspectorUtility.AddSpaceForNonU5(1);
                    DTInspectorUtility.StartGroupHeader(1);
                    var newFire = GUILayout.Toggle(aStat.fireEventsOnChange, "Custom Events");
                    if (newFire != aStat.fireEventsOnChange)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, aStat, "toggle Custom Events");
                        aStat.fireEventsOnChange = newFire;
                    }
                    EditorGUILayout.EndVertical();
                    if (aStat.fireEventsOnChange)
                    {
                        EditorGUI.indentLevel = 0;

                        DTInspectorUtility.ShowColorWarningBox("When variable value changes, fire the Custom Events below");

                        EditorGUILayout.BeginHorizontal();
                        GUI.contentColor = DTInspectorUtility.AddButtonColor;
                        GUILayout.Space(10);
                        if (GUILayout.Button(new GUIContent("Add", "Click to add a Custom Event"), EditorStyles.toolbarButton, GUILayout.Width(50)))
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, aStat, "Add Custom Event");
                            aStat.changeCustomEventsToFire.Add(new CGKCustomEventToFire());
                        }
                        GUILayout.Space(10);
                        if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last Custom Event"), EditorStyles.toolbarButton, GUILayout.Width(50)))
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, aStat, "Remove last Custom Event");
                            aStat.changeCustomEventsToFire.RemoveAt(aStat.changeCustomEventsToFire.Count - 1);
                        }
                        GUI.contentColor = Color.white;

                        EditorGUILayout.EndHorizontal();

                        if (aStat.changeCustomEventsToFire.Count == 0)
                        {
                            DTInspectorUtility.ShowColorWarningBox("You have no Custom Events selected to fire.");
                        }

                        DTInspectorUtility.VerticalSpace(2);

                        // ReSharper disable once ForCanBeConvertedToForeach
                        for (var j = 0; j < aStat.changeCustomEventsToFire.Count; j++)
                        {
                            var anEvent = aStat.changeCustomEventsToFire[j].CustomEventName;

                            anEvent = DTInspectorUtility.SelectCustomEventForVariable(ref _isDirty, anEvent,
                                                                                      aStat, "Custom Event");

                            if (anEvent == aStat.changeCustomEventsToFire[j].CustomEventName)
                            {
                                continue;
                            }

                            aStat.changeCustomEventsToFire[j].CustomEventName = anEvent;
                        }
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUI.indentLevel = 0;
                    var listenerWasEmpty = aStat.listenerPrefab == null;
                    var newListener      = (WorldVariableListener)EditorGUILayout.ObjectField("Listener", aStat.listenerPrefab, typeof(WorldVariableListener), true);
                    if (newListener != aStat.listenerPrefab)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref varDirty, aStat, "assign Listener");
                        aStat.listenerPrefab = newListener;
                        if (listenerWasEmpty && aStat.listenerPrefab != null)
                        {
                            // just assigned.
                            var listener = aStat.listenerPrefab.GetComponent <WorldVariableListener>();
                            if (listener == null)
                            {
                                DTInspectorUtility.ShowAlert("You cannot assign a listener that doesn't have a WorldVariableListener script in it.");
                                aStat.listenerPrefab = null;
                            }
                            else
                            {
                                listener.variableName = aStat.transform.name;
                            }
                        }
                    }
                }

                switch (functionPressed)
                {
                case DTInspectorUtility.FunctionButtons.Remove:
                    statToRemove = aStat.transform;
                    break;
                }

                if (varDirty)
                {
                    EditorUtility.SetDirty(aStat);
                }

                EditorGUILayout.EndVertical();

                DTInspectorUtility.AddSpaceForNonU5();
            }

            if (filteredStats.Count > 0)
            {
                DTInspectorUtility.EndGroupedControls();
            }
        }

        if (statToRemove != null)
        {
            _isDirty = true;
            RemoveStat(statToRemove);
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);     // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 19
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        _pool = (PoolBoss)target;

        _isDirty = false;

        //DTPoolBossInspectorUtility.DrawTexture(PoolBossInspectorResources);

        var isInProjectView = DTPoolBossInspectorUtility.IsPrefabInProjectView(_pool);

        if (isInProjectView)
        {
            DTPoolBossInspectorUtility.ShowLargeBarAlert("*You have selected the PoolBoss prefab in Project View.");
            DTPoolBossInspectorUtility.ShowLargeBarAlert("*Please select the one in your Scene to edit.");
            DTPoolBossInspectorUtility.ShowRedError("*Click the button below to create a PoolBoss prefab in the Scene.");

            EditorGUILayout.Separator();

            GUI.contentColor = Color.green;
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button("Create PoolBoss Prefab", EditorStyles.toolbarButton, GUILayout.Width(180)))
            {
                CreatePoolBossPrefab();
            }
            EditorGUILayout.EndHorizontal();
            GUI.contentColor = Color.white;
            return;
        }

        var newAutoAdd = EditorGUILayout.Toggle("Auto-Add Missing Items", _pool.autoAddMissingPoolItems);

        if (newAutoAdd != _pool.autoAddMissingPoolItems)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Auto-Add Missing Items");
            _pool.autoAddMissingPoolItems = newAutoAdd;
        }

        var newLog = EditorGUILayout.Toggle("Log Messages", _pool.logMessages);

        if (newLog != _pool.logMessages)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Log Messages");
            _pool.logMessages = newLog;
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Actions", GUILayout.Width(100));
        GUI.contentColor = Color.green;
        GUILayout.Space(47);
        if (GUILayout.Button("Sort Items Alpha", EditorStyles.toolbarButton, GUILayout.Width(110)))
        {
            _pool.poolItems.Sort(delegate(PoolBossItem x, PoolBossItem y) {
                if (x.prefabTransform == null || y.prefabTransform == null)
                {
                    return(0);
                }

                return(x.prefabTransform.name.CompareTo(y.prefabTransform.name));
            });
        }

        if (Application.isPlaying)
        {
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Despawn All", "Click to despawn prefabs"), EditorStyles.toolbarButton, GUILayout.Width(90)))
            {
                PoolBoss.DespawnAllPrefabs();
                _isDirty = true;
            }
        }
        GUI.contentColor = Color.white;

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

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUI.color = DTPoolBossInspectorUtility.DragAreaColor;
            var dragArea = GUILayoutUtility.GetRect(0f, 30f, GUILayout.ExpandWidth(true));
            GUI.Box(dragArea, "Drag prefabs here in bulk to add them to the Pool!");
            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)
                    {
                        AddPoolItem(dragged);
                    }
                }
                Event.current.Use();
                break;
            }
            GUILayout.Space(4);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Separator();
        }


        var state = _pool.poolItemsExpanded;
        var text  = string.Format("Pool Item Settings ({0})", _pool.poolItems.Count);

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state)
        {
            GUI.backgroundColor = DTPoolBossInspectorUtility.InactiveHeaderColor;
        }
        else
        {
            GUI.backgroundColor = DTPoolBossInspectorUtility.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 != _pool.poolItemsExpanded)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand Pool Settings");
            _pool.poolItemsExpanded = state;
        }

        DTPoolBossInspectorUtility.ResetColors();

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

        // Add expand/collapse buttons if there are items in the list
        if (_pool.poolItems.Count > 0)
        {
            GUI.contentColor = Color.green;
            const string collapseIcon   = "Collapse";
            var          content        = new GUIContent(collapseIcon, "Click to collapse all");
            var          masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(60), GUILayout.Height(16));

            const string expandIcon = "Expand";
            content = new GUIContent(expandIcon, "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(60), GUILayout.Height(16));
            if (masterExpand)
            {
                ExpandCollapseAll(true);
            }
            if (masterCollapse)
            {
                ExpandCollapseAll(false);
            }
            GUI.contentColor = Color.white;
        }
        else
        {
            GUILayout.FlexibleSpace();
        }


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

        var addText = string.Format("Click to add Pool Item{0}.", _pool.poolItems.Count > 0 ? " at the end" : "");

        // Main Add button
        GUI.contentColor = Color.yellow;
        if (GUILayout.Button(new GUIContent("Add", addText), EditorStyles.toolbarButton, GUILayout.Height(16)))
        {
            _isDirty = true;
            CreateNewPoolItem();
        }
        GUI.contentColor = Color.white;
        GUILayout.Space(4);

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


        EditorGUILayout.EndHorizontal();

        if (_pool.poolItemsExpanded)
        {
            DTPoolBossInspectorUtility.BeginGroupedControls();

            int?indexToRemove    = null;
            int?indexToInsertAt  = null;
            int?indexToShiftUp   = null;
            int?indexToShiftDown = null;

            for (var i = 0; i < _pool.poolItems.Count; i++)
            {
                DTPoolBossInspectorUtility.StartGroupHeader();
                var poolItem = _pool.poolItems[i];

                EditorGUI.indentLevel = 1;
                EditorGUILayout.BeginHorizontal();
                var itemName = poolItem.prefabTransform == null ? "[NO PREFAB]" : poolItem.prefabTransform.name;
                state = DTPoolBossInspectorUtility.Foldout(poolItem.isExpanded, itemName);
                if (state != poolItem.isExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle expand Pool Item");
                    poolItem.isExpanded = state;
                }

                if (Application.isPlaying)
                {
                    GUILayout.FlexibleSpace();

                    GUI.contentColor = Color.green;
                    if (GUILayout.Button(new GUIContent("Despawn All", "Click to despawn all of this prefab"), EditorStyles.toolbarButton, GUILayout.Width(80)))
                    {
                        PoolBoss.DespawnAllOfPrefab(poolItem.prefabTransform);
                        _isDirty = true;
                    }
                    GUI.contentColor = Color.white;

                    GUI.contentColor = Color.yellow;
                    if (poolItem.prefabTransform != null)
                    {
                        var itemInfo = PoolBoss.PoolItemInfoByName(itemName);
                        if (itemInfo != null)
                        {
                            var spawnedCount   = itemInfo.SpawnedClones.Count;
                            var despawnedCount = itemInfo.DespawnedClones.Count;
                            var content        = new GUIContent(string.Format("{0} / {1} Spawned", spawnedCount, despawnedCount + spawnedCount), "Click here to select all spawned items.");
                            if (GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(110)))
                            {
                                var obj = new List <GameObject>();
                                // ReSharper disable once ForCanBeConvertedToForeach
                                for (var o = 0; o < itemInfo.SpawnedClones.Count; o++)
                                {
                                    obj.Add(itemInfo.SpawnedClones[o].gameObject);
                                }

                                Selection.objects = obj.ToArray();
                            }
                        }
                    }
                    GUI.contentColor = Color.white;
                }

                var buttonPressed = DTPoolBossInspectorUtility.AddFoldOutListItemButtons(i, _pool.poolItems.Count, "Pool Item", true, true);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

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

                    var newPrefab = (Transform)EditorGUILayout.ObjectField("Prefab", poolItem.prefabTransform, typeof(Transform), false);
                    if (newPrefab != poolItem.prefabTransform)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Pool Item Prefab");
                        poolItem.prefabTransform = newPrefab;
                    }

                    var newPreloadQty = EditorGUILayout.IntSlider("Preload Qty", poolItem.instancesToPreload, 0, 10000);
                    if (newPreloadQty != poolItem.instancesToPreload)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Pool Item Preload Qty");
                        poolItem.instancesToPreload = newPreloadQty;
                    }
                    if (poolItem.instancesToPreload == 0)
                    {
                        DTPoolBossInspectorUtility.ShowColorWarning("*You have set the Preload Qty to 0. This prefab will not be in the Pool.");
                    }

                    var newAllow = EditorGUILayout.Toggle("Allow Instantiate More", poolItem.allowInstantiateMore);
                    if (newAllow != poolItem.allowInstantiateMore)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Allow Instantiate More");
                        poolItem.allowInstantiateMore = newAllow;
                    }

                    if (poolItem.allowInstantiateMore)
                    {
                        var newLimit = EditorGUILayout.IntSlider("Item Limit", poolItem.itemHardLimit, poolItem.instancesToPreload, 1000);
                        if (newLimit != poolItem.itemHardLimit)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Item Limit");
                            poolItem.itemHardLimit = newLimit;
                        }
                    }

                    newLog = EditorGUILayout.Toggle("Log Messages", poolItem.logMessages);
                    if (newLog != poolItem.logMessages)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "toggle Log Messages");
                        poolItem.logMessages = newLog;
                    }
                }

                switch (buttonPressed)
                {
                case DTPoolBossInspectorUtility.FunctionButtons.Remove:
                    indexToRemove = i;
                    break;

                case DTPoolBossInspectorUtility.FunctionButtons.Add:
                    indexToInsertAt = i;
                    break;

                case DTPoolBossInspectorUtility.FunctionButtons.ShiftUp:
                    indexToShiftUp = i;
                    break;

                case DTPoolBossInspectorUtility.FunctionButtons.ShiftDown:
                    indexToShiftDown = i;
                    break;

                case DTPoolBossInspectorUtility.FunctionButtons.DespawnAll:
                    PoolBoss.DespawnAllOfPrefab(poolItem.prefabTransform);
                    break;
                }

                EditorGUILayout.EndVertical();
                DTPoolBossInspectorUtility.AddSpaceForNonU5();
            }

            if (indexToRemove.HasValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "remove Pool Item");
                _pool.poolItems.RemoveAt(indexToRemove.Value);
            }
            if (indexToInsertAt.HasValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "insert Pool Item");
                _pool.poolItems.Insert(indexToInsertAt.Value, new PoolBossItem());
            }
            if (indexToShiftUp.HasValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "shift up Pool Item");
                var item = _pool.poolItems[indexToShiftUp.Value];
                _pool.poolItems.Insert(indexToShiftUp.Value - 1, item);
                _pool.poolItems.RemoveAt(indexToShiftUp.Value + 1);
            }

            if (indexToShiftDown.HasValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "shift down Pool Item");
                var index = indexToShiftDown.Value + 1;
                var item  = _pool.poolItems[index];
                _pool.poolItems.Insert(index - 1, item);
                _pool.poolItems.RemoveAt(index + 1);
            }

            DTPoolBossInspectorUtility.EndGroupedControls();
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);             // or it won't save the data!!
        }

        Repaint();
        //DrawDefaultInspector();
    }
Exemplo n.º 20
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 1;

        var ma = MasterAudio.Instance;

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

        EventCalcSounds sounds = (EventCalcSounds)target;

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

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

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

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

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

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

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

        var disabledText = "";

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

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

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

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

                    int?groupIndex = null;
                    var noMatch    = false;

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

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

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

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

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

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

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

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

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

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

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

        //DrawDefaultInspector();
    }
    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();
    }
Exemplo n.º 22
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;

        _pool = (PoolBoss)target;

        _isDirty = false;

        var isInProjectView = DTPoolBossInspectorUtility.IsPrefabInProjectView(_pool);

        if (isInProjectView)
        {
            DTPoolBossInspectorUtility.ShowRedError(PoolBossLang.ErrorInProjectView);
            return;
        }

        var catNames = new List <string>(_pool._categories.Count);

        for (var i = 0; i < _pool._categories.Count; i++)
        {
            catNames.Add(_pool._categories[i].CatName);
        }

        if (!Application.isPlaying)
        {
            DTPoolBossInspectorUtility.StartGroupHeader();
            var newCat = EditorGUILayout.TextField(PoolBossLang.NewCategoryName, _pool.newCategoryName);
            if (newCat != _pool.newCategoryName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangeNewCategoryName);
                _pool.newCategoryName = newCat;
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginHorizontal();
            GUI.contentColor = DTPoolBossInspectorUtility.BrightButtonColor;
            GUILayout.Space(2);
            if (GUILayout.Button(PoolBossLang.CreateNewCategory, EditorStyles.toolbarButton, GUILayout.Width(130)))
            {
                CreateCategory();
            }

            GUI.contentColor = Color.white;

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            DTPoolBossInspectorUtility.AddSpaceForNonU5();
            DTPoolBossInspectorUtility.ResetColors();

            var selCatIndex = catNames.IndexOf(_pool.addToCategoryName);

            if (selCatIndex == -1)
            {
                selCatIndex = 0;
                _isDirty    = true;
            }

            GUI.backgroundColor = DTPoolBossInspectorUtility.BrightButtonColor;

            var newIndex = EditorGUILayout.Popup(PoolBossLang.DefaultItemCategory, selCatIndex, catNames.ToArray());
            if (newIndex != selCatIndex)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangeDefaultItemCategory);
                _pool.addToCategoryName = catNames[newIndex];
            }

            GUI.backgroundColor = Color.white;
            GUI.contentColor    = Color.white;
        }

        GUI.contentColor = Color.white;

        if (!Application.isPlaying)
        {
            var maxFrames  = Math.Max(1, _pool.poolItems.Count);
            var guiContent = new GUIContent(PoolBossLang.InitializeTime, PoolBossLang.InitializeTimeDescription);
            var newFrames  = EditorGUILayout.IntSlider(guiContent, _pool.framesForInit, 1, maxFrames);
            if (newFrames != _pool.framesForInit)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.InitializeTimeChange);
                _pool.framesForInit = newFrames;
            }
        }

        PoolBossItem     itemToRemove     = null;
        int?             indexToInsertAt  = null;
        PoolBossCategory selectedCategory = null;
        PoolBossItem     itemToClone      = null;

        PoolBossCategory catEditing  = null;
        PoolBossCategory catRenaming = null;

        PoolBossCategory catToDelete = null;
        int?indexToShiftUp           = null;
        int?indexToShiftDown         = null;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < _pool.poolItems.Count; i++)
        {
            var item = _pool.poolItems[i];
            if (catNames.Contains(item.categoryName))
            {
                continue;
            }

            item.categoryName = catNames[0];
            _isDirty          = true;
        }

        var newAutoAdd = EditorGUILayout.Toggle(new GUIContent(PoolBossLang.AutoAddMissing, PoolBossLang.AutoAddMissingCategory), _pool.autoAddMissingPoolItems);

        if (newAutoAdd != _pool.autoAddMissingPoolItems)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.AutoAddToggle);
            _pool.autoAddMissingPoolItems = newAutoAdd;
        }

        var newAllowDisabled = EditorGUILayout.Toggle(new GUIContent(PoolBossLang.DisabledDespawn, PoolBossLang.DisabledDespawnDescription), _pool.allowDespawningInactive);

        if (newAllowDisabled != _pool.allowDespawningInactive)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.DisabledDespawnToggle);
            _pool.allowDespawningInactive = newAllowDisabled;
        }

        var newLog = EditorGUILayout.Toggle(PoolBossLang.LogMessages, _pool.logMessages);

        if (newLog != _pool.logMessages)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.LogMessagesToggle);
            _pool.logMessages = newLog;
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Actions", GUILayout.Width(100));
        GUI.contentColor = DTPoolBossInspectorUtility.BrightButtonColor;

        GUILayout.FlexibleSpace();

        var allExpanded = true;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < _pool._categories.Count; i++)
        {
            if (_pool._categories[i].IsExpanded)
            {
                continue;
            }

            allExpanded = false;
            break;
        }

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var i = 0; i < _pool.poolItems.Count; i++)
        {
            if (_pool.poolItems[i].isExpanded)
            {
                continue;
            }

            allExpanded = false;
            break;
        }

        if (Application.isPlaying)
        {
            if (GUILayout.Button(new GUIContent(PoolBossLang.ClearPeaks), EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                ClearAllPeaks();
                _isDirty = true;
            }

            GUILayout.Space(6);
        }

        var buttonTooltip = allExpanded ? PoolBossLang.CollapseAllTooltip : PoolBossLang.ExpandAllTooltip;
        var buttonText    = allExpanded ? PoolBossLang.CollapseAll : PoolBossLang.ExpandAll;

        if (GUILayout.Button(new GUIContent(buttonText, buttonTooltip), EditorStyles.toolbarButton,
                             GUILayout.Width(80)))
        {
            ExpandCollapseAll(!allExpanded);
        }

        if (Application.isPlaying)
        {
            GUILayout.Space(6);
            if (GUILayout.Button(new GUIContent(PoolBossLang.DespawnAll, PoolBossLang.DespawnAllTooltip), EditorStyles.toolbarButton,
                                 GUILayout.Width(80)))
            {
                PoolBoss.DespawnAllPrefabs();
                _isDirty = true;
            }
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();

        GUI.backgroundColor = Color.white;

        if (!Application.isPlaying)
        {
#if ADDRESSABLES_ENABLED
            var newSource =
                (PoolBoss.PrefabSource)EditorGUILayout.EnumPopup("Create Items As", _pool.newItemPrefabSource);
            if (newSource != _pool.newItemPrefabSource)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Create Items As");
                _pool.newItemPrefabSource = newSource;
            }
#endif

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUI.color = DTPoolBossInspectorUtility.DragAreaColor;
            var dragArea = GUILayoutUtility.GetRect(0f, 30f, GUILayout.ExpandWidth(true));
            GUI.Box(dragArea, PoolBossLang.DragPrefabHere);
            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)
                    {
                        AddPoolItem(dragged);
                    }
                }

                Event.current.Use();
                break;
            }

            GUILayout.Space(4);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            DTPoolBossInspectorUtility.VerticalSpace(4);
        }

        GUI.backgroundColor = Color.white;
        GUI.contentColor    = Color.white;

        // ReSharper disable once ForCanBeConvertedToForeach
        for (var c = 0; c < _pool._categories.Count; c++)
        {
            var cat = _pool._categories[c];

            EditorGUI.indentLevel = 0;

            var matchingItems = new List <PoolBossItem>();
            matchingItems.AddRange(_pool.poolItems);
            matchingItems.RemoveAll(delegate(PoolBossItem x) { return(x.categoryName != cat.CatName); });

            var hasItems = matchingItems.Count > 0;

            EditorGUILayout.BeginHorizontal();

            if (!cat.IsEditing || Application.isPlaying)
            {
                var catName = cat.CatName;

                if (!cat.IsExpanded)
                {
                    catName += $": {matchingItems.Count} item{((matchingItems.Count != 1) ? "s" : "")}";
                }

                var state = cat.IsExpanded;
                var text  = catName;

                DTPoolBossInspectorUtility.ShowCollapsibleSectionInline(ref state, text);
                GUILayout.Space(2f);

                if (state != cat.IsExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ExpandCategory);
                    cat.IsExpanded = state;
                }

                EditorGUILayout.EndHorizontal();

                var catItemsCollapsed = true;

                for (var i = 0; i < _pool.poolItems.Count; i++)
                {
                    var item = _pool.poolItems[i];
                    if (item.categoryName != cat.CatName)
                    {
                        continue;
                    }

                    if (!item.isExpanded)
                    {
                        continue;
                    }

                    catItemsCollapsed = false;
                    break;
                }

                var headerStyle = new GUIStyle();
                headerStyle.margin      = new RectOffset(0, 0, 0, 0);
                headerStyle.padding     = new RectOffset(0, 0, 1, 0);
                headerStyle.fixedHeight = 20;

                EditorGUILayout.BeginHorizontal(headerStyle, GUILayout.MaxWidth(50));

                GUI.backgroundColor = Color.white;

                var tooltip = catItemsCollapsed ? PoolBossLang.ExpandAllItems : PoolBossLang.CollapseAllItems;
                var btnText = catItemsCollapsed ? PoolBossLang.Expand : PoolBossLang.Collapse;

                GUI.contentColor = DTPoolBossInspectorUtility.BrightButtonColor;
                if (GUILayout.Button(new GUIContent(btnText, tooltip), EditorStyles.toolbarButton, GUILayout.Width(60),
                                     GUILayout.Height(16)))
                {
                    ExpandCollapseCategory(cat.CatName, catItemsCollapsed);
                }

                GUI.contentColor = Color.white;

                if (!Application.isPlaying)
                {
                    if (c > 0)
                    {
                        // the up arrow.
                        var upArrow = PoolBossInspectorResources.UpArrowTexture;
                        if (GUILayout.Button(new GUIContent(upArrow, PoolBossLang.ShiftCategoryUp),
                                             EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16)))
                        {
                            indexToShiftUp = c;
                        }
                    }
                    else
                    {
                        GUILayout.Button("", EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16));
                    }

                    if (c < _pool._categories.Count - 1)
                    {
                        // The down arrow will move things towards the end of the List
                        var dnArrow = PoolBossInspectorResources.DownArrowTexture;
                        if (GUILayout.Button(new GUIContent(dnArrow, PoolBossLang.ShiftCategoryDown),
                                             EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16)))
                        {
                            indexToShiftDown = c;
                        }
                    }
                    else
                    {
                        GUILayout.Button("", EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16));
                    }

                    var settingsIcon = new GUIContent(PoolBossInspectorResources.SettingsTexture, PoolBossLang.EditCategory);

                    GUI.backgroundColor = Color.white;
                    if (GUILayout.Button(settingsIcon, EditorStyles.toolbarButton, GUILayout.Width(24), GUILayout.Height(16)))
                    {
                        catEditing = cat;
                    }

                    GUI.backgroundColor = DTPoolBossInspectorUtility.DeleteButtonColor;
                    if (GUILayout.Button(new GUIContent(PoolBossLang.Delete, PoolBossLang.ClickDeleteCategory),
                                         EditorStyles.miniButton, GUILayout.MaxWidth(51)))
                    {
                        catToDelete = cat;
                    }

                    GUILayout.Space(15);
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    GUI.contentColor = DTPoolBossInspectorUtility.BrightButtonColor;

                    if (GUILayout.Button(new GUIContent(PoolBossLang.DespawnAll, PoolBossLang.DespawnAllPrefabsTooltip),
                                         EditorStyles.toolbarButton, GUILayout.Width(80)))
                    {
                        PoolBoss.DespawnAllPrefabsInCategory(cat.CatName);
                        _isDirty = true;
                    }

                    var itemsSpawned            = PoolBoss.CategoryItemsSpawned(cat.CatName);
                    var categoryHasItemsSpawned = itemsSpawned > 0;
                    var theBtnText = itemsSpawned.ToString();
                    var btnColor   = categoryHasItemsSpawned
                        ? DTPoolBossInspectorUtility.BrightTextColor
                        : DTPoolBossInspectorUtility.DeleteButtonColor;
                    GUI.backgroundColor = btnColor;

                    var btnWidth = 32;
                    if (theBtnText.Length > 3)
                    {
                        btnWidth = 11 * theBtnText.Length;
                    }

                    GUILayout.Button(theBtnText, EditorStyles.miniButtonRight, GUILayout.MaxWidth(btnWidth));

                    GUI.backgroundColor = Color.white;
                    GUI.contentColor    = Color.white;
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                GUI.backgroundColor = DTPoolBossInspectorUtility.BrightTextColor;
                var tex = EditorGUILayout.TextField("", cat.ProspectiveName);
                if (tex != cat.ProspectiveName)
                {
                    cat.ProspectiveName = tex;
                    _isDirty            = true;
                }

                var buttonPressed = DTPoolBossInspectorUtility.AddCancelSaveButtons(PoolBossLang.Category);

                switch (buttonPressed)
                {
                case DTPoolBossInspectorUtility.FunctionButtons.Cancel:
                    cat.IsEditing       = false;
                    cat.ProspectiveName = cat.CatName;
                    _isDirty            = true;
                    break;

                case DTPoolBossInspectorUtility.FunctionButtons.Save:
                    catRenaming = cat;
                    _isDirty    = true;
                    break;
                }

                GUILayout.Space(4);
            }

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

            if (cat.IsEditing)
            {
                DTPoolBossInspectorUtility.VerticalSpace(2);
            }

            matchingItems.Sort(delegate(PoolBossItem x, PoolBossItem y)
            {
                return(string.Compare(PoolBossItemName(x), PoolBossItemName(y), StringComparison.Ordinal));
            });

            if (!hasItems)
            {
                DTPoolBossInspectorUtility.BeginGroupedControls();
                DTPoolBossInspectorUtility.ShowLargeBarAlert(PoolBossLang.EmptyCategory);
                DTPoolBossInspectorUtility.EndGroupedControls();
            }

            if (cat.IsExpanded)
            {
                if (matchingItems.Count > 0)
                {
                    DTPoolBossInspectorUtility.BeginGroupedControls();
                }

                for (var i = 0; i < matchingItems.Count; i++)
                {
                    var poolItem = matchingItems[i];

                    DTPoolBossInspectorUtility.StartGroupHeader();

                    if (poolItem.prefabTransform != null)
                    {
                        var rend = poolItem.prefabTransform.GetComponent <TrailRenderer>();
                        if (rend != null && rend.autodestruct)
                        {
                            DTPoolBossInspectorUtility.ShowRedError(string.Format(PoolBossLang.PrefabContainsTrail, PoolBossLang.DoNotDestroyPoolItem));
                        }
                        else
                        {
#if UNITY_5_4_OR_NEWER
                            // nothing to check
#else
                            var partAnim = poolItem.prefabTransform.GetComponent <ParticleAnimator>();
                            if (partAnim != null && partAnim.autodestruct)
                            {
                                DTPoolBossInspectorUtility.ShowRedError(
                                    $"This prefab contains a Particle Animator with auto-destruct enabled. {PoolBossLang.DoNotDestroyPoolItem}");
                            }
#endif
                        }
                    }

                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.BeginHorizontal();
                    string itemName = string.Empty;

                    switch (poolItem.prefabSource)
                    {
                    case PoolBoss.PrefabSource.Prefab:
                        itemName = poolItem.prefabTransform == null ? "[NO PREFAB]" : poolItem.prefabTransform.name;
                        break;

#if ADDRESSABLES_ENABLED
                    case PoolBoss.PrefabSource.Addressable:
                        var addressableName =
                            PoolBossAddressableEditorHelper.EditTimeAddressableName(poolItem.prefabAddressable);
                        itemName = string.IsNullOrWhiteSpace(addressableName) ? "[NO PREFAB]" : addressableName;
                        break;
#endif
                    }

                    var state = DTPoolBossInspectorUtility.Foldout(poolItem.isExpanded, itemName);
                    if (state != poolItem.isExpanded)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleExpandPool);
                        poolItem.isExpanded = state;
                    }

                    if (Application.isPlaying)
                    {
                        GUILayout.FlexibleSpace();

                        GUI.contentColor = DTPoolBossInspectorUtility.BrightTextColor;
                        if (poolItem.prefabTransform != null)
                        {
                            if (GUILayout.Button(new GUIContent(PoolBossLang.DespawnAll, PoolBossLang.DespawnAllPrefabs),
                                                 EditorStyles.toolbarButton, GUILayout.Width(80)))
                            {
                                PoolBoss.DespawnAllOfPrefab(poolItem.prefabTransform);
                                _isDirty = true;
                            }

                            var itemInfo = PoolBoss.PoolItemInfoByName(itemName);
                            if (itemInfo != null)
                            {
                                var spawnedCount   = itemInfo.SpawnedClones.Count;
                                var despawnedCount = itemInfo.DespawnedClones.Count;
                                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                                if (spawnedCount == 0)
                                {
                                    GUI.backgroundColor = DTPoolBossInspectorUtility.DeleteButtonColor;
                                }
                                else
                                {
                                    GUI.backgroundColor = DTPoolBossInspectorUtility.BrightTextColor;
                                }

                                var spawned = string.Format(PoolBossLang.SpawnedCount, spawnedCount, despawnedCount + spawnedCount);
                                var content = new GUIContent(spawned, PoolBossLang.SpawnedCountTooltip);
                                if (GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(110)))
                                {
                                    var obj = new List <GameObject>();
                                    foreach (var t in itemInfo.SpawnedClones)
                                    {
                                        obj.Add(t.gameObject);
                                    }

                                    if (obj.Count > 0)
                                    {
                                        Selection.objects = obj.ToArray();
                                    }
                                }

                                content = new GUIContent("Pk: " + itemInfo.Peak, PoolBossLang.ResetPeak);
                                if (Time.realtimeSinceStartup - itemInfo.PeakTime < .2f)
                                {
                                    GUI.backgroundColor = DTPoolBossInspectorUtility.AddButtonColor;
                                }
                                else if (itemInfo.Peak == 0)
                                {
                                    GUI.backgroundColor = DTPoolBossInspectorUtility.DeleteButtonColor;
                                }
                                else
                                {
                                    GUI.backgroundColor = DTPoolBossInspectorUtility.BrightTextColor;
                                }

                                if (GUILayout.Button(content, EditorStyles.miniButton, GUILayout.Width(64)))
                                {
                                    itemInfo.Peak     = Math.Max(0, itemInfo.SpawnedClones.Count);
                                    itemInfo.PeakTime = Time.realtimeSinceStartup;
                                    _isDirty          = true;
                                    _pool._changes++;
                                }

                                GUI.backgroundColor = Color.white;
                            }
                        }

                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUI.backgroundColor = DTPoolBossInspectorUtility.BrightButtonColor;
                        var selCatIndex = catNames.IndexOf(poolItem.categoryName);
                        var newCat      = EditorGUILayout.Popup(selCatIndex, catNames.ToArray(), GUILayout.Width(130));
                        if (newCat != selCatIndex)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangePoolItemCategory);
                            poolItem.categoryName = catNames[newCat];
                        }

                        GUI.backgroundColor = Color.white;

                        switch (poolItem.prefabSource)
                        {
                        case PoolBoss.PrefabSource.Prefab:
                            DTPoolBossInspectorUtility.FocusInProjectViewButton(PoolBossLang.PoolItemPrefab,
                                                                                poolItem.prefabTransform == null ? null : poolItem.prefabTransform.gameObject);
                            break;

#if ADDRESSABLES_ENABLED
                        case PoolBoss.PrefabSource.Addressable:
                            DTPoolBossInspectorUtility.FocusAddressableInProjectViewButton(PoolBossLang.PoolItemPrefab, poolItem.prefabAddressable);
                            break;
#endif
                        }
                    }

                    var buttonPressed = DTPoolBossInspectorUtility.AddFoldOutListItemButtons(i, matchingItems.Count,
                                                                                             PoolBossLang.PoolItem, false, null, true, false, true);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();

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

#if ADDRESSABLES_ENABLED
                        var newSource =
                            (PoolBoss.PrefabSource)EditorGUILayout.EnumPopup("Prefab Source", poolItem.prefabSource);
                        if (newSource != poolItem.prefabSource)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, "change Prefab Source");
                            poolItem.prefabSource = newSource;

                            if (poolItem.prefabSource == PoolBoss.PrefabSource.Addressable)
                            {
                                poolItem.prefabTransform = null; // clear it out to eliminate references
                            }
                        }
#endif

                        switch (poolItem.prefabSource)
                        {
                        case PoolBoss.PrefabSource.Prefab:
                            var newPrefab = (Transform)EditorGUILayout.ObjectField(PoolBossLang.Prefab, poolItem.prefabTransform, typeof(Transform), false);
                            if (newPrefab != poolItem.prefabTransform)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangePoolItemPrefab);
                                poolItem.prefabTransform = newPrefab;
                            }
                            break;

#if ADDRESSABLES_ENABLED
                        case PoolBoss.PrefabSource.Addressable:
                            var itemNumber = _pool.poolItems.FindIndex(delegate(PoolBossItem item)
                            {
                                return(item == poolItem);
                            });

                            serializedObject.Update();

                            var poolItemsProp = serializedObject.FindProperty(nameof(PoolBoss.poolItems));
                            var poolItemProp  =
                                poolItemsProp.GetArrayElementAtIndex(itemNumber).FindPropertyRelative(nameof(PoolBossItem.prefabAddressable));

                            EditorGUILayout.PropertyField(poolItemProp, new GUIContent(PoolBossLang.PrefabAddressable, PoolBossLang.PrefabAddressableTooltip), true);

                            serializedObject.ApplyModifiedProperties();
                            break;
#endif
                        }

                        var newPreloadQty = EditorGUILayout.IntSlider(PoolBossLang.PreloadQty, poolItem.instancesToPreload, 0, 10000);
                        if (newPreloadQty != poolItem.instancesToPreload)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangePreloadQty);
                            poolItem.instancesToPreload = newPreloadQty;
                        }

                        if (poolItem.instancesToPreload == 0)
                        {
                            DTPoolBossInspectorUtility.ShowColorWarning(PoolBossLang.PreloadQtyToZero);
                        }

                        var newAllow = EditorGUILayout.Toggle(PoolBossLang.AllowInstantiate, poolItem.allowInstantiateMore);
                        if (newAllow != poolItem.allowInstantiateMore)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleAllowInstantiate);
                            poolItem.allowInstantiateMore = newAllow;
                        }

                        if (poolItem.allowInstantiateMore)
                        {
                            var newLimit = EditorGUILayout.IntSlider(PoolBossLang.ItemLimit, poolItem.itemHardLimit, poolItem.instancesToPreload, 10000);
                            if (newLimit != poolItem.itemHardLimit)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangeItemLimit);
                                poolItem.itemHardLimit = newLimit;
                            }
                        }
                        else
                        {
                            var newRecycle = EditorGUILayout.Toggle(PoolBossLang.RecycleOldest, poolItem.allowRecycle);
                            if (newRecycle != poolItem.allowRecycle)
                            {
                                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleRecycleOldest);
                                poolItem.allowRecycle = newRecycle;
                            }
                        }

#if UNITY_5_5 || UNITY_5_6 || UNITY_2017_1_OR_NEWER
                        if (poolItem.prefabTransform != null)
                        {
                            var navMeshAgent = poolItem.prefabTransform.GetComponent <NavMeshAgent>();
                            if (navMeshAgent != null)
                            {
                                var content  = new GUIContent(PoolBossLang.EnableNavMesh, PoolBossLang.EnableNavMeshTooltip);
                                var newAgent = EditorGUILayout.Toggle(content, poolItem.enableNavMeshAgentOnSpawn);
                                if (newAgent != poolItem.enableNavMeshAgentOnSpawn)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ToggleEnableNavMesh);
                                    poolItem.enableNavMeshAgentOnSpawn = newAgent;
                                }

                                if (poolItem.enableNavMeshAgentOnSpawn)
                                {
                                    var newDelay = EditorGUILayout.IntSlider(PoolBossLang.NavMeshAgentDelay, poolItem.delayNavMeshEnableByFrames, 0, 200);
                                    if (newDelay != poolItem.delayNavMeshEnableByFrames)
                                    {
                                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ChangeNavMeshAgentDelay);
                                        poolItem.delayNavMeshEnableByFrames = newDelay;
                                    }
                                }
                            }
                        }
#endif

                        newLog = EditorGUILayout.Toggle(PoolBossLang.LogMessages, poolItem.logMessages);
                        if (newLog != poolItem.logMessages)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.LogMessagesToggle);
                            poolItem.logMessages = newLog;
                        }
                    }

                    switch (buttonPressed)
                    {
                    case DTPoolBossInspectorUtility.FunctionButtons.Remove:
                        itemToRemove = poolItem;
                        break;

                    case DTPoolBossInspectorUtility.FunctionButtons.Add:
                        indexToInsertAt  = _pool.poolItems.IndexOf(poolItem);
                        selectedCategory = cat;
                        break;

                    case DTPoolBossInspectorUtility.FunctionButtons.DespawnAll:
                        PoolBoss.DespawnAllOfPrefab(poolItem.prefabTransform);
                        break;

                    case DTPoolBossInspectorUtility.FunctionButtons.Copy:
                        itemToClone = poolItem;
                        break;
                    }

                    EditorGUILayout.EndVertical();
                    DTPoolBossInspectorUtility.AddSpaceForNonU5();
                }

                if (matchingItems.Count > 0)
                {
                    DTPoolBossInspectorUtility.EndGroupedControls();
                    DTPoolBossInspectorUtility.VerticalSpace(2);
                }
            }

            DTPoolBossInspectorUtility.VerticalSpace(2);
        }

        if (indexToShiftUp.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ShiftUp);
            var item = _pool._categories[indexToShiftUp.Value];
            _pool._categories.Insert(indexToShiftUp.Value - 1, item);
            _pool._categories.RemoveAt(indexToShiftUp.Value + 1);
            _isDirty = true;
        }

        if (indexToShiftDown.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ShiftDown);
            var index = indexToShiftDown.Value + 1;
            var item  = _pool._categories[index];
            _pool._categories.Insert(index - 1, item);
            _pool._categories.RemoveAt(index + 1);
            _isDirty = true;
        }

        if (catToDelete != null)
        {
            if (_pool.poolItems.FindAll(delegate(PoolBossItem x) { return(x.categoryName == catToDelete.CatName); }).Count > 0)
            {
                DTPoolBossInspectorUtility.ShowAlert(PoolBossLang.DeleteCategoryWithPool);
            }
            else if (_pool._categories.Count <= 1)
            {
                DTPoolBossInspectorUtility.ShowAlert(PoolBossLang.DeleteLastCategory);
            }
            else
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.DeleteCategory);
                _pool._categories.Remove(catToDelete);
                _isDirty = true;
            }
        }

        if (catRenaming != null)
        {
            // ReSharper disable once ForCanBeConvertedToForeach
            var isValidName = true;

            if (string.IsNullOrEmpty(catRenaming.ProspectiveName))
            {
                isValidName = false;
                DTPoolBossInspectorUtility.ShowAlert(PoolBossLang.BlankCategoryName);
            }

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var c = 0; c < _pool._categories.Count; c++)
            {
                var cat = _pool._categories[c];
                // ReSharper disable once InvertIf
                if (cat != catRenaming && cat.CatName == catRenaming.ProspectiveName)
                {
                    isValidName = false;
                    var txt = string.Format(PoolBossLang.CategoryNameUnique, catRenaming.ProspectiveName);
                    DTPoolBossInspectorUtility.ShowAlert(txt);
                }
            }

            if (isValidName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.UndoChangeCategory);

                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < _pool.poolItems.Count; i++)
                {
                    var item = _pool.poolItems[i];
                    if (item.categoryName == catRenaming.CatName)
                    {
                        item.categoryName = catRenaming.ProspectiveName;
                    }
                }

                catRenaming.CatName   = catRenaming.ProspectiveName;
                catRenaming.IsEditing = false;
                _isDirty = true;
            }
        }

        if (catEditing != null)
        {
            // ReSharper disable once ForCanBeConvertedToForeach
            for (var c = 0; c < _pool._categories.Count; c++)
            {
                var cat = _pool._categories[c];
                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (catEditing == cat)
                {
                    cat.IsEditing = true;
                }
                else
                {
                    cat.IsEditing = false;
                }

                _isDirty = true;
            }
        }

        if (itemToRemove != null)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.RemovePoolItem);
            _pool.poolItems.Remove(itemToRemove);
        }

        if (itemToClone != null)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.ClonePoolItem);
            var newItem = itemToClone.Clone();

            var oldIndex = _pool.poolItems.IndexOf(itemToClone);

            _pool.poolItems.Insert(oldIndex, newItem);
        }

        if (indexToInsertAt.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _pool, PoolBossLang.InsertPoolItem);
            _pool.poolItems.Insert(indexToInsertAt.Value, new PoolBossItem
            {
                categoryName = selectedCategory.CatName
            });
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target); // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 23
0
    private bool RenderEventTypeControls(EventDespawnSpecifics despawnSettings, string toggleText, TriggeredSpawner.EventType eventType)
    {
        DTInspectorUtility.VerticalSpace(2);
        EditorGUI.indentLevel = 0;

        var state = despawnSettings.eventEnabled;
        var text  = " " + toggleText;

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

        DTInspectorUtility.StartGroupHeader(0);

        var newTog = EditorGUILayout.BeginToggleGroup(text, despawnSettings.eventEnabled);

        if (newTog != despawnSettings.eventEnabled)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle " + toggleText + " enabled");
            despawnSettings.eventEnabled = newTog;
        }


        if (!despawnSettings.eventEnabled)
        {
            EditorGUILayout.EndToggleGroup();
            DTInspectorUtility.EndGroupHeader();
            return(_isDirty);
        }

        DTInspectorUtility.BeginGroupedControls();

        if (TriggeredSpawner.eventsWithTagLayerFilters.Contains(eventType))
        {
            DTInspectorUtility.StartGroupHeader(1);
            var newUseLayerFilter = EditorGUILayout.BeginToggleGroup(" Layer filters", despawnSettings.useLayerFilter);
            if (newUseLayerFilter != despawnSettings.useLayerFilter)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle Layer filters");
                despawnSettings.useLayerFilter = newUseLayerFilter;
            }
            DTInspectorUtility.EndGroupHeader();
            if (despawnSettings.useLayerFilter)
            {
                for (var i = 0; i < despawnSettings.matchingLayers.Count; i++)
                {
                    var newMatch = EditorGUILayout.LayerField("Layer Match " + (i + 1), despawnSettings.matchingLayers[i]);
                    if (newMatch == despawnSettings.matchingLayers[i])
                    {
                        continue;
                    }
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Layer Match");
                    despawnSettings.matchingLayers[i] = newMatch;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(12);
                GUI.contentColor = DTInspectorUtility.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a Layer Match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Layer Match");

                    despawnSettings.matchingLayers.Add(0);
                }
                GUILayout.Space(10);
                if (despawnSettings.matchingLayers.Count > 1)
                {
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last Layer Match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "remove Layer Match");

                        despawnSettings.matchingLayers.RemoveAt(despawnSettings.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            DTInspectorUtility.AddSpaceForNonU5();

            DTInspectorUtility.StartGroupHeader(1);
            despawnSettings.useTagFilter = EditorGUILayout.BeginToggleGroup(" Tag filter", despawnSettings.useTagFilter);
            DTInspectorUtility.EndGroupHeader();
            if (despawnSettings.useTagFilter)
            {
                for (var i = 0; i < despawnSettings.matchingTags.Count; i++)
                {
                    var newMatch = EditorGUILayout.TagField("Tag Match " + (i + 1), despawnSettings.matchingTags[i]);
                    if (newMatch == despawnSettings.matchingTags[i])
                    {
                        continue;
                    }
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Tag Match");
                    despawnSettings.matchingTags[i] = newMatch;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(12);
                GUI.contentColor = DTInspectorUtility.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a Tag Match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Tag Match");
                    despawnSettings.matchingTags.Add("Untagged");
                }
                GUILayout.Space(10);
                if (despawnSettings.matchingTags.Count > 1)
                {
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last Tag Match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "remove Tag Match");
                        despawnSettings.matchingTags.RemoveAt(despawnSettings.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();
        }
        else
        {
            EditorGUI.indentLevel = 0;
            DTInspectorUtility.ShowColorWarningBox("No additional properties for this event type.");
        }

        DTInspectorUtility.EndGroupedControls();

        EditorGUILayout.EndToggleGroup();
        DTInspectorUtility.EndGroupHeader();

        return(_isDirty);
    }
Exemplo n.º 24
0
    void EditSoundGroup(ButtonClicker sounds, ref string soundGroup, string label)
    {
        if (maInScene)
        {
            var existingIndex = groupNames.IndexOf(soundGroup);

            int?groupIndex = null;

            var noMatch = false;

            if (existingIndex >= 1)
            {
                groupIndex = EditorGUILayout.Popup(label, existingIndex, groupNames.ToArray());
            }
            else if (existingIndex == -1 && soundGroup == MasterAudio.NO_GROUP_NAME)
            {
                groupIndex = EditorGUILayout.Popup(label, existingIndex, groupNames.ToArray());
            }
            else                 // non-match
            {
                noMatch = true;

                var newGroup = EditorGUILayout.TextField(label, soundGroup);
                if (newGroup != soundGroup)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
                    soundGroup = newGroup;
                }
                var newIndex = EditorGUILayout.Popup("All Sound Types", -1, groupNames.ToArray());
                if (newIndex >= 0)
                {
                    groupIndex = newIndex;
                }
            }

            if (noMatch)
            {
                DTGUIHelper.ShowRedError("Sound Type found no match. Choose one from 'All Sound Types'.");
            }

            if (groupIndex.HasValue)
            {
                if (existingIndex != groupIndex.Value)
                {
                    UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
                }
                if (groupIndex.Value == -1)
                {
                    soundGroup = MasterAudio.NO_GROUP_NAME;
                }
                else
                {
                    soundGroup = groupNames[groupIndex.Value];
                }
            }
        }
        else
        {
            var newGroup = EditorGUILayout.TextField(label, soundGroup);
            if (newGroup != soundGroup)
            {
                soundGroup = newGroup;
                UndoHelper.RecordObjectPropertyForUndo(sounds, "change Sound Group");
            }
        }
    }
    public static string SelectCustomEventForVariable(ref bool isDirty, string customEventName, Object gameObject, string label, ref FunctionButtons buttonClicked)
    {
        var eventNames = LevelSettings.Instance.CustomEventNames;

        StartGroupHeader(1, false);

        var existingIndex = eventNames.IndexOf(customEventName);

        int?eventIndex = null;

        var noMatch = false;

        var isItemSelected = existingIndex >= 1;

        EditorGUILayout.BeginHorizontal();
        var isDeleteClicked = false;

        if (isItemSelected)
        {
            eventIndex      = EditorGUILayout.Popup(label, existingIndex, eventNames.ToArray());
            isDeleteClicked = ShowDeleteButton("Custom Event");
            EditorGUILayout.EndHorizontal();
        }
        else if (existingIndex == -1 && customEventName == LevelSettings.NoEventName)
        {
            eventIndex      = EditorGUILayout.Popup(label, existingIndex, eventNames.ToArray());
            isDeleteClicked = ShowDeleteButton("Custom Event");
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            // non-match
            noMatch = true;

            var newGroup = EditorGUILayout.TextField(label, customEventName);
            if (newGroup != customEventName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, gameObject, "change " + label);
                customEventName = newGroup;
            }

            isDeleteClicked = ShowDeleteButton("Custom Event");
            EditorGUILayout.EndHorizontal();
            var newIndex = EditorGUILayout.Popup("All Custom Events", -1, eventNames.ToArray());
            if (newIndex >= 0)
            {
                eventIndex = newIndex;
            }
        }

        if (isDeleteClicked)
        {
            buttonClicked = FunctionButtons.Remove;
        }

        if (noMatch)
        {
            ShowRedErrorBox("Custom Event found no match. Choose one from 'All Custom Events'.");
        }

        if (eventIndex.HasValue)
        {
            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (eventIndex.Value == -1)
            {
                customEventName = LevelSettings.NoEventName;
            }
            else
            {
                customEventName = eventNames[eventIndex.Value];
            }
        }

        EditorGUILayout.EndVertical();

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

        PlaylistController controller = (PlaylistController)target;

        MasterAudio.Instance = null;

        var ma = MasterAudio.Instance;

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

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

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

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

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

            int?groupIndex = null;

            var noPl    = false;
            var noMatch = false;

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

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

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

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


        var syncGroupList = new List <string>();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        var stat = (WorldVariable)target;

        LevelSettings.Instance = null; // clear cached version
        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        var isDirty = false;

        var newName = EditorGUILayout.TextField("Name", stat.transform.name);

        if (newName != stat.transform.name)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat.gameObject, "change Name");
            stat.transform.name = newName;
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Variable Type");
        GUILayout.FlexibleSpace();
        GUI.contentColor = DTInspectorUtility.BrightButtonColor;
        GUILayout.Label(WorldVariableTracker.GetVariableTypeFriendlyString(stat.varType));

        if (Application.isPlaying)
        {
            var sValue = "";

            switch (stat.varType)
            {
            case WorldVariableTracker.VariableType._integer:
                var _int = WorldVariableTracker.GetExistingWorldVariableIntValue(stat.name, stat.startingValue);
                sValue = _int.HasValue ? _int.Value.ToString() : "";
                break;

            case WorldVariableTracker.VariableType._float:
                var _float = WorldVariableTracker.GetExistingWorldVariableFloatValue(stat.name, stat.startingValue);
                sValue = _float.HasValue ? _float.Value.ToString(CultureInfo.InvariantCulture) : "";
                break;

            default:
                Debug.Log("add code for varType: " + stat.varType);
                break;
            }

            GUILayout.Label("Value:");

            GUILayout.Label(sValue);
        }

        GUILayout.Space(110);
        GUI.contentColor = Color.white;
        EditorGUILayout.EndHorizontal();

        if (Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Change Value", GUILayout.Width(100));
            GUILayout.FlexibleSpace();
            switch (stat.varType)
            {
            case WorldVariableTracker.VariableType._integer:
                stat.prospectiveValue = EditorGUILayout.IntField("", stat.prospectiveValue, GUILayout.Width(120));
                break;

            case WorldVariableTracker.VariableType._float:
                stat.prospectiveFloatValue = EditorGUILayout.FloatField("", stat.prospectiveFloatValue, GUILayout.Width(120));
                break;

            default:
                Debug.LogError("Add code for varType: " + stat.varType.ToString());
                break;
            }

            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            if (GUILayout.Button("Change Value", EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                var variable = WorldVariableTracker.GetWorldVariable(stat.name);

                switch (stat.varType)
                {
                case WorldVariableTracker.VariableType._integer:
                    variable.CurrentIntValue = stat.prospectiveValue;
                    break;

                case WorldVariableTracker.VariableType._float:
                    variable.CurrentFloatValue = stat.prospectiveFloatValue;
                    break;

                default:
                    Debug.LogError("Add code for varType: " + stat.varType.ToString());
                    break;
                }
            }
            GUI.contentColor = Color.white;

            GUILayout.Space(10);

            EditorGUILayout.EndHorizontal();
        }

        var newPersist = (WorldVariable.StatPersistanceMode)EditorGUILayout.EnumPopup("Persistence mode", stat.persistanceMode);

        if (newPersist != stat.persistanceMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Persistence Mode");
            stat.persistanceMode = newPersist;
        }

        var newChange = (WorldVariable.VariableChangeMode)EditorGUILayout.EnumPopup("Modifications allowed", stat.changeMode);

        if (newChange != stat.changeMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Modifications allowed");
            stat.changeMode = newChange;
        }

        switch (stat.varType)
        {
        case WorldVariableTracker.VariableType._float: {
            var newStart = EditorGUILayout.FloatField("Starting value", stat.startingValueFloat);
            if (newStart != stat.startingValueFloat)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Starting value");
                stat.startingValueFloat = newStart;
            }
            break;
        }

        case WorldVariableTracker.VariableType._integer: {
            var newStart = EditorGUILayout.IntField("Starting value", stat.startingValue);
            if (newStart != stat.startingValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Starting value");
                stat.startingValue = newStart;
            }
            break;
        }
        }

        var newNeg = EditorGUILayout.Toggle("Allow negative?", stat.allowNegative);

        if (newNeg != stat.allowNegative)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "toggle Allow negative");
            stat.allowNegative = newNeg;
        }

        DTInspectorUtility.StartGroupHeader();
        var newTopLimit = GUILayout.Toggle(stat.hasMaxValue, "Has max value?");

        if (newTopLimit != stat.hasMaxValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "toggle Has max value");
            stat.hasMaxValue = newTopLimit;
        }
        EditorGUILayout.EndVertical();

        if (stat.hasMaxValue)
        {
            EditorGUI.indentLevel = 0;
            switch (stat.varType)
            {
            case WorldVariableTracker.VariableType._integer:
                var newMax = EditorGUILayout.IntField("Max Value", stat.intMaxValue);
                if (newMax != stat.intMaxValue)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Max Value");
                    stat.intMaxValue = newMax;
                }
                break;

            case WorldVariableTracker.VariableType._float:
                var newFloatMax = EditorGUILayout.FloatField("Max Value", stat.floatMaxValue);
                if (newFloatMax != stat.floatMaxValue)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change Max Value");
                    stat.floatMaxValue = newFloatMax;
                }
                break;

            default:
                Debug.Log("add code for varType: " + stat.varType);
                break;
            }
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;

        DTInspectorUtility.AddSpaceForNonU5();

        DTInspectorUtility.StartGroupHeader();
        var newCanEnd = GUILayout.Toggle(stat.canEndGame, "Triggers game over?");

        if (newCanEnd != stat.canEndGame)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "toggle Triggers game over");
            stat.canEndGame = newCanEnd;
        }
        EditorGUILayout.EndVertical();
        if (stat.canEndGame)
        {
            EditorGUI.indentLevel = 0;
            var newMin = EditorGUILayout.IntField("G.O. min value", stat.endGameMinValue);
            if (newMin != stat.endGameMinValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change G.O. min value");
                stat.endGameMinValue = newMin;
            }

            var newMax = EditorGUILayout.IntField("G.O. max value", stat.endGameMaxValue);
            if (newMax != stat.endGameMaxValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "change G.O. max value");
                stat.endGameMaxValue = newMax;
            }
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        var listenerWasEmpty = stat.listenerPrefab == null;
        var newListener      = (WorldVariableListener)EditorGUILayout.ObjectField("Listener", stat.listenerPrefab, typeof(WorldVariableListener), true);

        if (newListener != stat.listenerPrefab)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, stat, "assign Listener");
            stat.listenerPrefab = newListener;
            if (listenerWasEmpty && stat.listenerPrefab != null)
            {
                // just assigned.
                var listener = stat.listenerPrefab.GetComponent <WorldVariableListener>();
                if (listener == null)
                {
                    DTInspectorUtility.ShowAlert("You cannot assign a listener that doesn't have a WorldVariableListener script in it.");
                    stat.listenerPrefab = null;
                }
                else
                {
                    listener.variableName = stat.transform.name;
                    listener.vType        = stat.varType;
                }
            }
        }

        if (GUI.changed || isDirty)
        {
            EditorUtility.SetDirty(target);     // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
Exemplo n.º 28
0
    public static DTInspectorUtility.FunctionButtons DisplayKillerFloat(ref bool isDirty, KillerFloat killFloat, string fieldLabel, Object srcObject, bool showDeleteButton = false, bool indent = false)
    {
        var oldBg = GUI.backgroundColor;

        var allStatNames = AllStatNamesOfType(WorldVariableTracker.VariableType._float);

        EditorGUILayout.BeginHorizontal();

        if (indent)
        {
            GUILayout.Space(12);
        }

        GUILayout.Label(fieldLabel, GUILayout.MinWidth(50));

        GUILayout.FlexibleSpace();

        var newVarIndex = -1;

        var unfoundVariableName = string.Empty;

        if (showDeleteButton)
        {
            var newModMode = (KillerVariable.ModMode)EditorGUILayout.EnumPopup("", killFloat.curModMode, GUILayout.Width(ModModeFieldWidth));
            if (newModMode != killFloat.curModMode)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Mod Mode for " + fieldLabel);
                killFloat.curModMode = newModMode;
            }
        }

        var fieldWidth    = showDeleteButton ? ShortFieldWidth : FieldWidth;
        var oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = TinyLabelWidth;

        switch (killFloat.variableSource)
        {
        case LevelSettings.VariableSource.Self:
            var newVal = EditorGUILayout.FloatField("F", killFloat.selfValue, GUILayout.MinWidth(fieldWidth));
            if (newVal != killFloat.selfValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change " + fieldLabel);
                killFloat.Value = newVal;
            }
            break;

        case LevelSettings.VariableSource.Variable:
            var oldIndex = allStatNames.IndexOf(killFloat.worldVariableName);
            if (oldIndex < 0)
            {
                unfoundVariableName = killFloat.worldVariableName;
                oldIndex            = 0;
            }

            newVarIndex = EditorGUILayout.Popup("F", oldIndex, allStatNames.ToArray(), GUILayout.MinWidth(fieldWidth));
            if (oldIndex != newVarIndex)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Variable for " + fieldLabel);
                killFloat.worldVariableName = allStatNames[newVarIndex];
            }
            break;
        }

        EditorGUIUtility.labelWidth = oldLabelWidth;

        GUI.backgroundColor = DTInspectorUtility.BrightButtonColor;
        var newSource = (LevelSettings.VariableSource)EditorGUILayout.EnumPopup(killFloat.variableSource, GUILayout.Width(70));

        if (newSource != killFloat.variableSource)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change source of " + fieldLabel);
            killFloat.variableSource = newSource;
        }
        GUI.backgroundColor = oldBg;

        var deletePressed = false;

        if (showDeleteButton)
        {
            GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
            if (GUILayout.Button(new GUIContent("Delete", "Remove this mod"), EditorStyles.miniButton, GUILayout.Width(50)))
            {
                deletePressed = true;
            }
            GUI.backgroundColor = oldBg;
        }

        EditorGUILayout.EndHorizontal();

        if (killFloat.variableSource != LevelSettings.VariableSource.Variable ||
            (killFloat.worldVariableName != LevelSettings.DropDownNoneOption && newVarIndex > 0))
        {
            return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None);
        }
        if (string.IsNullOrEmpty(unfoundVariableName))
        {
            DTInspectorUtility.ShowLargeBarAlertBox("No variable has been selected. " + fieldLabel + " will get a value of " + KillerFloat.DefaultValue + ".");
        }
        else
        {
            DTInspectorUtility.ShowRedErrorBox("Could not find variable '" + unfoundVariableName + "' to assign to " + fieldLabel + ". Please select another.");
        }

        return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None);
    }
Exemplo n.º 29
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        _settings  = (WavePrefabPool)target;
        _poolTrans = _settings.transform;

        WorldVariableTracker.ClearInGamePlayerStats();

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        _isDirty = false;

        var allStats = KillerVariablesHelper.AllStatNames;

        var           myParent      = _settings.transform.parent;
        LevelSettings levelSettings = null;

        if (myParent != null)
        {
            var levelSettingObj = myParent.parent;
            if (levelSettingObj != null)
            {
                levelSettings = levelSettingObj.GetComponent <LevelSettings>();
            }
        }

        if (levelSettings == null)
        {
            return;
        }

        EditorGUI.indentLevel = 0;
        var newSeq = (WavePrefabPool.PoolDispersalMode)EditorGUILayout.EnumPopup("Spawn Sequence", _settings.dispersalMode);

        if (newSeq != _settings.dispersalMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Spawn Sequence");
            _settings.dispersalMode = newSeq;
        }
        if (_settings.dispersalMode == WavePrefabPool.PoolDispersalMode.Randomized)
        {
            var newExhaust = EditorGUILayout.Toggle("Exhaust before repeat", _settings.exhaustiveList);
            if (newExhaust != _settings.exhaustiveList)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle Exhaust before repeat");
                _settings.exhaustiveList = newExhaust;
            }
        }

        var hadNoListener = _settings.listener == null;
        var newListener   = (WavePrefabPoolListener)EditorGUILayout.ObjectField("Listener", _settings.listener, typeof(WavePrefabPoolListener), true);

        if (newListener != _settings.listener)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "assign Listener");
            _settings.listener = newListener;
            if (hadNoListener && _settings.listener != null)
            {
                _settings.listener.sourcePrefabPoolName = _settings.transform.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Scene Objects Using");

        GUI.contentColor = DTInspectorUtility.BrightButtonColor;
        if (GUILayout.Button("List", EditorStyles.toolbarButton, GUILayout.MinWidth(55)))
        {
            FindMatchingSpawners(_poolTrans, false);
        }
        GUILayout.Space(10);
        if (GUILayout.Button("Select", EditorStyles.toolbarButton, GUILayout.MinWidth(55)))
        {
            FindMatchingSpawners(_poolTrans, true);
        }
        GUILayout.FlexibleSpace();

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

        DTInspectorUtility.VerticalSpace(4);

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUI.color = DTInspectorUtility.DragAreaColor;
            var dragArea = GUILayoutUtility.GetRect(0f, 30f, GUILayout.ExpandWidth(true));
            GUI.Box(dragArea, "Drag prefabs here in bulk to add them to the Pool!");
            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)
                    {
                        AddPoolItem(dragged);
                    }
                }
                Event.current.Use();
                break;
            }
            GUILayout.Space(4);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            DTInspectorUtility.VerticalSpace(4);
        }

        EditorGUI.indentLevel = 0;

        var state = _settings.isExpanded;
        var text  = string.Format("Prefab Pool Items ({0})", _settings.poolItems.Count);

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state)
        {
            GUI.backgroundColor = DTInspectorUtility.InactiveHeaderColor;
        }
        else
        {
            GUI.backgroundColor = DTInspectorUtility.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 != _settings.isExpanded)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand Prefab Pool Items");
            _settings.isExpanded = state;
        }
        // BUTTONS...
        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(100));

        DTInspectorUtility.ResetColors();

        var alphaSort = false;

        //DTInspectorUtility.UseLightSkinButtonColor();
        // Add expand/collapse buttons if there are items in the list
        if (_settings.poolItems.Count > 0)
        {
            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            alphaSort        = GUILayout.Button("Alpha Sort", EditorStyles.toolbarButton, GUILayout.Height(16));

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

            const string expandIcon = "Expand";
            content = new GUIContent(expandIcon, "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Height(16));
            if (masterExpand)
            {
                ExpandCollapseAll(_settings, true);
            }
            if (masterCollapse)
            {
                ExpandCollapseAll(_settings, false);
            }
            GUI.contentColor = Color.white;
        }
        else
        {
            GUILayout.FlexibleSpace();
        }

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

        var topAdded = false;

        var addText = string.Format("Click to add Pool item{0}.", _settings.poolItems.Count > 0 ? " before the first" : "");

        GUI.contentColor = DTInspectorUtility.AddButtonColor;
        // Main Add button
        if (GUILayout.Button(new GUIContent("Add", addText), EditorStyles.toolbarButton, GUILayout.Height(16)))
        {
            topAdded = true;
        }
        GUI.contentColor = Color.white;

        GUILayout.Space(4);

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

        int?itemToDelete    = null;
        int?itemToInsert    = null;
        int?itemToShiftUp   = null;
        int?itemToShiftDown = null;

        if (_settings.isExpanded)
        {
            DTInspectorUtility.BeginGroupedControls();
            for (var i = 0; i < _settings.poolItems.Count; i++)
            {
                var item = _settings.poolItems[i];

                DTInspectorUtility.StartGroupHeader(1);

                EditorGUILayout.BeginHorizontal();
                EditorGUI.indentLevel = 1;

                var sName = "";
                if (!item.isExpanded)
                {
                    if (item.prefabToSpawn == null)
                    {
                        sName = " " + LevelSettings.EmptyValue;
                    }
                    else
                    {
                        sName = " (" + item.prefabToSpawn.name + ")";
                    }
                }

                var sDisabled    = "";
                var itemDisabled = item.activeMode == LevelSettings.ActiveItemMode.Never;
                if (!item.isExpanded && itemDisabled)
                {
                    sDisabled = " - DISABLED";
                }

                var newItemExpanded = DTInspectorUtility.Foldout(item.isExpanded,
                                                                 string.Format("Pool Item #{0}{1}{2}", (i + 1), sName, sDisabled));
                if (newItemExpanded != item.isExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand Pool Item");
                    item.isExpanded = newItemExpanded;
                }

                GUILayout.FlexibleSpace();

                if (Application.isPlaying)
                {
                    GUI.contentColor = DTInspectorUtility.BrightTextColor;
                    var itemCount = _settings.PoolInstancesOfIndex(i);
                    GUILayout.Label("Remaining: " + itemCount);
                    GUI.contentColor = Color.white;
                }

                var poolItemButton = DTInspectorUtility.AddFoldOutListItemButtons(i, _settings.poolItems.Count, "Pool Item", false, true);

                switch (poolItemButton)
                {
                case DTInspectorUtility.FunctionButtons.Remove:
                    itemToDelete = i;
                    _isDirty     = true;
                    break;

                case DTInspectorUtility.FunctionButtons.Add:
                    itemToInsert = i;
                    _isDirty     = true;
                    break;

                case DTInspectorUtility.FunctionButtons.ShiftUp:
                    itemToShiftUp = i;
                    _isDirty      = true;
                    break;

                case DTInspectorUtility.FunctionButtons.ShiftDown:
                    itemToShiftDown = i;
                    _isDirty        = true;
                    break;
                }

                EditorGUI.indentLevel = 0;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                if (itemDisabled)
                {
                    DTInspectorUtility.ShowColorWarningBox("This item is currently disabled and will never spawn.");
                }

                if (!item.isExpanded)
                {
                    EditorGUILayout.EndVertical();
                    continue;
                }
                EditorGUI.indentLevel = 0;

                if (item.prefabToSpawn == null && !itemDisabled)
                {
                    DTInspectorUtility.ShowColorWarningBox("Nothing will spawn when this item is chosen from the pool.");
                }

                var newActive = (LevelSettings.ActiveItemMode)EditorGUILayout.EnumPopup("Active Mode", item.activeMode);
                if (newActive != item.activeMode)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle Active Mode");
                    item.activeMode = newActive;
                }

                switch (item.activeMode)
                {
                case LevelSettings.ActiveItemMode.IfWorldVariableInRange:
                case LevelSettings.ActiveItemMode.IfWorldVariableOutsideRange:
                    var missingStatNames = new List <string>();
                    missingStatNames.AddRange(allStats);
                    missingStatNames.RemoveAll(delegate(string obj) {
                        return(item.activeItemCriteria.HasKey(obj));
                    });

                    var newStat = EditorGUILayout.Popup("Add Active Limit", 0, missingStatNames.ToArray());
                    if (newStat != 0)
                    {
                        AddActiveLimit(missingStatNames[newStat], item);
                    }

                    if (item.activeItemCriteria.statMods.Count == 0)
                    {
                        DTInspectorUtility.ShowRedErrorBox("You have no Active Limits. Item will never be Active.");
                    }
                    else
                    {
                        EditorGUILayout.Separator();

                        int?indexToDelete = null;

                        for (var j = 0; j < item.activeItemCriteria.statMods.Count; j++)
                        {
                            var modifier = item.activeItemCriteria.statMods[j];
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(15);
                            var statName = modifier._statName;
                            GUILayout.Label(statName);

                            GUILayout.FlexibleSpace();
                            GUILayout.Label("Min");

                            switch (modifier._varTypeToUse)
                            {
                            case WorldVariableTracker.VariableType._integer:
                                var newMin = EditorGUILayout.IntField(modifier._modValueIntMin, GUILayout.MaxWidth(60));
                                if (newMin != modifier._modValueIntMin)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Min");
                                    modifier._modValueIntMin = newMin;
                                }

                                GUILayout.Label("Max");
                                var newMax = EditorGUILayout.IntField(modifier._modValueIntMax, GUILayout.MaxWidth(60));
                                if (newMax != modifier._modValueIntMax)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Max");
                                    modifier._modValueIntMax = newMax;
                                }
                                break;

                            case WorldVariableTracker.VariableType._float:
                                var newMinFloat = EditorGUILayout.FloatField(modifier._modValueFloatMin, GUILayout.MaxWidth(60));
                                if (newMinFloat != modifier._modValueFloatMin)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Min");
                                    modifier._modValueFloatMin = newMinFloat;
                                }

                                GUILayout.Label("Max");
                                var newMaxFloat = EditorGUILayout.FloatField(modifier._modValueFloatMax, GUILayout.MaxWidth(60));
                                if (newMaxFloat != modifier._modValueFloatMax)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Max");
                                    modifier._modValueFloatMax = newMaxFloat;
                                }
                                break;

                            default:
                                Debug.LogError("Add code for varType: " + modifier._varTypeToUse.ToString());
                                break;
                            }
                            var oldBG = GUI.backgroundColor;

                            GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
                            if (GUILayout.Button(new GUIContent("Delete", "Remove this limit"), EditorStyles.miniButtonMid, GUILayout.MaxWidth(64)))
                            {
                                indexToDelete = j;
                            }
                            GUI.backgroundColor = oldBG;
                            GUILayout.Space(5);
                            EditorGUILayout.EndHorizontal();

                            var min = modifier._varTypeToUse == WorldVariableTracker.VariableType._integer ? modifier._modValueIntMin : modifier._modValueFloatMin;
                            var max = modifier._varTypeToUse == WorldVariableTracker.VariableType._integer ? modifier._modValueIntMax : modifier._modValueFloatMax;

                            if (min > max)
                            {
                                DTInspectorUtility.ShowRedErrorBox(modifier._statName + " Min cannot exceed Max, please fix!");
                            }
                        }

                        DTInspectorUtility.ShowColorWarningBox("Limits are inclusive: i.e. 'Above' means >=");
                        if (indexToDelete.HasValue)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "delete Active Limit");
                            item.activeItemCriteria.DeleteByIndex(indexToDelete.Value);
                        }

                        DTInspectorUtility.VerticalSpace(2);
                    }

                    break;
                }

                var newPrefab = (Transform)EditorGUILayout.ObjectField("Prefab", item.prefabToSpawn, typeof(Transform), true);
                if (newPrefab != item.prefabToSpawn)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Prefab");
                    item.prefabToSpawn = newPrefab;
                }

                KillerVariablesHelper.DisplayKillerInt(ref _isDirty, item.thisWeight, "Weight", _settings);
                EditorGUILayout.EndVertical();
                DTInspectorUtility.AddSpaceForNonU5();
            }

            DTInspectorUtility.EndGroupedControls();
        }

        if (topAdded)
        {
            var newItem = new WavePrefabPoolItem();
            var index   = 0;
            if (_settings.poolItems.Count > 0)
            {
                index = _settings.poolItems.Count - 1;
            }

            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Prefab Pool Item");
            _settings.poolItems.Insert(index, newItem);
        }
        else if (itemToDelete.HasValue)
        {
            if (_settings.poolItems.Count == 1)
            {
                DTInspectorUtility.ShowAlert("You cannot delete the only Prefab Pool item. Delete the entire Pool from the hierarchy if you wish.");
            }
            else
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "remove Prefab Pool Item");
                _settings.poolItems.RemoveAt(itemToDelete.Value);
            }
        }
        else if (itemToInsert.HasValue)
        {
            var newItem = new WavePrefabPoolItem();
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Prefab Pool Item");
            _settings.poolItems.Insert(itemToInsert.Value + 1, newItem);
        }

        if (itemToShiftUp.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "shift up Prefab Pool Item");
            var item = _settings.poolItems[itemToShiftUp.Value];
            _settings.poolItems.Insert(itemToShiftUp.Value - 1, item);
            _settings.poolItems.RemoveAt(itemToShiftUp.Value + 1);
        }

        if (itemToShiftDown.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "shift down Prefab Pool Item");
            var index = itemToShiftDown.Value + 1;
            var item  = _settings.poolItems[index];
            _settings.poolItems.Insert(index - 1, item);
            _settings.poolItems.RemoveAt(index + 1);
        }

        if (alphaSort)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "Alpha Sort Prefab Pool Items");
            _settings.poolItems.Sort(delegate(WavePrefabPoolItem x, WavePrefabPoolItem y) {
                if (x.prefabToSpawn == null)
                {
                    return(-1);
                }
                if (y.prefabToSpawn == null)
                {
                    return(1);
                }

                return(x.prefabToSpawn.name.CompareTo(y.prefabToSpawn.name));
            });
        }

        if (GUI.changed || topAdded || _isDirty)
        {
            EditorUtility.SetDirty(target);     // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        EditorGUI.indentLevel = 0;
        var isDirty = false;

        _group = (DynamicSoundGroup)target;

        _group = RescanChildren(_group);

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

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

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

        if (!isValid)
        {
            return;
        }

        var isInProjectView = DTGUIHelper.IsPrefabInProjectView(_group);

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

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

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

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

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

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

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

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

            EditorGUILayout.EndToggleGroup();
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        EditorGUI.indentLevel = 0;

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

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

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

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

        int?deadChildIndex = null;

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

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

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

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

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

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

                GUI.color = Color.white;

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

                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

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

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

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

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

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

                GUILayout.FlexibleSpace();

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

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

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

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

                EditorGUILayout.EndHorizontal();

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

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

                switch (variation.audLocation)
                {
                case MasterAudio.AudioLocation.Clip:
                    var newClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", variation.audio.clip, typeof(AudioClip), false);
                    if (newClip != variation.audio.clip)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(variation.audio, "change Audio Clip");
                        variation.audio.clip = newClip;
                    }
                    break;

                case MasterAudio.AudioLocation.ResourceFile:
                    if (oldLocation != variation.audLocation)
                    {
                        if (variation.audio.clip != null)
                        {
                            Debug.Log("Audio clip removed to prevent unnecessary memory usage on Resource file Variation.");
                        }
                        variation.audio.clip = null;
                    }

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

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

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

                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

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

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

                                UndoHelper.RecordObjectPropertyForUndo(variation, "change Resource Filename");
                                variation.resourceFileName = aClip.name;
                            }
                        }
                        Event.current.Use();
                        break;
                    }
                    EditorGUILayout.EndVertical();

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

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

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

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

                EditorUtility.SetDirty(variation.audio);

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

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

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

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

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

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

                EditorGUILayout.EndToggleGroup();

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

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

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

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

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

                EditorGUILayout.EndToggleGroup();

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

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

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

                EditorGUILayout.EndToggleGroup();

                var newFades = EditorGUILayout.BeginToggleGroup("Use Custom Fading", variation.useFades);
                if (newFades != variation.useFades)
                {
                    UndoHelper.RecordObjectPropertyForUndo(variation, "toggle Use Custom Fading");
                    variation.useFades = newFades;
                }

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

                    var newFadeOut = EditorGUILayout.Slider("Fade Out time (sec)", variation.fadeOutTime, 0f, 10f);
                    if (newFadeOut != variation.fadeOutTime)
                    {
                        UndoHelper.RecordObjectPropertyForUndo(variation, "change Fade Out Time");
                        variation.fadeOutTime = newFadeOut;
                    }
                }
                EditorGUILayout.EndToggleGroup();

                EditorGUILayout.Separator();
            }
        }

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

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

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



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

        //DrawDefaultInspector();
    }