/// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, RequiredAttribute attribute, GUIContent label)
        {
            if (property.ValueEntry.BaseValueType.IsValueType)
            {
                SirenixEditorGUI.ErrorMessageBox("Value types cannot be null, and thus cannot be marked as required.");
                return;
            }

            // Message context.
            PropertyContext <StringMemberHelper> context = null;

            if (attribute.ErrorMessage != null)
            {
                context = property.Context.Get <StringMemberHelper>(this, "ErrorMessage", (StringMemberHelper)null);
                if (context.Value == null)
                {
                    context.Value = new StringMemberHelper(property.ParentType, attribute.ErrorMessage);
                }

                if (context.Value.ErrorMessage != null)
                {
                    SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
                }
            }

            var isMissing = CheckIsMissing(property);

            if (isMissing)
            {
                string msg = attribute.ErrorMessage != null?context.Value.GetString(property) : (property.NiceName + " is required.");

                if (attribute.MessageType == InfoMessageType.Warning)
                {
                    SirenixEditorGUI.WarningMessageBox(msg);
                }
                else if (attribute.MessageType == InfoMessageType.Error)
                {
                    SirenixEditorGUI.ErrorMessageBox(msg);
                }
                else
                {
                    EditorGUILayout.HelpBox(msg, (MessageType)attribute.MessageType);
                }
            }

            var key = UniqueDrawerKey.Create(property, this);

            SirenixEditorGUI.BeginShakeableGroup(key);
            this.CallNextDrawer(property, label);
            SirenixEditorGUI.EndShakeableGroup(key);

            if (!isMissing && CheckIsMissing(property))
            {
                SirenixEditorGUI.StartShakingGroup(key);
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            // Message context.
            PropertyContext <StringMemberHelper> context = null;

            if (this.Attribute.ErrorMessage != null)
            {
                context = this.Property.Context.Get <StringMemberHelper>(this, "ErrorMessage", (StringMemberHelper)null);
                if (context.Value == null)
                {
                    //context.Value = new StringMemberHelper(property.ParentType, attribute.ErrorMessage);
                    context.Value = new StringMemberHelper(this.Property, this.Attribute.ErrorMessage);
                }

                if (context.Value.ErrorMessage != null)
                {
                    SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
                }
            }

            var isMissing = CheckIsMissing(this.Property);

            if (isMissing)
            {
                string msg = this.Attribute.ErrorMessage != null?context.Value.GetString(this.Property) : (this.Property.NiceName + " is required.");

                if (this.Attribute.MessageType == InfoMessageType.Warning)
                {
                    SirenixEditorGUI.WarningMessageBox(msg);
                }
                else if (this.Attribute.MessageType == InfoMessageType.Error)
                {
                    SirenixEditorGUI.ErrorMessageBox(msg);
                }
                else
                {
                    EditorGUILayout.HelpBox(msg, (MessageType)this.Attribute.MessageType);
                }
            }

            var key = UniqueDrawerKey.Create(this.Property, this);

            SirenixEditorGUI.BeginShakeableGroup(key);
            this.CallNextDrawer(label);
            SirenixEditorGUI.EndShakeableGroup(key);

            if (!isMissing && CheckIsMissing(this.Property))
            {
                SirenixEditorGUI.StartShakingGroup(key);
            }
        }
        protected override void DrawPropertyLayout(GUIContent label)
        {
            if (this.validationResults.Count == 0)
            {
                this.CallNextDrawer(label);
                return;
            }

            GUILayout.BeginVertical();
            SirenixEditorGUI.BeginShakeableGroup(this.shakeGroupKey);

            for (int i = 0; i < this.validationResults.Count; i++)
            {
                var result = this.validationResults[i];

                if (Event.current.type == EventType.Layout && (this.rerunFullValidation || result.Setup.Validator.RevalidationCriteria == RevalidationCriteria.Always))
                {
                    var formerResultType = result.ResultType;

                    result.Setup.ParentInstance = this.Property.ParentValues[0];
                    result.Setup.Value          = this.ValueEntry.Values[0];

                    result.RerunValidation();

                    if (formerResultType != result.ResultType && result.ResultType != ValidationResultType.Valid)
                    {
                        // We got a new result that was not valid
                        SirenixEditorGUI.StartShakingGroup(this.shakeGroupKey);
                    }
                }

                if (result.ResultType == ValidationResultType.Error)
                {
                    SirenixEditorGUI.ErrorMessageBox(result.Message);
                }
                else if (result.ResultType == ValidationResultType.Warning)
                {
                    SirenixEditorGUI.WarningMessageBox(result.Message);
                }
            }

            if (Event.current.type == EventType.Layout)
            {
                this.rerunFullValidation = false;
            }

            this.CallNextDrawer(label);
            SirenixEditorGUI.EndShakeableGroup(this.shakeGroupKey);
            GUILayout.EndVertical();
        }
Beispiel #4
0
    protected override void DrawPropertyLayout(GUIContent label)
    {
        display = this.ValueEntry.SmartValue.ToString();

        SirenixEditorGUI.BeginShakeableGroup(key);

        display = SirenixEditorFields.TextField(label, display);

        if (DateTime.TryParse(display, out DateTime result))
        {
            this.ValueEntry.SmartValue = result;
        }
        else
        {
            SirenixEditorGUI.StartShakingGroup(key);
        }

        SirenixEditorGUI.EndShakeableGroup(key);
    }
        /// <summary>
        /// Handles the Minesweeper game.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            Rect rect = EditorGUILayout.GetControlRect();

            this.ValueEntry.SmartValue = Mathf.Clamp(SirenixEditorFields.IntField(rect.AlignLeft(rect.width - 80 - 4), "Number of Bombs", this.ValueEntry.SmartValue), 1, (BoardSize * BoardSize) / 4);

            // Start game
            if (GUI.Button(rect.AlignRight(80), "Start"))
            {
                this.StartGame(this.ValueEntry.SmartValue);
            }

            // Game
            SirenixEditorGUI.BeginShakeableGroup(this.Key);
            if (this.isRunning)
            {
                this.Game();
            }
            SirenixEditorGUI.EndShakeableGroup(this.Key);
        }
