Ejemplo n.º 1
0
 public static void ShowErrorIfMissingVariable(string varName)
 {
     if (!WorldVariableTracker.VariableExistsInScene(varName))
     {
         DTInspectorUtility.ShowRedErrorBox(string.Format("Could not find World Variable '{0}'. Please fix.", varName));
     }
 }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 760, 100), "Click on enemies to do 1 damage to them. This level has one repeated wave. After each wave, the enemies get an additional hit point so it gets harder and harder! This is done with the Wave Repeat Bonus setting of the World Variable 'Enemy Toughness' which is assigned to the enemy's Hit Points. Pool Boss is set up correctly in this Scene with 2 prefabs.");

        var scoreVar      = WorldVariableTracker.GetWorldVariable("Score");
        var experienceVar = WorldVariableTracker.GetWorldVariable("Experience Points");
        var healthVar     = WorldVariableTracker.GetWorldVariable("Health");
        var livesVar      = WorldVariableTracker.GetWorldVariable("Lives");

        if (scoreVar != null)
        {
            GUI.Label(new Rect(10, 120, 100, 30), "Score: " + scoreVar.CurrentIntValue);
        }
        if (experienceVar != null)
        {
            GUI.Label(new Rect(10, 160, 100, 30), "Exp: " + experienceVar.CurrentIntValue);
        }
        if (healthVar != null)
        {
            GUI.Label(new Rect(10, 190, 100, 30), "Health: " + healthVar.CurrentIntValue);
        }
        if (livesVar != null)
        {
            GUI.Label(new Rect(10, 220, 100, 30), "lives: " + livesVar.CurrentIntValue);
        }
    }
    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 760, 130), "This scene has 6 waves of various settings. Left / right arrow keys and mouse click to fire. Feel free to tweak the settings. Wave 1 will repeat until you have 1000 score. " +
                  "Wave 3 will be skipped if you have 3000 score or more. Notice the music changing in wave 3, and the 'prefab pool' in wave 7 which allows for spawning of mutiple different prefabs from the same spawner wave. " +
                  "Wave 7 repeats forever and changes the items in its prefab pool depending on your score! " +
                  "We have included a KillableListenerSubclass as an example which listens for events on the Player prefab. It's in the Main Camera prefab. Also note that the player gets 5000 Experience Points for completing each of the first two levels. "
                  + "Score and the other World Variables displayed onscreen are using Legacy Unity GUI. For an example of Unity 4.6 uGUI, install the optional package. "
                  + "For support, check the readme file for links! Happy gaming!");

        var scoreVar      = WorldVariableTracker.GetWorldVariable("Score");
        var experienceVar = WorldVariableTracker.GetWorldVariable("Experience Points");
        var healthVar     = WorldVariableTracker.GetWorldVariable("Health");
        var livesVar      = WorldVariableTracker.GetWorldVariable("Lives");

        if (scoreVar != null)
        {
            GUI.Label(new Rect(10, 150, 100, 20), "Score: " + scoreVar.CurrentIntValue);
        }
        if (experienceVar != null)
        {
            GUI.Label(new Rect(10, 170, 100, 20), "Exp: " + experienceVar.CurrentIntValue);
        }
        if (healthVar != null)
        {
            GUI.Label(new Rect(10, 190, 100, 20), "Health: " + healthVar.CurrentIntValue);
        }
        if (livesVar != null)
        {
            GUI.Label(new Rect(10, 210, 100, 20), "lives: " + livesVar.CurrentIntValue);
        }
    }
        private void Set()
        {
            var trans    = ((GameObject)gameObject.Value).transform;
            var modifier = new WorldVariableModifier(_name.Value, WorldVariableTracker.VariableType._float);

            modifier._modValueFloatAmt.curModMode = KillerVariable.ModMode.Set;
            modifier._modValueFloatAmt.Value      = value.Value;

            WorldVariableTracker.ModifyPlayerStat(modifier, trans);
        }
