Пример #1
0
        protected override void OnDrawMenuItem(Rect rect, Rect labelRect)
        {
            if (Event.current.type == EventType.Repaint)
            {
                {
                    labelRect.width -= 10;
                    float widthOfMemberName = SirenixGUIStyles.Label.CalcSize(GUIHelper.TempContent(this.Name)).x;
                    float widthOfTypeName   = SirenixGUIStyles.RightAlignedGreyMiniLabel.CalcSize(GUIHelper.TempContent(this.typeName)).x;

                    GUI.Label(
                        labelRect
                        .SetX(Mathf.Max(labelRect.xMin + widthOfMemberName, labelRect.xMax - widthOfTypeName))
                        .SetXMax(labelRect.xMax),
                        this.typeName,
                        this.IsSelected ? SirenixGUIStyles.LeftAlignedWhiteMiniLabel : SirenixGUIStyles.LeftAlignedGreyMiniLabel);
                }

                rect.x += IconSpacing;
                rect.x += IconSpacing;
                rect    = rect.AlignLeft(IconSize);
                rect    = rect.AlignMiddle(IconSize);
                DrawTheIcon(rect, this.info.Info.HasAll(SerializationFlags.SerializedByOdin), this.info.OdinMessageType);
                rect.x += IconSpacing * 2 + IconSize;
                DrawTheIcon(rect, this.info.Info.HasAll(SerializationFlags.SerializedByUnity), this.info.UnityMessageType);
            }
        }
Пример #2
0
    public void drawEntity(NodeMEntity entity)
    {
        string name = "Entity";

        if (entity.entityName != "")
        {
            name = entity.entityName;
        }

        if (entity.orientation == PortOrientation.In)
        {
            //SirenixEditorGUI.
            SirenixEditorGUI.BeginIndentedHorizontal();
            SirenixEditorGUI.BeginBox();
            Rect rect = EditorGUILayout.GetControlRect();
            //  rect = EditorGUI.PrefixLabel(rect, new GUIContent("   "));


            rect = EditorGUI.PrefixLabel(rect, new GUIContent(name));

            if (GUI.Button(rect.AlignRight(15), EditorIcons.ArrowDown.Raw))
            {
                entity.style.unfolded = !entity.style.unfolded;
            }
            ;
            SirenixEditorGUI.EndBox();
            SirenixEditorGUI.EndIndentedHorizontal();
            // NodeEditorGUILayout.AddPortField(entity.port);
        }
        else
        {
            SirenixEditorGUI.BeginBox();
            Rect rect = EditorGUILayout.GetControlRect();
            EditorGUI.LabelField(rect.AlignRight(80), name);
            if (GUI.Button(rect.AlignLeft(15), EditorIcons.ArrowDown.Raw))
            {
                entity.style.unfolded = !entity.style.unfolded;
            }
            ;

            SirenixEditorGUI.EndBox();
            //  NodeEditorGUILayout.AddPortField(entity.port);
        }
        //  entity.style.unfolded = SirenixEditorGUI.Foldout(entity.style.unfolded, "");


        if (entity.style.unfolded)
        {
            SirenixEditorGUI.BeginBox();
            for (int i = 0; i < entity.components.Count; i++)
            {
                drawComponent(entity.components[i]);
            }
            SirenixEditorGUI.EndBox();
        }
        else
        {
            NodeEditorGUILayout.AddPortField(entity.port);
        }
    }
