Example #1
0
        public static bool PrefabPreview(Prefab prefab, bool useBoxStyle, PrefabPreviewButtonRenderData previewButtonRenderData)
        {
            string previewStyleName = useBoxStyle ? "Box" : "";
            var    previewStyle     = new GUIStyle(previewStyleName);

            return(GUILayout.Button(previewButtonRenderData.ButtonContent, previewStyle, GUILayout.Width(previewButtonRenderData.ButtonWidth), GUILayout.Height(previewButtonRenderData.ButtonHeight)));
        }
Example #2
0
        private void RenderActivePrefabPreviewButtonAndNextPrevControls(Prefab activePrefab)
        {
            var buttonDrawData = new PrefabPreviewButtonRenderData();

            buttonDrawData.ExtractFromPrefab(activePrefab, 1.0f);

            EditorGUILayoutEx.BeginVertical(GUILayout.Width(buttonDrawData.ButtonWidth));
            GUILayout.Button(buttonDrawData.ButtonContent, "Box", GUILayout.Width(buttonDrawData.ButtonWidth), GUILayout.Height(buttonDrawData.ButtonHeight));
            RenderNextAndPreviousPrefabButtons(activePrefab, buttonDrawData.ButtonWidth * 0.5f);
            EditorGUILayoutEx.EndVertical();
        }