Ejemplo n.º 6
0
    public int LogIfInvalid(Transform trans, string fieldName, int?levelNum = null, int?waveNum = null, string trigEventName = null)
    {
        var val = Value; // trigger Valid or not evaluation

        if (_isValid)
        {
            return(val);
        }

        WorldVariableTracker.LogIfInvalidWorldVariable(worldVariableName, trans, fieldName, levelNum, waveNum, trigEventName);

        return(val);
    }
Ejemplo n.º 7
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));
    }
Ejemplo n.º 8
0
    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 760, 90), "This scene shows how Composite Killables can be set up with zero code-writing. The mother ship has 2 sub-Killables of 'Fighter2', which each have a sub-Killable of 'Fighter1R'. Fighter2 is set to be invincible while children are alive, and Mothership is set the same. So you have to destroy the Fighter1R, then the Fighter2 (both sides), then the Mothership. This can be used to make uber-bosses and fortresses. A custom event is used to make the rotation of the spawners (Fighter2) look at you when you fire.");

        var scoreVar = WorldVariableTracker.GetWorldVariable("Score");
        var livesVar = WorldVariableTracker.GetWorldVariable("Lives");

        if (scoreVar != null)
        {
            GUI.Label(new Rect(10, 120, 100, 30), "Score: " + scoreVar.CurrentIntValue);
        }
        if (livesVar != null)
        {
            GUI.Label(new Rect(10, 150, 100, 30), "lives: " + livesVar.CurrentIntValue);
        }
    }
Ejemplo n.º 9
0
    // ReSharper disable once UnusedMember.Local
    void Start()
    {
        if (listenerPrefab == null)
        {
            return;
        }
        var variable = WorldVariableTracker.GetWorldVariable(name);

        if (variable == null)
        {
            return;
        }

        var curVal = variable.CurrentIntValue;

        listenerPrefab.UpdateValue(curVal);
    }
Ejemplo n.º 10
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();
    }
Ejemplo n.º 11
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();
    }
    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();
    }