Пример #3
0
        private void DrawFirstToolbar()
        {
            //选项
            GUILayout.Space(1);
            Rect rect = GUILayoutUtility.GetRect(0f, ToolbarHeight, SirenixGUIStyles.ToolbarBackground);

            rect = rect.SetHeight(ToolbarHeight);
            var  opptionWidth = SirenixGUIStyles.LeftAlignedCenteredLabel.CalcSize(this.m_optionGui).x * 2f;
            Rect leftRect     = rect.AlignLeft(opptionWidth);

            OdinSelector <int> .DrawSelectorDropdown(leftRect, this.m_optionGui, this.SelectType, btnStyle);

            //搜索
            Rect filterRect = rect.AlignRight(opptionWidth * 2);
            Rect searchRect = rect.SetXMax(filterRect.xMin).SetXMin(opptionWidth);

            searchRect            = searchRect.HorizontalPadding(5f).AlignMiddle(16);
            this.m_sSearchKeyName = SirenixEditorGUI.SearchField(searchRect, this.m_sSearchKeyName);
            //数据类型过滤
            EditorGUI.BeginChangeCheck();
            this.m_eDataFilterType = EnumSelector <EPlayerPrefsType> .DrawEnumField(filterRect, null, new GUIContent("Type Filter"), this.m_eDataFilterType, CaomaoPlayerPrefsWindow.btnStyle);

            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt("CaomaoPlayerPrefsWindow.m_eDataFilterType", (int)this.m_eDataFilterType);
            }
        }
    protected override void DrawPropertyLayout(GUIContent label)
    {
        Rect   rect      = EditorGUILayout.GetControlRect();
        Color  tempColor = this.ValueEntry.SmartValue;
        string hexCode   = ColorUtility.ToHtmlStringRGB(tempColor);

        if (label != null)
        {
            rect = EditorGUI.PrefixLabel(rect, label);
        }

        rect      = EditorGUILayout.GetControlRect();
        tempColor = SirenixEditorFields.ColorField(rect.AlignLeft(rect.width * 0.75f), tempColor);

        //hexcode
        hexCode = SirenixEditorFields.TextField(rect.AlignRight(rect.width * 0.25f), "#" + hexCode);
        if (ColorUtility.TryParseHtmlString(hexCode, out tempColor))
        {
            this.ValueEntry.SmartValue = tempColor;
        }

        //rgb values
        rect = EditorGUILayout.GetControlRect();

        GUIHelper.PushLabelWidth(15);
        tempColor.r = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.3f), "R", tempColor.r, 0f, 1f);
        tempColor.g = EditorGUI.Slider(rect.AlignCenter(rect.width * 0.3f), "G", tempColor.g, 0f, 1f);
        tempColor.b = EditorGUI.Slider(rect.AlignRight(rect.width * 0.3f), "B", tempColor.b, 0f, 1f);
        GUIHelper.PopLabelWidth();

        //hsv values
        Color.RGBToHSV(tempColor, out float h, out float s, out float v);
        rect = EditorGUILayout.GetControlRect();

        GUIHelper.PushLabelWidth(15);
        h = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.3f), "H", h, 0f, 1f);
        s = EditorGUI.Slider(rect.AlignCenter(rect.width * 0.3f), "S", s, 0f, 1f);
        v = EditorGUI.Slider(rect.AlignRight(rect.width * 0.3f), "V", v, 0f, 1f);
        GUIHelper.PopLabelWidth();

        tempColor = Color.HSVToRGB(h, s, v);

        this.ValueEntry.SmartValue = tempColor;
    }
Пример #5
0
        public void Draw()
        {
            SirenixEditorGUI.BeginBox();
            SirenixEditorGUI.BeginBoxHeader();
            {
                Rect rect = GUILayoutUtility.GetRect(100, 500, 20, 20).AddY(2);
                if (this.Icon != null)
                {
                    EditorIcons.X.Draw(rect.AlignLeft(16).SetHeight(16).AddX(2), this.Icon);
                    rect.xMin += 20;
                }

                GUI.Label(rect, this.Name);

                if (string.IsNullOrEmpty(this.registration.DocumentationUrl) == false)
                {
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("Documentation", SirenixGUIStyles.MiniButton))
                    {
                        Help.BrowseURL(this.registration.DocumentationUrl);
                    }
                }
            }
            SirenixEditorGUI.EndBoxHeader();

            if (string.IsNullOrEmpty(this.registration.Description) == false)
            {
                GUILayout.Label(this.registration.Description);
            }

            SirenixEditorGUI.EndBox();
            GUILayout.Space(15);

            if (this.examples.Length > 0)
            {
                this.tabGroup.BeginGroup();
                foreach (var example in this.examples)
                {
                    var tab = this.tabGroup.RegisterTab(example.ExampleInfo.Name);
                    if (tab.BeginPage())
                    {
                        example.Draw(this.DrawCodeExample);
                    }
                    tab.EndPage();
                }
                this.tabGroup.EndGroup();
            }
            else
            {
                GUILayout.Label("No examples available.");
            }
        }