Example #3
0
        public static bool PrefabPreview(Prefab prefab, float previewScale, bool useBoxStyle)
        {
            var previewButtonRenderData = new PrefabPreviewButtonRenderData();

            previewButtonRenderData.ExtractFromPrefab(prefab, previewScale);

            string previewStyleName = useBoxStyle ? "Box" : "";
            var    previewStyle     = new GUIStyle(previewStyleName);

            return(GUILayout.Button(previewButtonRenderData.ButtonContent, previewStyle, GUILayout.Width(previewButtonRenderData.ButtonWidth), GUILayout.Height(previewButtonRenderData.ButtonHeight)));
        }
        private void RenderPrefabPreviewRows()
        {
            for (int prefabIndex = 0; prefabIndex < _filteredPrefabs.Count; ++prefabIndex)
            {
                // Start a new row?
                if (prefabIndex % ViewData.NumberOfPrefabsPerRow == 0)
                {
                    if (prefabIndex != 0)
                    {
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.BeginHorizontal();
                }

                // Render the prefab entry
                Prefab prefab = _filteredPrefabs[prefabIndex];
                var    previewButtonRenderData = new PrefabPreviewButtonRenderData();
                previewButtonRenderData.ExtractFromPrefab(prefab, ViewData.PrefabPreviewScale);

                EditorGUILayout.BeginVertical(GUILayout.Width(previewButtonRenderData.ButtonWidth));

                // Render the prefab preview button
                EditorGUIColor.Push(prefab == _prefabCategory.ActivePrefab ? ViewData.ActivePrefabTint : Color.white);
                if (EditorGUILayoutEx.PrefabPreview(prefab, true, previewButtonRenderData))
                {
                    ObjectPlacementSettings placementSettings = ObjectPlacementSettings.Get();
                    if (placementSettings.ObjectPlacementMode == ObjectPlacementMode.DecorPaint &&
                        placementSettings.DecorPaintObjectPlacementSettings.DecorPaintMode == DecorPaintMode.Brush &&
                        DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush != null && Event.current.button == (int)MouseButton.Right)
                    {
                        UndoEx.RecordForToolAction(DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush);
                        DecorPaintObjectPlacementBrushElement brushElement = DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush.CreateNewElement();
                        brushElement.Prefab = prefab;
                        Octave3DWorldBuilder.ActiveInstance.RepaintAllEditorWindows();
                        Octave3DWorldBuilder.ActiveInstance.Inspector.Repaint();
                    }
                    else
                    if (Octave3DWorldBuilder.ActiveInstance.Inspector.ActiveInspectorGUIIdentifier == InspectorGUIIdentifier.ObjectSelection &&
                        AllShortcutCombos.Instance.ReplacePrefabsForSelectedObjects.IsActive())
                    {
                        ObjectSelection.Get().ReplaceSelectedObjectsWithPrefab(prefab);
                    }
                    else
                    {
                        UndoEx.RecordForToolAction(_prefabCategory);
                        _prefabCategory.SetActivePrefab(prefab);
                    }
                }
                EditorGUIColor.Pop();

                // Render the prefab name labels if necessary
                if (ViewData.ShowPrefabNames)
                {
                    Rect previewRectangle = GUILayoutUtility.GetLastRect();
                    EditorGUILayoutEx.LabelInMiddleOfControlRect(previewRectangle, prefab.Name, previewButtonRenderData.ButtonHeight, GetStyleForPrefabNameLabel());
                }

                // Render the remove prefab button
                if (GUILayout.Button(GetRemovePrefabButtonContent()))
                {
                    UndoEx.RecordForToolAction(_prefabCategory);
                    _prefabCategory.RemoveAndDestroyPrefab(prefab);
                    Octave3DWorldBuilder.ActiveInstance.Inspector.Repaint();
                }

                EditorGUILayout.EndVertical();
            }

            // End the last row (if any)
            if (_filteredPrefabs.Count != 0)
            {
                EditorGUILayout.EndHorizontal();
            }
        }
Example #5
0
        protected override void RenderContent()
        {
            RenderNameChangeField();
            RenderRadiusField();
            RenderMaxNumberOfObjectsField();
            RenderDistanceBetweenObjectsField();
            RenderIgnoreObjectsOutsideOfPaintSurfaceToggle();
            RenderDestinationCategoryForElementPrefabsSelectionPopup();

            EditorGUILayout.Separator();
            if (!_brush.IsEmpty)
            {
                Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("Left click on an element's preview to change its parameters. Right click to remove the element from the brush. SHIFT + Right click to toggle the element on/off.");
            }
            Data.ElementsScrollPos = EditorGUILayout.BeginScrollView(Data.ElementsScrollPos, "Box", GUILayout.Height(Data.ElementsScrollViewHeight));
            if (_brush.IsEmpty)
            {
                EditorGUILayout.HelpBox("There are no brush elements available. You can drag and drop prefabs onto this area or " +
                                        "right click on prefabs inside the active category to create new elements. All brush elements will " +
                                        "be shown with a preview inside this area.", UnityEditor.MessageType.None);
            }
            else
            {
                List <DecorPaintObjectPlacementBrushElement> allBrushElements = _brush.GetAllBrushElements();
                for (int brushElemIndex = 0; brushElemIndex < allBrushElements.Count; ++brushElemIndex)
                {
                    if (brushElemIndex % Data.NumElementsPerRow == 0)
                    {
                        if (brushElemIndex != 0)
                        {
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.BeginHorizontal();
                    }

                    DecorPaintObjectPlacementBrushElement brushElement = allBrushElements[brushElemIndex];
                    var previewButtonRenderData = new PrefabPreviewButtonRenderData();
                    previewButtonRenderData.ExtractFromPrefab(brushElement.Prefab, Data.ElementPreviewScale);

                    Color previewTint = brushElement != _brush.ActiveElement ? Color.white : Data.ActiveElementTintColor;
                    if (_brush.ActiveElement != brushElement && !brushElement.IsEnabled)
                    {
                        previewTint = Data.DisabledElementTintColor;
                    }

                    EditorGUILayout.BeginVertical(GUILayout.Width(previewButtonRenderData.ButtonWidth));
                    EditorGUIColor.Push(previewTint);
                    if (EditorGUILayoutEx.PrefabPreview(brushElement.Prefab, true, previewButtonRenderData))
                    {
                        if (Event.current.button == (int)MouseButton.Left)
                        {
                            if (brushElement != _brush.ActiveElement)
                            {
                                UndoEx.RecordForToolAction(_brush);
                                _brush.SetActiveElement(brushElement);
                            }
                        }
                        else
                        if (Event.current.button == (int)MouseButton.Right)
                        {
                            if (!Event.current.shift)
                            {
                                UndoEx.RecordForToolAction(_brush);
                                _brush.RemoveAndDestroyElement(brushElement);
                            }
                            else
                            {
                                UndoEx.RecordForToolAction(brushElement);
                                brushElement.IsEnabled = !brushElement.IsEnabled;
                            }
                        }
                    }
                    EditorGUIColor.Pop();
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();
            Rect prefabDropRect = GUILayoutUtility.GetLastRect();

            EditorGUILayout.BeginHorizontal();
            var content = new GUIContent();

            content.text    = "Load active category";
            content.tooltip = "Loads all the prefabs from the active category inside the active brush. Note: Prefabs which already exist in the brush, will be ignored.";
            if (GUILayout.Button(content, GUILayout.Width(130.0f)))
            {
                UndoEx.RecordForToolAction(_brush);
                _brush.LoadAllPrefabsInActiveCategory();
            }
            RenderRemoveAllElementsButton();

            content.text    = "Look and feel...";
            content.tooltip = "Opens up a new window which allows you to control the look and feel of the brush elements view.";
            if (GUILayout.Button(content, GUILayout.Width(110.0f)))
            {
                Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.DecorPaintBrushViewLookAndFeelWindow.ViewData = Data;
                Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.DecorPaintBrushViewLookAndFeelWindow.ShowOctave3DWindow();
            }
            EditorGUILayout.EndHorizontal();

            if (_brush.ActiveElement != null)
            {
                EditorGUILayout.Separator();
                _brush.ActiveElement.View.Render();
            }

            PrefabsToDecorPaintBrushEventHandler.Get().DropDest         = PrefabsToDecorPaintBrushEventHandler.DropDestination.Brush;
            PrefabsToDecorPaintBrushEventHandler.Get().DestinationBrush = _brush;
            PrefabsToDecorPaintBrushEventHandler.Get().Handle(Event.current, prefabDropRect);
        }