Ejemplo n.º 13
0
    void FillPool()
    {
        // fill weighted pool
        for (var item = 0; item < poolItems.Count; item++)
        {
            var poolItem = poolItems[item];

            var includeItem = true;

            switch (poolItem.activeMode)
            {
            case LevelSettings.ActiveItemMode.Always:
                break;

            case LevelSettings.ActiveItemMode.Never:
                continue;

            case LevelSettings.ActiveItemMode.IfWorldVariableInRange:
                if (poolItem.activeItemCriteria.statMods.Count == 0)
                {
                    includeItem = false;
                }

                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < poolItem.activeItemCriteria.statMods.Count; i++)
                {
                    var stat = poolItem.activeItemCriteria.statMods[i];
                    if (!WorldVariableTracker.VariableExistsInScene(stat._statName))
                    {
                        Debug.LogError(string.Format("Prefab Pool '{0}' could not find World Variable '{1}', which is used in its Active Item Criteria.",
                                                     transform.name,
                                                     stat._statName));
                        includeItem = false;
                        break;
                    }

                    var variable = WorldVariableTracker.GetWorldVariable(stat._statName);
                    if (variable == null)
                    {
                        includeItem = false;
                        break;
                    }
                    var varVal = stat._varTypeToUse == WorldVariableTracker.VariableType._integer ? variable.CurrentIntValue : variable.CurrentFloatValue;

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

                    if (min > max)
                    {
                        LevelSettings.LogIfNew("The Min cannot be greater than the Max for Active Item Limit in Prefab Pool '" + transform.name + "'. Skipping item '" + poolItem.prefabToSpawn.name + "'.");
                        includeItem = false;
                        break;
                    }

                    if (!(varVal < min) && !(varVal > max))
                    {
                        continue;
                    }
                    includeItem = false;
                    break;
                }

                break;

            case LevelSettings.ActiveItemMode.IfWorldVariableOutsideRange:
                if (poolItem.activeItemCriteria.statMods.Count == 0)
                {
                    includeItem = false;
                }

                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < poolItem.activeItemCriteria.statMods.Count; i++)
                {
                    var stat     = poolItem.activeItemCriteria.statMods[i];
                    var variable = WorldVariableTracker.GetWorldVariable(stat._statName);
                    if (variable == null)
                    {
                        includeItem = false;
                        break;
                    }
                    var varVal = stat._varTypeToUse == WorldVariableTracker.VariableType._integer ? variable.CurrentIntValue : variable.CurrentFloatValue;

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

                    if (min > max)
                    {
                        LevelSettings.LogIfNew("The Min cannot be greater than the Max for Active Item Limit in Prefab Pool '" + transform.name + "'. Skipping item '" + poolItem.prefabToSpawn.name + "'.");
                        includeItem = false;
                        break;
                    }

                    if (!(varVal >= min) || !(varVal <= max))
                    {
                        continue;
                    }
                    includeItem = false;
                    break;
                }

                break;
            }

            if (!includeItem)
            {
                continue;
            }

            for (var i = 0; i < poolItem.thisWeight.Value; i++)
            {
                _poolItemIndexes.Add(item);
            }
        }

        if (_poolItemIndexes.Count == 0)
        {
            LevelSettings.LogIfNew("The Prefab Pool '" + name + "' has no active Prefab Pool items. Please add some or delete the Prefab pool before continuing. Disabling Core GameKit.");
            LevelSettings.IsGameOver = true;
            return;
        }

        _isValid = true;
    }
        private void Get()
        {
            var variable = WorldVariableTracker.GetWorldVariable(_name.Value);

            store.Value = variable.CurrentFloatValue;
        }
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        _settings = (WavePrefabPoolGroup)target;

        WorldVariableTracker.ClearInGamePlayerStats();

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        _isDirty = false;

        DTInspectorUtility.BeginGroupedControls();

        DTInspectorUtility.StartGroupHeader();
        EditorGUI.indentLevel = 1;
        var newExp = DTInspectorUtility.Foldout(_settings.newPrefabPoolExpanded, "Create New Prefab Pools");

        if (newExp != _settings.newPrefabPoolExpanded)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand Create New Prefab Pools");
            _settings.newPrefabPoolExpanded = newExp;
        }
        EditorGUILayout.EndVertical();

        if (_settings.newPrefabPoolExpanded)
        {
            EditorGUI.indentLevel = 0;
            var newPoolName = EditorGUILayout.TextField("New Pool Name", _settings.newPrefabPoolName);
            if (newPoolName != _settings.newPrefabPoolName)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change New Pool Name");
                _settings.newPrefabPoolName = newPoolName;
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(6);
            GUI.contentColor = DTInspectorUtility.AddButtonColor;
            if (GUILayout.Button("Create Prefab Pool", EditorStyles.toolbarButton, GUILayout.MaxWidth(110)))
            {
                CreatePrefabPool();
            }
            GUI.contentColor = Color.white;
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();

        DTInspectorUtility.VerticalSpace(2);

        var pools = LevelSettings.GetAllPrefabPools;

        if (pools.Count == 0)
        {
            DTInspectorUtility.ShowColorWarningBox("You currently have no Prefab Pools.");
        }

        foreach (var pool in pools)
        {
            DTInspectorUtility.StartGroupHeader(1, false);
            EditorGUILayout.BeginHorizontal();

            var poolScript = pool.GetComponent <WavePrefabPool>();

            var itemName = pool.name + " (" + poolScript.poolItems.Count + " ";
            itemName += (poolScript.poolItems.Count == 1 ? "item" : "items") + ")";
            GUILayout.Label(itemName);

            GUILayout.FlexibleSpace();

            var buttonPressed = DTInspectorUtility.AddControlButtons("Prefab Pool");
            if (buttonPressed == DTInspectorUtility.FunctionButtons.Edit)
            {
                Selection.activeGameObject = pool.gameObject;
            }

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

        DTInspectorUtility.EndGroupedControls();

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