Пример #6
0
        private void DrawTopBar()
        {
            Rect rect = SirenixEditorGUI.BeginHorizontalToolbar();

            {
                var iconRect = rect.AlignLeft(SerializationInfoMenuItem.IconSize).AlignMiddle(SerializationInfoMenuItem.IconSize);
                iconRect.x += SerializationInfoMenuItem.IconSpacing * 2;
                GUI.color   = (this.backendFlags & SerializationBackendFlags.Odin) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f);
                GUI.DrawTexture(iconRect.Padding(2), EditorIcons.OdinInspectorLogo, ScaleMode.ScaleToFit);
                iconRect.x += SerializationInfoMenuItem.IconSize + SerializationInfoMenuItem.IconSpacing * 2;
                GUI.color   = (this.backendFlags & SerializationBackendFlags.Unity) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f);
                GUI.DrawTexture(iconRect.Padding(2), EditorIcons.UnityLogo, ScaleMode.ScaleToFit);
                GUI.color = Color.white;

                var typeName = "   " + (this.targetType == null ? "Select Type" : this.targetType.GetNiceName().SplitPascalCase()) + "   ";
                GUILayout.Space(iconRect.xMax + 3);
                bool selectB = SirenixEditorGUI.ToolbarButton(new GUIContent(typeName));
                GUILayout.FlexibleSpace();
                bool selectA = SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown);

                if (selectA || selectB)
                {
                    var btnRect = GUIHelper.GetCurrentLayoutRect().HorizontalPadding(20).AlignTop(20);
                    btnRect = btnRect.AlignRight(400);
                    var source = AssemblyUtilities.GetTypes(AssemblyTypeFlags.CustomTypes)
                                 .Where(x => !x.IsAbstract && x.IsClass && x.InheritsFrom <UnityEngine.Object>())
                                 .Where(x => !x.Assembly.FullName.StartsWith("Sirenix"))
                                 .OrderBy(x => x.Assembly.GetAssemblyTypeFlag())
                                 .OrderBy(x => x.Assembly.GetAssemblyTypeFlag())
                                 .ThenBy(x => x.Namespace)
                                 .ThenByDescending(x => x.Name);

                    var p = new TypeSelector(source, false);

                    p.SelectionChanged += (types) =>
                    {
                        var t = types.FirstOrDefault();
                        if (t != null)
                        {
                            this.targetType  = t;
                            this.odinContext = this.targetType.IsDefined <ShowOdinSerializedPropertiesInInspectorAttribute>(true);
                            this.CreateMenuTree(true);
                        }
                    };

                    p.SetSelection(this.targetType);
                    p.ShowInPopup(300);
                }
            }
            SirenixEditorGUI.EndHorizontalToolbar();
        }
Пример #7
0
        [Test] public void Alignment()
        {
            Assert.AreEqual(new Rect(-5, -5, 10, 10), Rect.AlignCenter(0, 0, 10, 10));

            Assert.AreEqual(new Rect(0, -5, 10, 10), Rect.AlignLeft(0, 0, 10, 10));
            Assert.AreEqual(new Rect(-10, -5, 10, 10), Rect.AlignRight(0, 0, 10, 10));
            Assert.AreEqual(new Rect(-5, 0, 10, 10), Rect.AlignTop(0, 0, 10, 10));
            Assert.AreEqual(new Rect(-5, -10, 10, 10), Rect.AlignBottom(0, 0, 10, 10));

            Assert.AreEqual(new Rect(0, 0, 10, 10), Rect.AlignTopLeft(0, 0, 10, 10));
            Assert.AreEqual(new Rect(-10, 0, 10, 10), Rect.AlignTopRight(0, 0, 10, 10));
            Assert.AreEqual(new Rect(0, -10, 10, 10), Rect.AlignBottomLeft(0, 0, 10, 10));
            Assert.AreEqual(new Rect(-10, -10, 10, 10), Rect.AlignBottomRight(0, 0, 10, 10));
        }
