Disposable helper class for managing BeginVertical / EndVertical.

Inheritance: GUI.Scope
        private void DisplaySceneForkflowButtons(float width)
        {
            using (VerticalScope vertical = new VerticalScope())
            {
                GUILayout.Label("Scenes Context", ExtGUIStyles.MiniTextCentered, GUILayout.Height(HEIGHT_TEXT));
                using (HorizontalScope horizontal = new HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();
                    _refGameAsset = EditorGUILayout.ObjectField(_refGameAsset, typeof(ContextListerAsset), false, GUILayout.Width(50), GUILayout.Height(HEIGHT_BUTTON)) as ContextListerAsset;
                    if (EditorGUI.EndChangeCheck())
                    {
                        ExtSaveAssetGUID.ResetKey(KEY_USED_FOR_CONTEXT_ASSET);
                        ExtSaveAssetGUID.SaveAssetReference(_refGameAsset, KEY_USED_FOR_CONTEXT_ASSET, "");
                    }
#if UNITY_2018_3_OR_NEWER
                    if (IsRightClickContext())
                    {
                        CreateGenericMenu();
                    }
#endif
                    if (_refGameAsset != null)
                    {
                        DisplayContextButtonsName();
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// display content of peek window
        /// </summary>
        public void DrawPeekWindow()
        {
            if (_pinnedGameObjectDrawer == null)
            {
                InitDrawer();
            }

            float widthEditorWindow     = position.width;
            float widthWithoutScrollBar = widthEditorWindow - SIZE_SCROLL_BAR;

            using (VerticalScope verticalScope = new VerticalScope())
            {
                _scrollPosition = GUILayout.BeginScrollView(
                    _scrollPosition,
                    false,
                    false,
                    GUIStyle.none,
                    GUI.skin.verticalScrollbar,
                    GUILayout.Width(widthEditorWindow));

                _pinnedGameObjectDrawer.Display();
                GUILayout.Label("");

                _pinnedObjectDrawer.Display();
                GUILayout.Label("");

                _selectedObjectDrawer.Display();

                GUILayout.Label("", GUILayout.Width(widthWithoutScrollBar));
                GUI.EndScrollView();
            }
        }
Exemple #3
0
    public override Dictionary <Guid, float> Inspect(string label,
                                                     Dictionary <Guid, float> value,
                                                     object parent,
                                                     DatabaseInspector inspectorWindow,
                                                     InspectableDatabaseLinkAttribute attribute)
    {
        Space();
        LabelField(label, EditorStyles.boldLabel);

        using (var v = new VerticalScope(GUI.skin.box))
        {
            if (value.Count == 0)
            {
                using (new HorizontalScope(DatabaseInspector.ListItemStyle))
                {
                    GUILayout.Label("Drag from list to add item");
                }
            }
            foreach (var ingredient in value.ToArray())
            {
                using (new HorizontalScope(DatabaseInspector.ListItemStyle))
                {
                    var entry = DatabaseInspector.CultCache.Get(ingredient.Key);
                    if (entry == null)
                    {
                        value.Remove(ingredient.Key);
                        GUI.changed = true;
                        return(value);
                    }

                    if (entry is INamedEntry named)
                    {
                        GUILayout.Label(named.EntryName);
                    }
                    else
                    {
                        GUILayout.Label(entry.ID.ToString());
                    }
                    value[ingredient.Key] = DelayedFloatField(value[ingredient.Key], GUILayout.Width(50));

                    // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
                    // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
                    if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3)))
                    {
                        value.Remove(ingredient.Key);
                    }
                }
            }

            if (v.rect.Contains(Event.current.mousePosition))
            {
                var dragData    = DragAndDrop.GetGenericData("Item");
                var isId        = dragData is Guid guid;
                var dragEntry   = isId ? DatabaseInspector.CultCache.Get(guid) : null;
                var correctType = attribute.EntryType.IsInstanceOfType(dragEntry);
                if (Event.current.type == EventType.DragUpdated)
                {
                    DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    if (isId && correctType)
                    {
                        DragAndDrop.AcceptDrag();
                        value[guid] = 1;
                        GUI.changed = true;
                    }
                }
            }
        }

        return(value);
    }
Exemple #4
0
    public override List <Guid> Inspect(string label,
                                        List <Guid> value,
                                        object parent,
                                        DatabaseInspector inspectorWindow,
                                        InspectableDatabaseLinkAttribute link)
    {
        using (var v = new VerticalScope(GUI.skin.box))
        {
            GUILayout.Label(label, EditorStyles.boldLabel);
            if (value.Count == 0)
            {
                using (new HorizontalScope(ListItemStyle))
                {
                    GUILayout.Label($"Drag from list to add {link.EntryType.Name}");
                }
            }
            foreach (var guid in value.ToArray())
            {
                using (new HorizontalScope(ListItemStyle))
                {
                    var entry = DatabaseInspector.CultCache.Get(guid);
                    if (entry == null)
                    {
                        value.Remove(guid);
                        GUI.changed = true;
                    }
                    else
                    {
                        GUILayout.Label((entry as INamedEntry)?.EntryName ?? entry.ID.ToString());

                        // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
                        // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
                        if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3)))
                        {
                            value.Remove(guid);
                        }
                    }
                }
            }

            if (v.rect.Contains(Event.current.mousePosition))
            {
                var guid    = DragAndDrop.GetGenericData("Item");
                var dragObj = DragAndDrop.GetGenericData("Item") is Guid?DatabaseInspector.CultCache.Get((Guid)guid) : null;

                var dragValid = dragObj != null && link.EntryType.IsInstanceOfType(dragObj) && !value.Contains(dragObj.ID);
                if (Event.current.type == EventType.DragUpdated)
                {
                    DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    if (dragValid)
                    {
                        DragAndDrop.AcceptDrag();
                        value.Add((Guid)guid);
                        GUI.changed = true;
                    }
                }
            }
        }

        return(value);
    }
        public static bool OnGUI(RockGenerator generator)
        {
            var groupStyle  = GUI.skin.box;
            var newSettings = new RockGenerationSettings(generator.Settings);

            using (var vs = new VerticalScope(groupStyle))
            {
                newSettings.StockDensity = SettingSlider(nameof(newSettings.StockDensity),
                                                         newSettings.StockDensity, 2, 16, "N1");
                newSettings.TargetTriangleCount = Mathf.RoundToInt(
                    SettingSlider(nameof(newSettings.TargetTriangleCount),
                                  newSettings.TargetTriangleCount, 50, 2000,
                                  "N0",
                                  logScale: true
                                  )
                    );
            }

            using (var vs = new VerticalScope(groupStyle))
            {
                using (var gcs = new GUIChangedScope())
                {
                    var Uniformity = Mathf.Clamp01(1 - newSettings.GridSettings.Randomness);
                    Uniformity = SettingSlider(nameof(Uniformity), Uniformity, 0, 1);

                    if (GUI.changed)
                    {
                        newSettings.GridSettings = new VoronoiGridSettings(newSettings.GridSettings)
                        {
                            Randomness = 1 - Uniformity
                        };
                    }
                }

                newSettings.Distortion = SettingSlider(nameof(newSettings.Distortion),
                                                       newSettings.Distortion, -1, 1);
                newSettings.PatternSize = SettingSlider(nameof(newSettings.PatternSize),
                                                        newSettings.PatternSize, .5f, 2.5f);
            }

            using (var vs = new VerticalScope(groupStyle))
                using (var gcs = new GUIChangedScope())
                {
                    var scale = newSettings.Scale;
                    Label("Shape:");
                    var newX = SettingSlider("X", Mathf.Clamp((float)scale.X, .5f, 2), 0.5f, 2);
                    var newY = SettingSlider("Y", Mathf.Clamp((float)scale.Y, .5f, 2), 0.5f, 2);
                    var newZ = (float)scale.Z;

                    if (GUI.changed)
                    {
                        var m = UnityEngine.Matrix4x4.TRS(DEFAULT_POS,
                                                          rotation,
                                                          new Vector3(newX, newY, newZ));
                        newSettings.Transform = Convert.FromUnityMatrix(m);
                    }
                }

            if (Button("Make Rock"))
            {
                var newGridSettings = new VoronoiGridSettings(newSettings.GridSettings);
                newGridSettings.Randomness += 1e-6f;

                newSettings.Transform = Convert.FromUnityMatrix(
                    UnityEngine.Matrix4x4.TRS(DEFAULT_POS + Random.insideUnitSphere,
                                              rotation = Random.rotation,
                                              Convert.ToVector3(newSettings.Scale))
                    );

                newSettings.GridSettings = newGridSettings;
            }

            var settingsChanged = GUI.changed;

            if (settingsChanged)
            {
                generator.Settings = newSettings;
            }

            if (Button("Save this one"))
            {
                var path = FileSaver.SaveMesh(generator.LatestMesh, "rock");
                OnFileExported(path);
            }

            return(settingsChanged);
        }
        /// <summary>
        /// display the content of the peek toolBar
        /// </summary>
        public bool DisplayPeekToolBar()
        {
            if (PeekSaveDatas.Instance == null)
            {
                return(false);
            }

            if (PeekSerializeObject.CurrentIndex >= PeekSerializeObject.SelectedObjectsCount)
            {
                PeekSerializeObject.SetCurrentIndex(PeekSerializeObject.SelectedObjectsCount - 1);
                PeekSerializeObject.Save(30);
            }

            using (VerticalScope vertical = new VerticalScope())
            {
                GUILayout.Label("Browse selections", ExtGUIStyles.MiniTextCentered, GUILayout.Height(_heightText));
                using (HorizontalScope horizontal = new HorizontalScope())
                {
                    if (GUILayout.Button(EditorGUIUtility.IconContent(OPEN_EDITOR_WINDOW_ICON), ExtGUIStyles.MicroButton, GUILayout.Width(28), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0)
                    {
                        PeekLogic.ManageOpenPeekEditorWindow();
                    }
#if UNITY_2018_3_OR_NEWER
                    if (IsRightClickContext())
                    {
                        return(true);
                    }
#endif


                    EditorGUI.BeginDisabledGroup(PeekSerializeObject.SelectedObjectsCount == 0);
                    {
                        float         delta           = 0;
                        bool          isScrollingDown = ExtMouse.IsScrollingDown(Event.current, ref delta);
                        StringBuilder previousTip     = new StringBuilder();
                        previousTip.Append("Go to previous selection (");
                        previousTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY));
                        previousTip.Append("+");
                        previousTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_PREVIOUS_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_PREVIOUS_KEY));
                        previousTip.Append(")");

                        if ((GUILayout.Button(new GUIContent(PREVIOUS_ICON, previousTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingDown)
                        {
                            if (Selection.objects.Length != 0)
                            {
                                PeekLogic.AddToIndex(-1);
                            }
                            PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
                        }
#if UNITY_2018_3_OR_NEWER
                        if (IsRightClickContext())
                        {
                            return(true);
                        }
#endif
                        bool          isScrollingUp = ExtMouse.IsScrollingUp(Event.current, ref delta);
                        StringBuilder nextTip       = new StringBuilder();
                        nextTip.Append("Go to next selection (");
                        nextTip.Append(ExtShortCutEditor.GetModifierKey(UnityEssentialsPreferences.SHORTCUT_MODIFIER_KEY_FOR_PREVIOUS_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_MODIFIER_KEY));
                        nextTip.Append("+");
                        nextTip.Append(ExtShortCutEditor.GetKey(UnityEssentialsPreferences.SHORTCUT_KEY_FOR_NEXT_SELECTION, (int)UnityEssentialsPreferences.DEFAULT_NEXT_KEY));
                        nextTip.Append(")");

                        if ((GUILayout.Button(new GUIContent(NEXT_ICON, nextTip.ToString()), ExtGUIStyles.MicroButton, GUILayout.Width(23), GUILayout.Height(EditorGUIUtility.singleLineHeight)) && Event.current.button == 0) || isScrollingUp)
                        {
                            PeekLogic.AddToIndex(1);
                            PeekLogic.ForceSelection(PeekSerializeObject.SelectedObjectsIndex(PeekSerializeObject.CurrentIndex));
                        }
#if UNITY_2018_3_OR_NEWER
                        if (IsRightClickContext())
                        {
                            return(true);
                        }
#endif

                        if (PeekSerializeObject.SelectedObjectsCount == 0)
                        {
                            GUIContent gUIContent = new GUIContent("-/-", "there is no previously selected objects");
                            GUILayout.Label(gUIContent);
                        }
                        else
                        {
                            string     showCount  = (PeekSerializeObject.CurrentIndex + 1).ToString() + "/" + (PeekSerializeObject.SelectedObjectsCount);
                            GUIContent gUIContent = new GUIContent(showCount, "Scroll Up/Down to browse previous/next");
                            GUILayout.Label(gUIContent);
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
            GUILayout.FlexibleSpace();
            return(false);
        }
    public override Shape Inspect(string label, Shape value, object parent, DatabaseInspector inspectorWindow, InspectableSchematicShapeAttribute attribute)
    {
        var item = parent as EquippableItemData;

        if (value == null)
        {
            value          = new Shape(1, 1);
            value[int2(0)] = true;
        }
        using (new VerticalScope())
        {
            Texture2D schematic = null;
            if (item != null && !string.IsNullOrEmpty(item.Schematic))
            {
                schematic = AssetDatabase.LoadAssetAtPath <Texture2D>(item.Schematic);
            }
            using (new HorizontalScope())
            {
                GUILayout.Label(label, GUILayout.Width(width));
                GUILayout.Label("Size", GUILayout.ExpandWidth(false));
                if (schematic == null)
                {
                    GUILayout.Label("X", GUILayout.Width(labelWidth));
                    value.Width = DelayedIntField(value.Width);
                    GUILayout.Label("Y", GUILayout.Width(labelWidth));
                    value.Height = DelayedIntField(value.Height);
                }
                else
                {
                    GUILayout.Label("X", GUILayout.Width(labelWidth));
                    value.Width  = DelayedIntField(value.Width);
                    value.Height = Mathf.RoundToInt(value.Width * ((float)schematic.height / schematic.width));
                    GUILayout.Label("Y", GUILayout.Width(labelWidth));
                    LabelField($"{value.Height}");
                }
            }

            using (new HorizontalScope())
            {
                GUILayout.Label("", GUILayout.Width(width));
                using (var a = new VerticalScope())
                {
                    if (schematic != null)
                    {
                        EditorGUI.DrawPreviewTexture(a.rect, schematic, _schematicMat);
                    }
                    for (var y = value.Height - 1; y >= 0; y--)
                    {
                        using (new HorizontalScope())
                        {
                            for (var x = 0; x < value.Width; x++)
                            {
                                var oldColor = GUI.backgroundColor;
                                if (item is HullData hull)
                                {
                                    var hardpoint = hull.Hardpoints
                                                    .FirstOrDefault(hp =>
                                                                    hp.Shape.Coordinates
                                                                    .Select(v => v + hp.Position)
                                                                    .Any(v => v.x == x && v.y == y));
                                    if (hardpoint != null)
                                    {
                                        GUI.backgroundColor = hardpoint.TintColor.ToColor();
                                    }
                                }
                                value[int2(x, y)]   = Toggle(value[int2(x, y)], GUILayout.Width(toggleWidth));
                                GUI.backgroundColor = oldColor;
                            }
                        }
                    }
                }
                GUILayout.FlexibleSpace();
            }
        }

        return(value);
    }