Beispiel #6
0
        /// <summary>
        /// Handles the Minesweeper game.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <int> entry, MinesweeperAttribute attribute, GUIContent label)
        {
            PropertyContext <GameContext> context;

            if (entry.Context.Get(this, "GameContext", out context))
            {
                context.Value = new GameContext()
                {
                    IsRunning    = false,
                    GameOver     = false,
                    VisibleTiles = new Tile[BoardSize, BoardSize],
                    Tiles        = new Tile[BoardSize, BoardSize],
                    Key          = new object(),
                };
            }

            GameContext game = context.Value;

            Rect rect = EditorGUILayout.GetControlRect();

            entry.SmartValue = Mathf.Clamp(SirenixEditorFields.IntField(rect.AlignLeft(rect.width - 80 - 4), "Number of Bombs", entry.SmartValue), 1, (BoardSize * BoardSize) / 4);

            // Start game
            if (GUI.Button(rect.AlignRight(80), "Start"))
            {
                game.NumberOfBombs = entry.SmartValue;
                game.FlaggedBombs  = 0;

                for (int x = 0; x < BoardSize; x++)
                {
                    for (int y = 0; y < BoardSize; y++)
                    {
                        game.VisibleTiles[x, y] = Tile.None;
                        game.Tiles[x, y]        = Tile.None;
                    }
                }

                // Spawn bombs.
                for (int count = 0; count < game.NumberOfBombs;)
                {
                    int x = UnityEngine.Random.Range(0, BoardSize);
                    int y = UnityEngine.Random.Range(0, BoardSize);

                    if (game.Tiles[x, y] != Tile.Bomb)
                    {
                        game.Tiles[x, y] = Tile.Bomb;

                        if (x + 1 < BoardSize && game.Tiles[x + 1, y] != Tile.Bomb)
                        {
                            game.Tiles[x + 1, y] = (Tile)((int)game.Tiles[x + 1, y] + 1);
                        }
                        if (x + 1 < BoardSize && y + 1 < BoardSize && game.Tiles[x + 1, y + 1] != Tile.Bomb)
                        {
                            game.Tiles[x + 1, y + 1] = (Tile)((int)game.Tiles[x + 1, y + 1] + 1);
                        }
                        if (y + 1 < BoardSize && game.Tiles[x, y + 1] != Tile.Bomb)
                        {
                            game.Tiles[x, y + 1] = (Tile)((int)game.Tiles[x, y + 1] + 1);
                        }
                        if (x - 1 >= 0 && y + 1 < BoardSize && game.Tiles[x - 1, y + 1] != Tile.Bomb)
                        {
                            game.Tiles[x - 1, y + 1] = (Tile)((int)game.Tiles[x - 1, y + 1] + 1);
                        }

                        if (x - 1 >= 0 && game.Tiles[x - 1, y] != Tile.Bomb)
                        {
                            game.Tiles[x - 1, y] = (Tile)((int)game.Tiles[x - 1, y] + 1);
                        }
                        if (x - 1 >= 0 && y - 1 >= 0 && game.Tiles[x - 1, y - 1] != Tile.Bomb)
                        {
                            game.Tiles[x - 1, y - 1] = (Tile)((int)game.Tiles[x - 1, y - 1] + 1);
                        }
                        if (y - 1 >= 0 && game.Tiles[x, y - 1] != Tile.Bomb)
                        {
                            game.Tiles[x, y - 1] = (Tile)((int)game.Tiles[x, y - 1] + 1);
                        }
                        if (x + 1 < BoardSize && y - 1 >= 0 && game.Tiles[x + 1, y - 1] != Tile.Bomb)
                        {
                            game.Tiles[x + 1, y - 1] = (Tile)((int)game.Tiles[x + 1, y - 1] + 1);
                        }

                        count++;
                    }
                }
                game.IsRunning = true;
                game.GameOver  = false;
                game.PrevTime  = EditorApplication.timeSinceStartup;
                game.Time      = 0;
            }

            // Game

            SirenixEditorGUI.BeginShakeableGroup(game.Key);
            if (game.IsRunning)
            {
                this.Game(game);
            }
            SirenixEditorGUI.EndShakeableGroup(game.Key);
        }