Пример #8
0
    public void drawFilter(NodeFilter filter)
    {
        if (filter != null)
        {
            if (filter.orientation == PortOrientation.In)
            {
                SirenixEditorGUI.BeginBox();
                Rect rect = EditorGUILayout.GetControlRect();
                rect = EditorGUI.PrefixLabel(rect, new GUIContent("In filter"));
                if (GUI.Button(rect.AlignRight(15), EditorIcons.ArrowDown.Raw))
                {
                    filter.style.unfolded = !filter.style.unfolded;
                }
                ;
                SirenixEditorGUI.EndBox();
                // NodeEditorGUILayout.AddPortField(filter.port);
            }
            else
            {
                SirenixEditorGUI.BeginBox();
                Rect rect = EditorGUILayout.GetControlRect();
                EditorGUI.LabelField(rect.AlignRight(60), "Out filter");
                if (GUI.Button(rect.AlignLeft(15), EditorIcons.ArrowDown.Raw))
                {
                    filter.style.unfolded = !filter.style.unfolded;
                }
                ;
                SirenixEditorGUI.EndBox();
            }

            // NodeEditorGUILayout.


            if (filter.style.unfolded)
            {
                SirenixEditorGUI.BeginBox();
                for (int i = 0; i < filter.filter.Count; i++)
                {
                    drawEntity(filter.filter[i]);
                }
                SirenixEditorGUI.EndBox();
            }
            else
            {
                NodeEditorGUILayout.AddPortField(filter.port);
            }
        }
    }
        protected override void DrawPropertyLayout(GUIContent label)
        {
            Rect rect = EditorGUILayout.GetControlRect();

            if (label != null)
            {
                rect = EditorGUI.PrefixLabel(rect, label);
            }
            MyStruct value = this.ValueEntry.SmartValue;

            GUIHelper.PushLabelWidth(20);
            value.X = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.5f), "X", value.X, 0, 100);
            value.Y = EditorGUI.Slider(rect.AlignRight(rect.width * 0.5f), "Y", value.Y, 0, 100);
            GUIHelper.PopLabelWidth();
            this.ValueEntry.SmartValue = value;
        }
        private void AddBar()
        {
            _bar = new GameObject("bar", this.GameObj);

            Transform t = _bar.AddComponent <Transform>();

            t.RelativePos   = new Vector3(Rect.W / 2, Rect.H / 2, 0);
            t.RelativeAngle = 0;

            SkinnedPanel sp = new SkinnedPanel();

            sp.VisibilityGroup = this.VisibilityGroup;
            sp.Skin            = BarSkin;
            sp.Rect            = Rect.AlignLeft(-Rect.W / 2 + Skin.Res.Border.X, 0, 0, Rect.H - Skin.Res.Border.Y - Skin.Res.Border.W);

            _bar.AddComponent <SkinnedPanel>(sp);
            Scene.Current.AddObject(_bar);
        }
        /// <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);
        }
Пример #12
0
    protected override void DrawPropertyLayout(GUIContent label)
    {
        Rect rect = EditorGUILayout.GetControlRect();

        if (label != null)
        {
            rect = EditorGUI.PrefixLabel(rect, label);
        }

        Vector2 value = this.ValueEntry.SmartValue;

        GUIHelper.PushLabelWidth(20);
        value.x = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.5f), "X", value.x,
                                   this.Attribute.minValue, this.Attribute.maxValue);
        value.y = EditorGUI.Slider(rect.AlignRight(rect.width * 0.5f), "Y", value.y,
                                   this.Attribute.minValue, this.Attribute.maxValue);
        GUIHelper.PopLabelWidth();

        this.ValueEntry.SmartValue = value;
    }
Пример #13
0
        public void DrawPageNavigation(Rect rect)
        {
            var leftBtnRect = rect.AlignLeft(rect.height * 1.3f);

            GUIHelper.PushGUIEnabled(!this.IsOnFirstPage);
            if (GUI.Button(leftBtnRect, GUIContent.none, GUIStyle.none))
            {
                this.NavigateBack();
            }
            EditorIcons.TriangleLeft.Draw(leftBtnRect, 19);
            GUIHelper.PopGUIEnabled();

            rect.xMin += rect.height;

            var totalLength = 0;

            for (int i = this.pages.Count - 1; i >= 0; i--)
            {
                var p = this.pages[i];
                if (!p.TitleWidth.HasValue)
                {
                    p.TitleWidth = (int)SirenixGUIStyles.Label.CalcSize(new GUIContent(p.Name)).x + 7;
                }
                totalLength += p.TitleWidth.Value;
            }

            rect.width -= 8;

            var cut = rect.xMin;

            if (totalLength > rect.width)
            {
                rect.xMin -= totalLength - rect.width;
            }

            for (int i = 0; i < this.pages.Count; i++)
            {
                var p = this.pages[i];
                if (!p.TitleWidth.HasValue)
                {
                    p.TitleWidth = (int)SirenixGUIStyles.Label.CalcSize(new GUIContent(p.Name)).x + 7;
                }
                rect.width = p.TitleWidth.Value;

                var btnRect = rect;
                btnRect.width -= 6;
                btnRect.xMin   = Mathf.Max(cut, btnRect.xMin);
                //var hover = btnRect.Contains(Event.current.mousePosition);
                //var active = i == this.pages.Count - 1;

                if (GUI.Button(btnRect, p.Name, SirenixGUIStyles.LabelCentered))
                {
                    this.NavigateBack(i + 1);
                }
                if (i != this.pages.Count - 1)
                {
                    var lblRect = btnRect.AlignRight(10);
                    lblRect.x   += 8;
                    lblRect.xMin = Mathf.Max(cut, lblRect.xMin);
                    GUI.Label(lblRect, "/", SirenixGUIStyles.LabelCentered);
                }
                rect.x += rect.width;
            }
        }
        private void DrawColumn(Rect rect, IPropertyValueEntry <TArray> entry, Context context, int columnIndex)
        {
            if (columnIndex < context.ColCount)
            {
                GUI.Label(rect, columnIndex.ToString(), SirenixGUIStyles.LabelCentered);

                // Handle Column dragging.
                if (!context.Attribute.IsReadOnly)
                {
                    var id = GUIUtility.GetControlID(FocusType.Passive);
                    if (GUI.enabled && Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                    {
                        GUIHelper.RemoveFocusControl();
                        GUIUtility.hotControl = id;
                        EditorGUIUtility.SetWantsMouseJumping(1);
                        Event.current.Use();
                        context.ColumnDragFrom = columnIndex;
                        context.ColumnDragTo   = columnIndex;
                        context.dragStartPos   = Event.current.mousePosition;
                    }
                    else if (GUIUtility.hotControl == id)
                    {
                        if ((context.dragStartPos - Event.current.mousePosition).sqrMagnitude > 5 * 5)
                        {
                            context.IsDraggingColumn = true;
                        }
                        if (Event.current.type == EventType.MouseDrag)
                        {
                            Event.current.Use();
                        }
                        else if (Event.current.type == EventType.MouseUp)
                        {
                            GUIUtility.hotControl = 0;
                            EditorGUIUtility.SetWantsMouseJumping(0);
                            Event.current.Use();
                            context.IsDraggingColumn = false;

                            ApplyArrayModifications(entry, arr => MultiDimArrayUtilities.MoveColumn(arr, context.ColumnDragFrom, context.ColumnDragTo));
                        }
                    }

                    if (context.IsDraggingColumn && Event.current.type == EventType.Repaint)
                    {
                        float mouseX = Event.current.mousePosition.x;
                        if (mouseX > rect.x - 1 && mouseX < rect.x + rect.width + 1)
                        {
                            Rect arrowRect;
                            if (mouseX > rect.x + rect.width * 0.5f)
                            {
                                arrowRect            = rect.AlignRight(16);
                                arrowRect.height     = 16;
                                arrowRect.y         -= 13;
                                arrowRect.x         += 8;
                                context.ColumnDragTo = columnIndex;
                            }
                            else
                            {
                                arrowRect            = rect.AlignLeft(16);
                                arrowRect.height     = 16;
                                arrowRect.y         -= 13;
                                arrowRect.x         -= 8;
                                context.ColumnDragTo = columnIndex - 1;
                            }

                            entry.Property.Tree.DelayActionUntilRepaint(() =>
                            {
                                //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                                GUI.DrawTexture(arrowRect, EditorIcons.ArrowDown.Active);
                                //GL.sRGBWrite = false;

                                var lineRect   = arrowRect;
                                lineRect.x     = lineRect.center.x - 2 + 1;
                                lineRect.width = 3;
                                lineRect.y    += 14;
                                lineRect.yMax  = context.Table.TableRect.yMax;
                                EditorGUI.DrawRect(lineRect, new Color(0, 0, 0, 0.6f));
                            });
                        }

                        if (columnIndex == context.ColCount - 1)
                        {
                            entry.Property.Tree.DelayActionUntilRepaint(() =>
                            {
                                var cell     = context.Table[context.Table.ColumnCount - context.ColCount + context.ColumnDragFrom, context.Table.RowCount - 1];
                                var rowRect  = cell.Rect;
                                rowRect.yMin = rect.yMin;
                                SirenixEditorGUI.DrawSolidRect(rowRect, new Color(0, 0, 0, 0.2f));
                            });
                        }
                    }
                }
            }
            else
            {
                GUI.Label(rect, "-", EditorStyles.centeredGreyMiniLabel);
            }

            if (!context.Attribute.IsReadOnly && Event.current.type == EventType.MouseDown && Event.current.button == 1 && rect.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Insert 1 left"), false, () => ApplyArrayModifications(entry, arr => MultiDimArrayUtilities.InsertOneColumnLeft(arr, columnIndex)));
                menu.AddItem(new GUIContent("Insert 1 right"), false, () => ApplyArrayModifications(entry, arr => MultiDimArrayUtilities.InsertOneColumnRight(arr, columnIndex)));
                menu.AddItem(new GUIContent("Duplicate"), false, () => ApplyArrayModifications(entry, arr => MultiDimArrayUtilities.DuplicateColumn(arr, columnIndex)));
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Delete"), false, () => ApplyArrayModifications(entry, arr => MultiDimArrayUtilities.DeleteColumn(arr, columnIndex)));
                menu.ShowAsContext();
            }
        }
Пример #15
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);
        }
Пример #16
0
    protected override void OnGUI()
    {
        _repaintSheduled = false;
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Clear"))
        {
            _properties.Clear();
        }

        Rect settingsRect = GUILayoutUtility.GetRect(24, 24, GUILayout.ExpandWidth(false)).AlignLeft(20).AlignCenterY(20);

        if (SirenixEditorGUI.IconButton(settingsRect, _showSettings ? EditorIcons.SettingsCog.Inactive : EditorIcons.SettingsCog.Active, "Settings"))
        {
            _showSettings = !_showSettings;
        }
        GUILayout.EndHorizontal();

        if (_showSettings)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(40);
            GUI.changed = false;
            Rect rect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true));
            _labelWidth = GUI.HorizontalSlider(rect, _labelWidth, rect.xMin, rect.xMax);
            if (GUI.changed)
            {
                EditorPrefs.SetFloat("OWW_labelWidth", _labelWidth);
            }
            EditorGUILayout.LabelField("Label Width", GUILayout.Width(70));
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(5);
        bool first = true;

        if (_properties.Count == 0)
        {
            EditorGUILayout.LabelField("Right-click any property in an Inspector and select 'Watch' to make it show up here.", SirenixGUIStyles.MultiLineCenteredLabel);
        }

        GUIHelper.PushLabelWidth(_labelWidth - 30);

        for (int i = 0; i < _properties.Count; i++)
        {
            TreeValuesHolder holder = _properties[i];
            holder.CheckRefresh();
            if (!first)
            {
                GUILayout.Space(5);
            }
            first = false;

            Rect titleRect = SirenixEditorGUI.BeginBox("      " + holder.Tree.TargetType.Name);

            titleRect = titleRect.AlignTop(21);
            if (holder.ParentObject != null)
            {
                Rect alignRight = titleRect.AlignRight(200).AlignCenterY(16).AlignLeft(180);
                GUIHelper.PushGUIEnabled(false);
                SirenixEditorFields.UnityObjectField(alignRight, holder.ParentObject, typeof(GameObject), true);
                GUIHelper.PopGUIEnabled();
            }

            if (SirenixEditorGUI.IconButton(titleRect.AlignRight(20).AlignCenterY(18), EditorIcons.X))
            {
                _properties.RemoveAt(i--);
            }

            Rect titleDragDropRect = titleRect.AlignLeft(30).AlignCenter(20, 20);
            EditorIcons.List.Draw(titleDragDropRect);

            TreeValuesHolder treedragdrop = (TreeValuesHolder)DragAndDropUtilities.DragAndDropZone(titleDragDropRect, holder, typeof(TreeValuesHolder), false, false);
            if (treedragdrop != holder)
            {
                int treeDragDropIndex = _properties.IndexOf(treedragdrop);
                Swap(_properties, treeDragDropIndex, i);
            }

            if (holder.Tree.UnitySerializedObject?.targetObject == null)
            {
                EditorGUILayout.LabelField($"This component is no longer valid in the current context (loaded different scene?)", SirenixGUIStyles.MultiLineLabel);
            }
            else
            {
                InspectorUtilities.BeginDrawPropertyTree(holder.Tree, true);
                for (int index = 0; index < holder.ValuePaths.Count; index++)
                {
                    string path = holder.ValuePaths[index];
                    GUILayout.BeginHorizontal();

                    Rect rect1 = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight + 5, EditorGUIUtility.singleLineHeight + 3, GUILayout.ExpandWidth(false)).AlignRight(EditorGUIUtility.singleLineHeight + 2);

                    EditorIcons.List.Draw(rect1);

                    ValueDragDropHolder dragdrop = (ValueDragDropHolder)DragAndDropUtilities.DragAndDropZone(rect1, new ValueDragDropHolder(holder, index), typeof(ValueDragDropHolder), false, false);
                    if (dragdrop.TreeValuesHolder == holder && dragdrop.Index != index)
                    {
                        string ptemp = holder.ValuePaths[index];
                        holder.ValuePaths[index]          = holder.ValuePaths[dragdrop.Index];
                        holder.ValuePaths[dragdrop.Index] = ptemp;
                    }

                    InspectorProperty propertyAtPath = holder.Tree.GetPropertyAtPath(path);
                    if (propertyAtPath == null)
                    {
                        propertyAtPath = holder.Tree.GetPropertyAtUnityPath(path);
                    }
                    if (propertyAtPath != null)
                    {
                        propertyAtPath.Draw();
                    }
                    else
                    {
                        EditorGUILayout.LabelField($"Could not find property ({path})");
                    }

                    if (SirenixEditorGUI.IconButton(EditorIcons.X))
                    {
                        holder.ValuePaths.RemoveAt(index--);
                        if (holder.ValuePaths.Count == 0)
                        {
                            _properties.RemoveAt(i--);
                        }
                    }

                    GUILayout.Space(3);
                    GUILayout.EndHorizontal();
                }

                InspectorUtilities.EndDrawPropertyTree(holder.Tree);
            }

            SirenixEditorGUI.EndBox();
        }

        GUIHelper.PopLabelWidth();
    }