示例#1
0
        public static void PreferenceWindow()
        {
            EditorGUI.BeginChangeCheck();
            {
                CSGSettings.ShowTooltips       = EditorGUILayout.ToggleLeft("Show Tool-Tips", CSGSettings.ShowTooltips);
                CSGSettings.SnapNonCSGObjects  = EditorGUILayout.ToggleLeft("Snap Non-CSG Objects to the grid", CSGSettings.SnapNonCSGObjects);
                CSGSettings.DefaultPreserveUVs = EditorGUILayout.ToggleLeft("Preserve UVs (Default)", CSGSettings.DefaultPreserveUVs);
                EditorGUILayout.Space();
                CSGSettings.MaxCircleSides  = EditorGUILayout.IntField("Max Circle Sides", CSGSettings.MaxCircleSides);
                CSGSettings.MaxSphereSplits = EditorGUILayout.IntField("Max Sphere Splits", CSGSettings.MaxSphereSplits);
                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Surfaces", EditorStyles.boldLabel);
                var beforeToggleWorldSpaceTexture = (CSGSettings.DefaultTexGenFlags & TexGenFlags.WorldSpaceTexture) != TexGenFlags.WorldSpaceTexture;
                var afterToggleWorldSpaceTexture  = EditorGUILayout.ToggleLeft("Lock Texture To Object (Default)", beforeToggleWorldSpaceTexture);
                if (afterToggleWorldSpaceTexture != beforeToggleWorldSpaceTexture)
                {
                    if (afterToggleWorldSpaceTexture)
                    {
                        CSGSettings.DefaultTexGenFlags &= ~TexGenFlags.WorldSpaceTexture;
                    }
                    else
                    {
                        CSGSettings.DefaultTexGenFlags |= TexGenFlags.WorldSpaceTexture;
                    }
                }

                CSGSettings.ShowSceneInfo = EditorGUILayout.ToggleLeft("Show Scene Info", CSGSettings.ShowSceneInfo);
            }
            if (EditorGUI.EndChangeCheck())
            {
                CSGSettings.Save();
            }
        }
示例#2
0
        static void OnGUIContentsMaterialImage(bool isSceneGUI, Material material, bool mixedValues, SelectedBrushSurface[] selectedBrushSurfaces)
        {
            GUILayout.BeginHorizontal(materialWidth, materialHeight);
            {
                //if (materialEditor == null || prevMaterial != material)
                {
                    var editor = materialEditor as Editor;
                    Editor.CreateCachedEditor(material, typeof(MaterialEditor), ref editor);
                    materialEditor = editor as MaterialEditor;
                    //prevMaterial = material;
                }

                if (materialEditor != null)
                {
                    var rect = GUILayoutUtility.GetRect(materialSize, materialSize);
                    EditorGUI.showMixedValue = mixedValues;
                    materialEditor.OnPreviewGUI(rect, GUIStyle.none);
                    EditorGUI.showMixedValue = false;
                }
                else
                {
                    GUILayout.Box(new GUIContent(), CSG_GUIStyleUtility.emptyMaterialStyle, materialWidth, materialHeight);
                }
            }
            GUILayout.EndHorizontal();
            var currentArea  = GUILayoutUtility.GetLastRect();
            var currentPoint = Event.current.mousePosition;

            if (currentArea.Contains(currentPoint))
            {
                if (Event.current.type == EventType.DragUpdated &&
                    GetDragMaterial())
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.DragPerform)
                {
                    var new_material = GetDragMaterial();
                    if (new_material)
                    {
                        SurfaceUtility.SetMaterials(selectedBrushSurfaces, new_material);
                        CSGSettings.DefaultMaterial = new_material;
                        CSGSettings.Save();
                        GUI.changed = true;
                        Event.current.Use();
                    }
                }
            }
        }
        internal static void CreateRenderPipelineVersionOfDefaultMaterials(Material defaultMaterial)
        {
            if (_pipeline.Length < 1)
            {
                _pipeline = defaultMaterial.shader.name.StartsWith("HDRP") ? "HDRP" : "URP";
            }

            if (!defaultMaterial)
            {
                return;
            }

            CreateRenderPipelineVersionOfDefaultMaterial(defaultMaterial, WallMaterialName);
            CreateRenderPipelineVersionOfDefaultMaterial(defaultMaterial, FloorMaterialName);
            CreateRenderPipelineVersionOfDefaultMaterial(defaultMaterial, WindowMaterialName);
            CreateRenderPipelineVersionOfDefaultMaterial(defaultMaterial, MetalMaterialName);

            CSGSettings.Reload();
            var currentMaterial = CSGSettings.DefaultMaterial;

            if (!currentMaterial)
            {
                return;
            }

            var currentMaterialPath = AssetDatabase.GetAssetPath(currentMaterial);

            if (!currentMaterialPath.StartsWith(DefaultMaterialPath))
            {
                return;
            }

            var materialPath = string.Format("{0}{1}/", DefaultMaterialPath, _pipeline);

            if (currentMaterialPath.StartsWith(materialPath))
            {
                return;
            }

            var newMaterialPath = currentMaterialPath.Replace(DefaultMaterialPath, materialPath);

            currentMaterial = AssetDatabase.LoadAssetAtPath <Material>(newMaterialPath);
            if (currentMaterial)
            {
                CSGSettings.DefaultMaterial = currentMaterial;
            }
            CSGSettings.Save();
        }
示例#4
0
 protected bool IgnoreDepthForRayCasts(Camera camera)
 {
     return(CSGSettings.Assume2DView(camera));
 }
示例#5
0
        protected override void HandleCreateShapeEvents(Rect sceneRect)
        {
            bool     pointOnEdge      = false;
            bool     havePlane        = false;
            bool     vertexOnGeometry = false;
            CSGBrush vertexOnBrush    = null;

            CSGPlane hoverBuildPlane = buildPlane;
            var      sceneView       = SceneView.currentDrawingSceneView; //(SceneView.currentDrawingSceneView != null) ? SceneView.currentDrawingSceneView : SceneView.lastActiveSceneView;
            var      camera          = (sceneView == null) ? null : sceneView.camera;
            var      assume2DView    = CSGSettings.Assume2DView(sceneView);

            if (camera != null &&
                camera.pixelRect.Contains(Event.current.mousePosition))
            {
                if (!hoverDefaultPlane.HasValue ||
                    settings.vertices.Length == 0)
                {
                    bool forceGrid = RealtimeCSG.CSGGrid.ForceGrid;
                    RealtimeCSG.CSGGrid.ForceGrid = false;
                    hoverDefaultPlane             = RealtimeCSG.CSGGrid.CurrentGridPlane;
                    RealtimeCSG.CSGGrid.ForceGrid = forceGrid;
                    firstSnappedEdges             = null;
                    firstSnappedBrush             = null;
                    firstSnappedPlanes            = null;
                    base.geometryModel            = null;
                }
                if (editMode == EditMode.CreatePlane)
                {
                    BrushIntersection intersection;
                    if (!assume2DView && !havePlane &&
                        SceneQueryUtility.FindWorldIntersection(Event.current.mousePosition, out intersection))
                    {
                        worldPosition = intersection.worldIntersection;
                        if (intersection.surfaceInverted)
                        {
                            hoverBuildPlane = intersection.plane.Negated();
                        }
                        else
                        {
                            hoverBuildPlane = intersection.plane;
                        }
                        vertexOnBrush = intersection.brush;

                        vertexOnGeometry = true;
                    }
                    else
                    {
                        hoverBuildPlane = hoverDefaultPlane.Value;
                        vertexOnBrush   = null;

                        var mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                        worldPosition    = hoverBuildPlane.Intersection(mouseRay);
                        vertexOnGeometry = false;
                    }
                    ResetVisuals();
                    if (snapFunction != null)
                    {
                        CSGBrush snappedOnBrush;
                        worldPosition = snapFunction(worldPosition, hoverBuildPlane, ref visualSnappedEdges, out snappedOnBrush, generatedBrushes, ignoreAllBrushes: true);
                        if (snappedOnBrush != null)
                        {
                            pointOnEdge = (visualSnappedEdges != null &&
                                           visualSnappedEdges.Count > 0);
                            vertexOnBrush    = snappedOnBrush;
                            vertexOnGeometry = true;
                        }
                    }

                    if (settings.vertices.Length == 1)
                    {
                        if (hoverBuildPlane.normal != MathConstants.zeroVector3)
                        {
                            editMode  = EditMode.CreateShape;
                            havePlane = true;
                        }
                    }
                }
                else
                {
                    var mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    if (settings.vertices.Length == 2)
                    {
                        var startPoint = settings.vertices[1];

                        var forward = camera.transform.forward;
                        if (Vector3.Dot(forward, gridBinormal) < Vector3.Dot(forward, gridTangent))
                        {
                            hoverBuildPlane = new CSGPlane(gridBinormal, startPoint);
                        }
                        else
                        {
                            hoverBuildPlane = new CSGPlane(gridTangent, startPoint);
                        }
                        worldPosition = hoverBuildPlane.Intersection(mouseRay);

                        // the third point is always straight up from the second point
                        //worldPosition = startPoint + (Vector3.Dot(worldPosition - startPoint, gridNormal) * gridNormal);

                        RealtimeCSG.CSGGrid.SetForcedGrid(hoverBuildPlane);
                        ResetVisuals();
                        if (raySnapFunction != null)
                        {
                            Ray      ray = new Ray(startPoint, gridNormal);
                            CSGBrush snappedOnBrush;
                            worldPosition = raySnapFunction(worldPosition, ray, ref visualSnappedEdges, out snappedOnBrush);
                            if (snappedOnBrush != null)
                            {
                                pointOnEdge = (visualSnappedEdges != null &&
                                               visualSnappedEdges.Count > 0);
                                vertexOnBrush = snappedOnBrush;
                            }
                        }

                        worldPosition = GeometryUtility.ProjectPointOnInfiniteLine(worldPosition, startPoint, gridNormal);
                    }
                    else
                    {
                        worldPosition = hoverBuildPlane.Intersection(mouseRay);

                        RealtimeCSG.CSGGrid.SetForcedGrid(hoverBuildPlane);
                        ResetVisuals();
                        if (snapFunction != null)
                        {
                            CSGBrush snappedOnBrush;
                            worldPosition = snapFunction(worldPosition, hoverBuildPlane, ref visualSnappedEdges, out snappedOnBrush, generatedBrushes, ignoreAllBrushes: true);
                            if (snappedOnBrush != null)
                            {
                                pointOnEdge = (visualSnappedEdges != null &&
                                               visualSnappedEdges.Count > 0);
                                vertexOnBrush = snappedOnBrush;
                            }
                        }
                    }
                }

                if (geometryModel == null && vertexOnBrush != null)
                {
                    var brush_cache = InternalCSGModelManager.GetBrushCache(vertexOnBrush);
                    if (brush_cache != null && brush_cache.childData != null && brush_cache.childData.Model)
                    {
                        geometryModel = brush_cache.childData.Model;
                    }
                }

                if (worldPosition != prevWorldPosition)
                {
                    prevWorldPosition = worldPosition;
                    if (settings.vertices.Length > 0)
                    {
                        if ((settings.vertices[0] - worldPosition).sqrMagnitude > MathConstants.EqualityEpsilon)
                        {
                            UpdateSizes();
                            UpdateBaseShape(true);
                        }
                    }
                    if (Event.current.type != EventType.Repaint)
                    {
                        SceneView.RepaintAll();
                    }
                }

                visualSnappedGrid  = RealtimeCSG.CSGGrid.FindAllGridEdgesThatTouchPoint(worldPosition);
                visualSnappedBrush = vertexOnBrush;
            }
            RealtimeCSG.CSGGrid.SetForcedGrid(hoverBuildPlane);



            if (!SceneDragToolManager.IsDraggingObjectInScene &&
                Event.current.type == EventType.Repaint)
            {
                PaintSnapVisualisation();
                PaintShape(base.shapeId);
            }


            var type = Event.current.GetTypeForControl(base.shapeId);

            switch (type)
            {
            case EventType.Layout:
            {
                return;
            }

            case EventType.ValidateCommand:
            case EventType.KeyDown:
            {
                if (GUIUtility.hotControl == base.shapeId)
                {
                    if (Keys.PerformActionKey.IsKeyPressed() ||
                        Keys.DeleteSelectionKey.IsKeyPressed() ||
                        Keys.CancelActionKey.IsKeyPressed())
                    {
                        Event.current.Use();
                    }
                }
                return;
            }

            case EventType.KeyUp:
            {
                if (GUIUtility.hotControl == base.shapeId)
                {
                    if (Keys.CylinderBuilderMode.IsKeyPressed() ||
                        Keys.PerformActionKey.IsKeyPressed())
                    {
                        HotKeyReleased();
                        Event.current.Use();
                        return;
                    }
                    if (Keys.DeleteSelectionKey.IsKeyPressed() ||
                        Keys.CancelActionKey.IsKeyPressed())
                    {
                        Cancel();
                        Event.current.Use();
                        return;
                    }
                }
                return;
            }

            case EventType.MouseDown:
            {
                if (!sceneRect.Contains(Event.current.mousePosition))
                {
                    break;
                }
                if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                {
                    return;
                }
                if ((GUIUtility.hotControl != 0 && GUIUtility.hotControl != shapeEditId && GUIUtility.hotControl != base.shapeId) ||
                    Event.current.button != 0)
                {
                    return;
                }

                Event.current.Use();
                if (settings.vertices.Length == 0)
                {
                    if ((GUIUtility.hotControl == 0 ||
                         GUIUtility.hotControl == base.shapeEditId) && base.shapeId != -1)
                    {
                        base.CalculateWorldSpaceTangents();
                        GUIUtility.hotControl             = base.shapeId;
                        GUIUtility.keyboardControl        = base.shapeId;
                        EditorGUIUtility.editingTextField = false;
                    }
                }

                if (GUIUtility.hotControl == base.shapeId &&
                    settings.vertices.Length < kMaxPoints)
                {
                    if (!float.IsNaN(worldPosition.x) && !float.IsInfinity(worldPosition.x) &&
                        !float.IsNaN(worldPosition.y) && !float.IsInfinity(worldPosition.y) &&
                        !float.IsNaN(worldPosition.z) && !float.IsInfinity(worldPosition.z))
                    {
                        if (settings.vertices.Length < 2 &&
                            hoverBuildPlane.normal.sqrMagnitude != 0)
                        {
                            buildPlane = hoverBuildPlane;
                        }
                        CalculateWorldSpaceTangents();

                        if (settings.vertices.Length == 0)
                        {
                            if (pointOnEdge)
                            {
                                firstSnappedEdges  = visualSnappedEdges.ToArray();
                                firstSnappedBrush  = visualSnappedBrush;
                                firstSnappedPlanes = null;
                            }
                            else
                            {
                                firstSnappedBrush  = null;
                                firstSnappedEdges  = null;
                                firstSnappedPlanes = null;
                            }
                            planeOnGeometry = vertexOnGeometry;
                        }
                        else
                        {
                            if (firstSnappedEdges != null)
                            {
                                if (firstSnappedPlanes == null)
                                {
                                    CreateSnappedPlanes();
                                }

                                bool outside = true;
                                for (int i = 0; i < firstSnappedPlanes.Length; i++)
                                {
                                    if (firstSnappedPlanes[i].Distance(worldPosition) <= MathConstants.DistanceEpsilon)
                                    {
                                        outside = false;
                                        break;
                                    }
                                }

                                planeOnGeometry = !outside;
                            }

                            if (vertexOnGeometry)
                            {
                                var plane    = hoverDefaultPlane.Value;
                                var distance = plane.Distance(worldPosition);
                                plane.d          += distance;
                                hoverDefaultPlane = plane;

                                for (int i = 0; i < settings.vertices.Length; i++)
                                {
                                    if (!settings.onGeometryVertices[i])
                                    {
                                        settings.SetPoint(i, GeometryUtility.ProjectPointOnPlane(plane, settings.vertices[i]));
                                        settings.onGeometryVertices[i] = true;
                                    }
                                }
                            }
                        }
                        ArrayUtility.Add(ref settings.onGeometryVertices, vertexOnGeometry);
                        settings.AddPoint(worldPosition);

                        UpdateSizes();
                        SceneView.RepaintAll();
                        if (settings.vertices.Length == kMaxPoints)
                        {
                            HotKeyReleased();
                        }
                    }
                }
                return;
            }

            case EventType.MouseDrag:
            {
                if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                {
                    break;
                }
                if (GUIUtility.hotControl == base.shapeId && Event.current.button == 0)
                {
                    Event.current.Use();
                }
                return;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl != base.shapeId)
                {
                    return;
                }
                if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                {
                    return;
                }
                if (Event.current.button == 0)
                {
                    Event.current.Use();

                    ResetVisuals();
                    if (settings.vertices.Length == kMaxPoints)
                    {
                        GUIUtility.hotControl             = 0;
                        GUIUtility.keyboardControl        = 0;
                        EditorGUIUtility.editingTextField = false;

                        editMode = EditMode.CreateShape;
                        HotKeyReleased();
                    }
                }
                return;
            }
            }
        }
示例#6
0
        /*
         *              GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
         *              {
         *
         *                      GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
         *                      {
         *                              //GUILayout.Label(Keys.VerticalMoveMode.ToString() + " to dragging brush up/down", EditorStyles.miniLabel);
         *                              GUILayout.Label("Control (hold) to drag polygon on it's plane", EditorStyles.miniLabel);
         *                              GUILayout.Label("Shift (hold) to drag extrude polygon", EditorStyles.miniLabel);
         *                              GUILayout.Label("Shift (hold) to chamfer edges and vertices", EditorStyles.miniLabel);
         *                      }
         *                      GUILayout.EndVertical();
         *              }
         *              GUILayout.EndHorizontal();*/
        static void OnGUIContents(bool isSceneGUI, EditModeMeshEdit tool)
        {
            EditModeCommonGUI.StartToolGUI();

            var filteredSelection = EditModeManager.FilteredSelection;

            var left   = EditorStyles.miniButtonLeft;
            var middle = EditorStyles.miniButtonMid;
            var right  = EditorStyles.miniButtonRight;
            var button = GUI.skin.button;


            var defaultMaterial = CSGSettings.DefaultMaterial;

            GUILayout.BeginVertical(isSceneGUI ? InSceneWidth : CSG_GUIStyleUtility.ContentEmpty);
            {
                ShowCSGOperations(isSceneGUI, tool, filteredSelection);
                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    var selectionIgnoreBackfaced = CSGSettings.HiddenSurfacesNotSelectable;
                    var selectionVertex          = CSGSettings.SelectionVertex;
                    var selectionEdge            = CSGSettings.SelectionEdge;
                    var selectionSurface         = CSGSettings.SelectionSurface;

                    EditorGUILayout.LabelField(ContentSelection);
                    EditorGUI.BeginChangeCheck();
                    {
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            selectionIgnoreBackfaced = GUILayout.Toggle(selectionIgnoreBackfaced, ContentIgnoreHidden, button);
                            TooltipUtility.SetToolTip(TooltipIgnoreHidden);
                        }
                        GUILayout.EndHorizontal();
                        if (!selectionVertex && !selectionEdge && !selectionSurface)
                        {
                            GUILayout.Label("No selection mode has been selected and nothing can be selected", CSG_GUIStyleUtility.redTextArea);
                        }
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            selectionVertex = GUILayout.Toggle(selectionVertex, ContentVertex, button);
                            TooltipUtility.SetToolTip(TooltipVertex);

                            selectionEdge = GUILayout.Toggle(selectionEdge, ContentEdge, button);
                            TooltipUtility.SetToolTip(TooltipEdge);

                            selectionSurface = GUILayout.Toggle(selectionSurface, ContentSurface, button);
                            TooltipUtility.SetToolTip(TooltipSurface);
                        }
                        GUILayout.EndHorizontal();
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        CSGSettings.HiddenSurfacesNotSelectable = selectionIgnoreBackfaced;
                        CSGSettings.SelectionVertex             = selectionVertex;
                        CSGSettings.SelectionEdge    = selectionEdge;
                        CSGSettings.SelectionSurface = selectionSurface;
                        CSGSettings.Save();
                    }
                    GUILayout.Space(3);
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    var autoCommitExtrusion = CSGSettings.AutoCommitExtrusion;
                    EditorGUI.BeginChangeCheck();
                    {
                        autoCommitExtrusion = GUILayout.Toggle(autoCommitExtrusion, ContentAutoCommitExtrusion, button);
                        TooltipUtility.SetToolTip(TooltipAutoCommitExtrusion);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        CSGSettings.AutoCommitExtrusion = autoCommitExtrusion;
                        CSGSettings.Save();
                    }
                }
                GUILayout.EndVertical();
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    if (isSceneGUI)
                    {
                        GUILayout.Space(4);
                        GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial, small: true);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    bool have_nodes = tool != null && (filteredSelection.NodeTargets.Length > 0);

                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUI.BeginDisabledGroup(!have_nodes);
                        {
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentFlip, labelWidth);
                                }
                                else
                                {
                                    EditorGUILayout.LabelField(ContentFlip, largeLabelWidth);
                                }

                                if (GUILayout.Button(ContentFlipX, left))
                                {
                                    tool.FlipX();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipX);
                                if (GUILayout.Button(ContentFlipY, middle))
                                {
                                    tool.FlipY();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipY);
                                if (GUILayout.Button(ContentFlipZ, right))
                                {
                                    tool.FlipZ();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipZ);
                            }
                            GUILayout.EndHorizontal();

                            /*
                             * EditorGUILayout.LabelField(ContentEdgesLabel);
                             * GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                             * {
                             *      EditorGUI.BeginDisabledGroup(!tool.CanSmooth());
                             *      {
                             *              if (GUILayout.Button("Smooth"))		{ tool.Smooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             *      EditorGUI.BeginDisabledGroup(!tool.CanUnSmooth());
                             *      {
                             *              if (GUILayout.Button("Un-smooth"))	{ tool.UnSmooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             * }
                             * GUILayout.EndHorizontal();
                             */

                            if (GUILayout.Button(ContentSnapToGrid))
                            {
                                tool.SnapToGrid(Camera.current);
                            }
                            TooltipUtility.SetToolTip(TooltipSnapToGrid);
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(2);
                if (!isSceneGUI)
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial, small: false);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                    }
                    if (EditorGUI.EndChangeCheck() && defaultMaterial)
                    {
                        CSGSettings.DefaultMaterial = defaultMaterial;
                        CSGSettings.Save();
                    }
                }
            }
            GUILayout.EndVertical();
            EditorGUI.showMixedValue = false;
        }
示例#7
0
 public static void DoubleGridSize()
 {
     CSGSettings.SnapVector *= 2f;
     CSGSettings.Save();
 }
示例#8
0
 public static void ToggleRealtimeCSG()
 {
     CSGSettings.SetRealtimeCSGEnabled(!CSGSettings.EnableRealtimeCSG);
 }
示例#9
0
        static void OnGUIContents(bool isSceneGUI, EditModeClip tool)
        {
            EditModeCommonGUI.StartToolGUI();

            if (tool.ClipBrushCount == 0)
            {
                GUILayout.Label(string.Format("no brushes selected", tool.ClipBrushCount), CSG_GUIStyleUtility.redTextArea);
            }
            else
            {
                if (tool.ClipBrushCount == 1)
                {
                    GUILayout.Label(string.Format("{0} brush selected", tool.ClipBrushCount));
                }
                else
                {
                    GUILayout.Label(string.Format("{0} brushes selected", tool.ClipBrushCount));
                }
            }
            EditorGUILayout.Space();
            EditorGUI.BeginDisabledGroup(tool == null);
            {
                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    var newClipMode = (tool != null) ? tool.clipMode : ((ClipMode)999);
                    var skin        = CSG_GUIStyleUtility.Skin;
                    for (int i = 0; i < clipModeValues.Length; i++)
                    {
                        var        selected = newClipMode == clipModeValues[i];
                        GUIContent content;
                        GUIStyle   style;
                        if (selected)
                        {
                            style = CSG_GUIStyleUtility.selectedIconLabelStyle;   content = skin.clipNamesOn[i];
                        }
                        else
                        {
                            style = CSG_GUIStyleUtility.unselectedIconLabelStyle; content = skin.clipNames[i];
                        }
                        if (GUILayout.Toggle(selected, content, style))
                        {
                            newClipMode = clipModeValues[i];
                        }
                        TooltipUtility.SetToolTip(CSG_GUIStyleUtility.clipTooltips[i]);
                    }
                    if (tool != null && tool.clipMode != newClipMode)
                    {
                        tool.SetClipMode(newClipMode);
                    }
                }
                GUILayout.EndVertical();
                if (!isSceneGUI)
                {
                    GUILayout.Space(10);
                }

                bool disabled = (tool == null || tool.editMode != EditModeClip.EditMode.EditPoints);

                var defaultMaterial = CSGSettings.DefaultMaterial;
                GUILayout.BeginVertical(isSceneGUI ? MaterialSceneWidth : CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        if (isSceneGUI)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                        }
                        {
                            EditorGUI.BeginDisabledGroup(disabled);
                            {
                                if (GUILayout.Button(ContentCancel))
                                {
                                    doCancel = true;
                                }
                                TooltipUtility.SetToolTip(CancelTooltip);
                                if (GUILayout.Button(ContentCommit))
                                {
                                    doCommit = true;
                                }
                                TooltipUtility.SetToolTip(CommitTooltip);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        if (isSceneGUI)
                        {
                            GUILayout.EndVertical();
                        }
                    }
                    GUILayout.EndHorizontal();
                    if (isSceneGUI)
                    {
                        GUILayout.Space(2);
                        EditorGUI.BeginChangeCheck();
                        {
                            defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                        }
                        if (EditorGUI.EndChangeCheck() && defaultMaterial)
                        {
                            CSGSettings.DefaultMaterial = defaultMaterial;
                            CSGSettings.Save();
                        }
                    }
                }
                if (!isSceneGUI)
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial, small: false);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
示例#10
0
        /*
         * static void OnGUIContentsMaterialInspector(Material material, bool mixedValues)
         * {
         *      //if (materialEditor == null || prevMaterial != material)
         *      {
         *              var editor = materialEditor as Editor;
         *              Editor.CreateCachedEditor(material, typeof(MaterialEditor), ref editor);
         *              materialEditor = editor as MaterialEditor;
         *      }
         *
         *      if (materialEditor != null)
         *      {
         *              EditorGUI.showMixedValue = mixedValues;
         *              try
         *              {
         *                      materialEditor.DrawHeader();
         *                      if (materialEditor.PropertiesGUI())
         *                      {
         *                              materialEditor.PropertiesChanged();
         *                      }
         *              }
         *              catch
         *              {}
         *              EditorGUI.showMixedValue = false;
         *      }
         * }
         */

        private static void OnGUIContents(bool isSceneGUI, EditModeSurface tool)
        {
            EditModeCommonGUI.StartToolGUI();

            var selectedBrushSurfaces = (tool == null) ? new SelectedBrushSurface[0] : tool.GetSelectedSurfaces();
            var enabled = selectedBrushSurfaces.Length > 0;

            EditorGUI.BeginDisabledGroup(!enabled);
            {
                Material material      = null;
                var      currentTexGen = new TexGen();

                var  haveTexgen            = false;
                var  multipleColors        = !enabled;
                var  multipleTranslationX  = !enabled;
                var  multipleTranslationY  = !enabled;
                var  multipleScaleX        = !enabled;
                var  multipleScaleY        = !enabled;
                var  multipleRotationAngle = !enabled;
                var  multipleMaterials     = !enabled;
                bool?textureLocked         = null;

                bool foundHelperMaterial = false;
                RenderSurfaceType?firstRenderSurfaceType = null;
                Material          firstMaterial          = null;
                if (selectedBrushSurfaces.Length > 0)
                {
                    for (var i = 0; i < selectedBrushSurfaces.Length; i++)
                    {
                        var brush = selectedBrushSurfaces[i].brush;
                        if (!brush)
                        {
                            continue;
                        }
                        var surfaceIndex = selectedBrushSurfaces[i].surfaceIndex;
                        if (surfaceIndex >= brush.Shape.Surfaces.Length)
                        {
                            Debug.LogWarning("surface_index >= brush.Shape.Surfaces.Length");
                            continue;
                        }
                        var texGenIndex = brush.Shape.Surfaces[surfaceIndex].TexGenIndex;
                        if (texGenIndex >= brush.Shape.TexGens.Length)
                        {
                            Debug.LogWarning("texGen_index >= brush.Shape.TexGens.Length");
                            continue;
                        }
                        var      brushCache = InternalCSGModelManager.GetBrushCache(brush);
                        var      model      = (brushCache != null) ? brushCache.childData.Model : null;
                        Material foundMaterial;
                        var      texGenFlags = brush.Shape.TexGenFlags[texGenIndex];
                        if (model && (!model.IsRenderable || model.ShadowsOnly))
                        {
                            foundHelperMaterial = true;
                            if (!firstRenderSurfaceType.HasValue)
                            {
                                firstRenderSurfaceType = ModelTraits.GetModelSurfaceType(model);
                            }
                            foundMaterial = null;
                        }
                        else
                        if ((texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender)
                        {
                            foundHelperMaterial = true;
                            if (!firstRenderSurfaceType.HasValue)
                            {
                                if ((texGenFlags & TexGenFlags.NoCastShadows) != TexGenFlags.NoCastShadows)
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.ShadowOnly;
                                }
                                else
                                if ((texGenFlags & TexGenFlags.NoCollision) != TexGenFlags.NoCollision)
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.Collider;
                                }
                                else
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.Hidden;
                                }
                            }
                            foundMaterial = null;
                        }
                        else
                        {
                            var surfaceMaterial = brush.Shape.TexGens[texGenIndex].RenderMaterial;
                            if (!foundHelperMaterial)
                            {
                                var surfaceType = MaterialUtility.GetMaterialSurfaceType(surfaceMaterial);
                                if (!firstRenderSurfaceType.HasValue)
                                {
                                    firstRenderSurfaceType = surfaceType;
                                }
                                foundHelperMaterial = surfaceType != RenderSurfaceType.Normal;
                            }
                            foundMaterial = surfaceMaterial;
                        }
                        if ((texGenFlags & TexGenFlags.WorldSpaceTexture) == TexGenFlags.WorldSpaceTexture)
                        {
                            if (i == 0)
                            {
                                textureLocked = false;
                            }
                            else if (textureLocked.HasValue && textureLocked.Value)
                            {
                                textureLocked = null;
                            }
                        }
                        else
                        {
                            if (i == 0)
                            {
                                textureLocked = true;
                            }
                            else if (textureLocked.HasValue && !textureLocked.Value)
                            {
                                textureLocked = null;
                            }
                        }
                        if (foundMaterial != material)
                        {
                            if (!material)
                            {
                                firstMaterial = foundMaterial;
                                material      = foundMaterial;
                            }
                            else
                            {
                                multipleMaterials = true;
                            }
                        }
                        if (!haveTexgen)
                        {
                            currentTexGen = brush.Shape.TexGens[texGenIndex];
                            haveTexgen    = true;
                        }
                        else
                        {
                            if (!multipleColors)
                            {
                                var color = brush.Shape.TexGens[texGenIndex].Color;
                                multipleColors = currentTexGen.Color.a != color.a ||
                                                 currentTexGen.Color.b != color.b ||
                                                 currentTexGen.Color.g != color.g ||
                                                 currentTexGen.Color.r != color.r;
                            }
                            if (!multipleScaleX || !multipleScaleY)
                            {
                                var scale = brush.Shape.TexGens[texGenIndex].Scale;
                                multipleScaleX = multipleScaleX || currentTexGen.Scale.x != scale.x;
                                multipleScaleY = multipleScaleY || currentTexGen.Scale.y != scale.y;
                            }

                            if (!multipleTranslationX || !multipleTranslationY)
                            {
                                var translation = brush.Shape.TexGens[texGenIndex].Translation;
                                multipleTranslationX = multipleTranslationX || currentTexGen.Translation.x != translation.x;
                                multipleTranslationY = multipleTranslationY || currentTexGen.Translation.y != translation.y;
                            }

                            if (!multipleRotationAngle)
                            {
                                var rotationAngle = brush.Shape.TexGens[texGenIndex].RotationAngle;
                                multipleRotationAngle = currentTexGen.RotationAngle != rotationAngle;
                            }
                        }
                    }
                    if (foundHelperMaterial && !firstMaterial)
                    {
                        if (firstRenderSurfaceType.HasValue)
                        {
                            firstMaterial = MaterialUtility.GetSurfaceMaterial(firstRenderSurfaceType.Value);
                        }
                        else
                        {
                            firstMaterial = MaterialUtility.HiddenMaterial;
                        }
                    }
                }

                GUILayout.BeginVertical(isSceneGUI ? materialDoubleWidth : CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        /*
                         * Color new_color;
                         * EditorGUI.BeginChangeCheck();
                         * {
                         *      EditorGUI.showMixedValue = multipleColors;
                         *      // why doesn't the colorfield return a modified color?
                         *      try
                         *      {
                         *              new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color);
                         *      }
                         *      catch
                         *      {
                         *              new_color = currentTexGen.Color;
                         *      }
                         * }
                         * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color)
                         * {
                         *      SurfaceUtility.SetColors(selectedBrushSurfaces, new_color);
                         * }
                         */
                        if (isSceneGUI)
                        {
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginDisabledGroup(material == null);
                                {
                                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                                    {
                                        GUILayout.Space(1);

                                        /*
                                         * Color new_color;
                                         * EditorGUI.BeginChangeCheck();
                                         * {
                                         *      EditorGUI.showMixedValue = multipleColors;
                                         *      // why doesn't the colorfield return a modified color?
                                         *      try
                                         *      {
                                         *              new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color);
                                         *      }
                                         *      catch
                                         *      {
                                         *              new_color = currentTexGen.Color;
                                         *      }
                                         * }
                                         * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color)
                                         * {
                                         *      SurfaceUtility.SetColors(selectedBrushSurfaces, new_color);
                                         * }
                                         *
                                         * GUILayout.Space(1);
                                         */
                                        Material newMaterial;
                                        EditorGUI.BeginChangeCheck();
                                        {
                                            EditorGUI.showMixedValue = multipleMaterials;
                                            newMaterial = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                            EditorGUI.showMixedValue = false;
                                        }
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            if (newMaterial)
                                            {
                                                SurfaceUtility.SetMaterials(selectedBrushSurfaces, newMaterial);
                                                CSGSettings.DefaultMaterial = newMaterial;
                                                CSGSettings.Save();
                                            }
                                        }
                                    }
                                    GUILayout.EndVertical();
                                    GUILayout.Space(1);
                                }
                                EditorGUI.EndDisabledGroup();
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.Space(4);
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                GUILayout.Space(2);
                                OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces);
                                GUILayout.BeginHorizontal(materialWidth);
                                {
                                    GUILayout.FlexibleSpace();
                                    GUILayout.BeginVertical(materialHeight);
                                    {
                                        OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces);
                                        GUILayout.FlexibleSpace();
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                                GUILayout.FlexibleSpace();
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    if (currentTexGen.Scale.x == 0.0f)
                    {
                        currentTexGen.Scale.x = 1.0f;
                    }
                    if (currentTexGen.Scale.y == 0.0f)
                    {
                        currentTexGen.Scale.y = 1.0f;
                    }

                    const float scale_round = 10000.0f;
                    currentTexGen.Scale.x       = Mathf.RoundToInt(currentTexGen.Scale.x * scale_round) / scale_round;
                    currentTexGen.Scale.y       = Mathf.RoundToInt(currentTexGen.Scale.y * scale_round) / scale_round;
                    currentTexGen.Translation.x = Mathf.RoundToInt(currentTexGen.Translation.x * scale_round) / scale_round;
                    currentTexGen.Translation.y = Mathf.RoundToInt(currentTexGen.Translation.y * scale_round) / scale_round;
                    currentTexGen.RotationAngle = Mathf.RoundToInt(currentTexGen.RotationAngle * scale_round) / scale_round;

                    var leftStyle   = isSceneGUI ? EditorStyles.miniButtonLeft  : GUI.skin.button;
                    var middleStyle = isSceneGUI ? EditorStyles.miniButtonMid   : GUI.skin.button;
                    var rightStyle  = isSceneGUI ? EditorStyles.miniButtonRight : GUI.skin.button;

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !textureLocked.HasValue;
                            textureLocked            = EditorGUILayout.ToggleLeft(ContentLockTexture, textureLocked.HasValue ? textureLocked.Value : false);
                            TooltipUtility.SetToolTip(ToolTipLockTexture);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            SurfaceUtility.SetTextureLock(selectedBrushSurfaces, textureLocked.Value);
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentUVScale, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentUVScale, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipScaleUV);

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentUSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleScaleX;
                                    currentTexGen.Scale.x    = EditorGUILayout.FloatField(currentTexGen.Scale.x, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetScaleX(selectedBrushSurfaces, currentTexGen.Scale.x);
                                }
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentVSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleScaleY;
                                    currentTexGen.Scale.y    = EditorGUILayout.FloatField(currentTexGen.Scale.y, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetScaleY(selectedBrushSurfaces, currentTexGen.Scale.y);
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentOffset, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentOffset, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipOffsetUV);

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentUSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleTranslationX;
                                    currentTexGen.Translation.x = EditorGUILayout.FloatField(currentTexGen.Translation.x, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetTranslationX(selectedBrushSurfaces, currentTexGen.Translation.x);
                                }

                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentVSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleTranslationY;
                                    currentTexGen.Translation.y = EditorGUILayout.FloatField(currentTexGen.Translation.y, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetTranslationY(selectedBrushSurfaces, currentTexGen.Translation.y);
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentRotate, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentRotate, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipRotation);

                            if (!isSceneGUI)
                            {
                                GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                            }

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleRotationAngle;
                                    currentTexGen.RotationAngle = EditorGUILayout.FloatField(currentTexGen.RotationAngle, minFloatFieldWidth);
                                    if (!isSceneGUI)
                                    {
                                        EditorGUILayout.LabelField(ContentAngleSymbol, unitWidth);
                                    }
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetRotationAngle(selectedBrushSurfaces, currentTexGen.RotationAngle);
                                }
                            }
                            GUILayout.EndHorizontal();

                            var buttonWidth = isSceneGUI ? new GUILayoutOption[] { angleButtonWidth } : new GUILayoutOption[0];
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (GUILayout.Button(ContentRotate90Negative, leftStyle, buttonWidth))
                                {
                                    SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, -90.0f);
                                }
                                TooltipUtility.SetToolTip(ToolTipRotate90Negative);
                                if (GUILayout.Button(ContentRotate90Positive, rightStyle, buttonWidth))
                                {
                                    SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, +90.0f);
                                }
                                TooltipUtility.SetToolTip(ToolTipRotate90Positive);
                            }
                            GUILayout.EndHorizontal();
                            if (!isSceneGUI)
                            {
                                GUILayout.EndVertical();
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentFit, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentFit, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentFitX, leftStyle))
                            {
                                SurfaceUtility.FitSurfaceX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitX);
                            if (GUILayout.Button(ContentFitXY, middleStyle))
                            {
                                SurfaceUtility.FitSurface(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitXY);
                            if (GUILayout.Button(ContentFitY, rightStyle))
                            {
                                SurfaceUtility.FitSurfaceY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentReset, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentReset, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentResetX, leftStyle))
                            {
                                SurfaceUtility.ResetSurfaceX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetX);
                            if (GUILayout.Button(ContentResetXY, middleStyle))
                            {
                                SurfaceUtility.ResetSurface(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetXY);
                            if (GUILayout.Button(ContentResetY, rightStyle))
                            {
                                SurfaceUtility.ResetSurfaceY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentFlip, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentFlip, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentFlipX, leftStyle))
                            {
                                SurfaceUtility.FlipX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipX);
                            if (GUILayout.Button(ContentFlipXY, middleStyle))
                            {
                                SurfaceUtility.FlipXY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipXY);
                            if (GUILayout.Button(ContentFlipY, rightStyle))
                            {
                                SurfaceUtility.FlipY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentScale, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentScale, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentDoubleScale, leftStyle))
                            {
                                SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 2.0f);
                            }
                            TooltipUtility.SetToolTip(ToolTipDoubleScale);
                            if (GUILayout.Button(ContentHalfScale, rightStyle))
                            {
                                SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 0.5f);
                            }
                            TooltipUtility.SetToolTip(ToolTipHalfScale);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    if (!isSceneGUI)
                    {
                        OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces);
                    }

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        EditModeCommonGUI.OnSurfaceFlagButtons(selectedBrushSurfaces, isSceneGUI);
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanSmooth(selectedBrushSurfaces));
                            {
                                if (GUILayout.Button(ContentSmoothSurfaces, leftStyle))
                                {
                                    SurfaceUtility.Smooth(selectedBrushSurfaces);
                                }
                                TooltipUtility.SetToolTip(ToolTipSmoothSurfaces);
                            }
                            EditorGUI.EndDisabledGroup();
                            EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanUnSmooth(selectedBrushSurfaces));
                            {
                                if (GUILayout.Button(ContentUnSmoothSurfaces, rightStyle))
                                {
                                    SurfaceUtility.UnSmooth(selectedBrushSurfaces);
                                }
                                TooltipUtility.SetToolTip(ToolTipUnSmoothSurfaces);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                        Material new_material;
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUILayout.LabelField(ContentMaterial, largeLabelWidth);
                            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleMaterials;
                                    new_material             = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                    EditorGUI.showMixedValue = false;
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (!new_material)
                                    {
                                        new_material = MaterialUtility.MissingMaterial;
                                    }
                                    SurfaceUtility.SetMaterials(selectedBrushSurfaces, new_material);
                                }
                            }
                            GUILayout.Space(2);
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                GUILayout.Space(5);
                                OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces);
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                        // Unity won't let us do this
                        //GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        //OnGUIContentsMaterialInspector(first_material, multiple_materials);
                        //GUILayout.EndVertical();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.showMixedValue = false;
        }
示例#11
0
        static void OnGUIContents(EditModeGenerate tool, bool isSceneGUI, float height)
        {
            if (!isSceneGUI)
            {
                Rect shapeModeBounds;
                var  csg_skin = CSG_GUIStyleUtility.Skin;
                tool.BuilderMode = (ShapeMode)CSG_EditorGUIUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: CSG_GUIStyleUtility.shapeModeTooltips, yOffset: height, areaWidth: EditorGUIUtility.currentViewWidth - 4);
                GUILayout.Space(shapeModeBounds.height);

                EditModeCommonGUI.StartToolGUI();

                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                {
                    ChooseOperation(tool, isSceneGUI);
                    tool.CurrentGenerator.OnShowGUI(isSceneGUI);
                    CommitOrCancel(isSceneGUI, tool);
                    EditorGUILayout.Space();
                    var defaultMaterial = CSGSettings.DefaultMaterial;
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                tool.CurrentGenerator.OnDefaultMaterialModified();
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial, small: false);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                tool.CurrentGenerator.OnDefaultMaterialModified();
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                EditorGUILayout.EndScrollView();
            }
            if (isSceneGUI)
            {
                GUILayout.BeginHorizontal(GUILayout.MinHeight(100));
                {
                    GUILayout.BeginVertical(GUILayout.Width(100));
                    {
                        GUILayout.FlexibleSpace();

                        var rect = GUILayoutUtility.GetLastRect();

                        var  csg_skin = CSG_GUIStyleUtility.Skin;
                        Rect shapeModeBounds;
                        tool.BuilderMode = (ShapeMode)CSG_EditorGUIUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: CSG_GUIStyleUtility.shapeModeTooltips, yOffset: rect.y, xOffset: rect.x, areaWidth: 100);
                        GUILayout.Space(shapeModeBounds.height);

                        ChooseOperation(tool, isSceneGUI);
                    }
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        tool.CurrentGenerator.OnShowGUI(isSceneGUI);
                        GUILayout.FlexibleSpace();
                        CommitOrCancel(isSceneGUI, tool);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
        }
示例#12
0
        static void CommitOrCancel(bool isSceneGUI, EditModeGenerate tool)
        {
            var defaultMaterial = CSGSettings.DefaultMaterial;

            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                if (isSceneGUI)
                {
                    GUILayout.Space(5);
                    GUILayout.BeginVertical(GUILayout.MinWidth(10));
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            defaultMaterial = CSG_EditorGUIUtility.MaterialImage(defaultMaterial);
                        }
                        if (EditorGUI.EndChangeCheck() && defaultMaterial)
                        {
                            CSGSettings.DefaultMaterial = defaultMaterial;
                            tool.CurrentGenerator.OnDefaultMaterialModified();
                            CSGSettings.Save();
                        }
                    }
                    GUILayout.EndVertical();
                    GUILayout.Space(4);
                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                }
                {
                    var generator = tool.CurrentGenerator;
                    EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                    {
                        if (GUILayout.Button(CancelContent))
                        {
                            generator.DoCancel();
                        }
                        TooltipUtility.SetToolTip(CancelTooltip);
                        if (GUILayout.Button(CreateContent))
                        {
                            generator.DoCommit();
                        }
                        TooltipUtility.SetToolTip(CreateTooltip);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                if (isSceneGUI)
                {
                    GUILayout.EndVertical();
                }
            }
            GUILayout.EndHorizontal();
            if (isSceneGUI)
            {
                GUILayout.Space(2);
                EditorGUI.BeginChangeCheck();
                {
                    defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                }
                if (EditorGUI.EndChangeCheck() && defaultMaterial)
                {
                    CSGSettings.DefaultMaterial = defaultMaterial;
                    tool.CurrentGenerator.OnDefaultMaterialModified();
                    CSGSettings.Save();
                }
            }
        }
示例#13
0
 protected bool IgnoreDepthForRayCasts(SceneView sceneview)
 {
     return(CSGSettings.Assume2DView(sceneview));
 }
示例#14
0
        internal static void OnScene(SceneView sceneView)
        {
            if (Event.current.type == EventType.MouseMove)
            {
                sceneView.Repaint();
            }

            sceneView.cameraSettings.dynamicClip         = false;
            sceneView.cameraSettings.easingEnabled       = false;
            sceneView.cameraSettings.accelerationEnabled = false;

            //if (sceneView.orthographic)
            //{
            //    sceneView.camera.nearClipPlane = 1;
            //    sceneView.camera.farClipPlane = 1001f;

            //    var camPos = sceneView.pivot;
            //    var camForward = sceneView.camera.transform.forward;
            //    for (int i = 0; i < 3; i++)
            //    {
            //        if (!FastApproximately(camForward[i], 0, .01f))
            //        {
            //            camPos[i] = 1000;
            //        }
            //    }
            //    sceneView.pivot = camPos;
            //}

            if (sceneView.orthographic)
            {
                if (Event.current.type == EventType.KeyDown &&
                    Event.current.keyCode == KeyCode.F)
                {
                    Event.current.Use();
                    sceneView.pivot = Vector3.zero;
                    if (TryGetSelectionBounds(out Bounds bounds))
                    {
                        var sz = bounds.extents.magnitude;
                        sz = Mathf.Clamp(sz, 0.05f, 500);
                        sceneView.pivot = bounds.center;
                        sceneView.size  = sz;
                    }
                }

                if (sceneView.size > 500)
                {
                    sceneView.size = 500;
                }

                if (sceneView.size < .05f)
                {
                    sceneView.size = .05f;
                }
            }

            CSGSettings.RegisterSceneView(sceneView);

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG ||
                EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            UpdateLoop.UpdateOnSceneChange();

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                ColorSettings.isInitialized = false;
            }
            else if (!ColorSettings.isInitialized)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    ColorSettings.Update();
                }
            }

            if (!UpdateLoop.IsActive())
            {
                UpdateLoop.ResetUpdateRoutine();
            }

            if (Event.current.type == EventType.MouseDown ||
                Event.current.type == EventType.MouseDrag)
            {
                mousePressed = true;
            }
            else if (Event.current.type == EventType.MouseUp ||
                     Event.current.type == EventType.MouseMove)
            {
                mousePressed = false;
            }

            SceneDragToolManager.OnHandleDragAndDrop(sceneView);
            RectangleSelectionManager.Update(sceneView);
            EditModeManager.InitSceneGUI(sceneView);

            if (Event.current.type == EventType.Repaint)
            {
                MeshInstanceManager.UpdateHelperSurfaces();
                SceneToolRenderer.OnPaint(sceneView);
            }
            else
            {
                SceneViewBottomBarGUI.ShowGUI(sceneView);
                SceneViewInfoGUI.DrawInfoGUI(sceneView);
            }

            //if(EditorWindow.mouseOverWindow == sceneView)
            {
                EditModeManager.OnSceneGUI(sceneView);

                TooltipUtility.InitToolTip(sceneView);

                if (!mousePressed)
                {
                    Handles.BeginGUI();
                    TooltipUtility.DrawToolTip(getLastRect: false);
                    Handles.EndGUI();
                }

                if (Event.current.type == EventType.Layout)
                {
                    var currentFocusControl = CSGHandles.FocusControl;
                    if (prevFocusControl != currentFocusControl)
                    {
                        prevFocusControl = currentFocusControl;
                        HandleUtility.Repaint();
                    }
                }
            }
        }
        protected void GrabHeightHandle(SceneView sceneView, int index, bool ignoreFirstMouseUp = false)
        {
            var camera = sceneView.camera;

            if (camera == null)
            {
                return;
            }

            var assume2DView = CSGSettings.Assume2DView(camera);

            firstClick                        = ignoreFirstMouseUp;
            editMode                          = EditMode.ExtrudeShape;
            GUIUtility.hotControl             = extrusionPoints[index].ID;
            GUIUtility.keyboardControl        = extrusionPoints[index].ID;
            EditorGUIUtility.editingTextField = false;
            EditorGUIUtility.SetWantsMouseJumping(1);

            var     surfaceDirection = buildPlane.normal;
            var     closestAxisForward = GeometryUtility.SnapToClosestAxis(-camera.transform.forward);
            var     closestAxisArrow = GeometryUtility.SnapToClosestAxis(surfaceDirection);
            Vector3 tangent, normal;
            float   dot = Mathf.Abs(Vector3.Dot(closestAxisForward, closestAxisArrow));

            if (dot != 1)
            {
                Vector3 v1, v2;
                if (closestAxisForward.x == 0 && closestAxisForward.y == 0)
                {
                    v1 = new Vector3(1, 0, 0);
                    v2 = new Vector3(0, 1, 0);
                }
                else
                if (closestAxisForward.x == 0 && closestAxisForward.z == 0)
                {
                    v1 = new Vector3(1, 0, 0);
                    v2 = new Vector3(0, 0, 1);
                }
                else
                //if (closestAxisForward.y == 0 && closestAxisForward.z == 0)
                {
                    v1 = new Vector3(0, 1, 0);
                    v2 = new Vector3(0, 0, 1);
                }

                var   backward = -camera.transform.forward;
                float dot1     = Vector3.Dot(backward, v1);
                float dot2     = Vector3.Dot(backward, v2);
                if (dot1 < dot2)
                {
                    tangent = v1;
                }
                else
                {
                    tangent = v2;
                }
            }
            else
            {
                tangent = GeometryUtility.SnapToClosestAxis(Vector3.Cross(surfaceDirection, -camera.transform.forward));
            }

            normal = Vector3.Cross(surfaceDirection, tangent);

            if (assume2DView)
            {
                normal = -camera.transform.forward;
            }

            if (normal == MathConstants.zeroVector3)
            {
                normal = GeometryUtility.SnapToClosestAxis(-camera.transform.forward);
            }

            movePlane = new CSGPlane(normal, extrusionPoints[index].Position);
            if (!assume2DView && Mathf.Abs(movePlane.Distance(camera.transform.position)) < 2.0f)
            {
                var new_tangent = Vector3.Cross(normal, closestAxisForward);
                if (new_tangent != MathConstants.zeroVector3)
                {
                    tangent   = new_tangent;
                    normal    = Vector3.Cross(surfaceDirection, tangent);
                    movePlane = new CSGPlane(normal, extrusionPoints[index].Position);
                }
            }

            movePolygonDirection = haveForcedDirection ? forcedDirection : buildPlane.normal;

            if (!isFinished)
            {
                RealtimeCSG.CSGGrid.SetForcedGrid(camera, movePlane);
            }

            var plane = new CSGPlane(buildPlane.normal, extrusionPoints[index].Position);

            heightPosition = Event.current.mousePosition;

            heightHandleOffset = (plane.Distance(GetHeightHandlePosition(sceneView, extrusionPoints[index].Position)) * movePolygonDirection);

            if (float.IsInfinity(heightHandleOffset.x) || float.IsNaN(heightHandleOffset.x) ||
                float.IsInfinity(heightHandleOffset.y) || float.IsNaN(heightHandleOffset.y) ||
                float.IsInfinity(heightHandleOffset.z) || float.IsNaN(heightHandleOffset.z))
            {
                heightHandleOffset = Vector3.zero;
            }
        }
示例#16
0
        static void OnGUIContents(bool isSceneGUI, MeshEditBrushTool tool)
        {
            CommonGUI.StartToolGUI();

            var filteredSelection = CSGBrushEditorManager.FilteredSelection;

            var defaultMaterial = CSGSettings.DefaultMaterial;

            GUILayout.BeginVertical(isSceneGUI ? InSceneWidth : GUIStyleUtility.ContentEmpty);
            {            /*
                          *     GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                          *     {
                          *
                          *             GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                          *             {
                          *                     //GUILayout.Label(Keys.VerticalMoveMode.ToString() + " to dragging brush up/down", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Control (hold) to drag polygon on it's plane", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Shift (hold) to drag extrude polygon", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Shift (hold) to chamfer edges and vertices", EditorStyles.miniLabel);
                          *             }
                          *             GUILayout.EndVertical();
                          *     }
                          *     GUILayout.EndHorizontal();*/
                ChooseCSGOperation(filteredSelection, isSceneGUI, tool);
                GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                {
                    if (isSceneGUI)
                    {
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: true);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                    {
                        bool have_nodes = tool != null && (filteredSelection.NodeTargets.Length > 0);

                        EditorGUI.BeginDisabledGroup(!have_nodes);
                        {
                            GUIStyle left   = EditorStyles.miniButtonLeft;
                            GUIStyle middle = EditorStyles.miniButtonMid;
                            GUIStyle right  = EditorStyles.miniButtonRight;

                            GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                            {
                                if (isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentFlip, labelWidth);
                                }
                                else
                                {
                                    EditorGUILayout.LabelField(ContentFlip, largeLabelWidth);
                                }
                                if (GUILayout.Button(ContentFlipX, left))
                                {
                                    tool.FlipX();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipX);
                                if (GUILayout.Button(ContentFlipY, middle))
                                {
                                    tool.FlipY();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipY);
                                if (GUILayout.Button(ContentFlipZ, right))
                                {
                                    tool.FlipZ();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipZ);
                            }
                            GUILayout.EndHorizontal();

                            /*
                             * EditorGUILayout.LabelField(ContentEdgesLabel);
                             * GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                             * {
                             *      EditorGUI.BeginDisabledGroup(!tool.CanSmooth());
                             *      {
                             *              if (GUILayout.Button("Smooth"))		{ tool.Smooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             *      EditorGUI.BeginDisabledGroup(!tool.CanUnSmooth());
                             *      {
                             *              if (GUILayout.Button("Un-smooth"))	{ tool.UnSmooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             * }
                             * GUILayout.EndHorizontal();
                             */

                            if (GUILayout.Button(ContentSnapToGrid))
                            {
                                tool.SnapToGrid();
                            }
                            TooltipUtility.SetToolTip(TooltipSnapToGrid);
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(2);
                if (!isSceneGUI)
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: false);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                    }
                    if (EditorGUI.EndChangeCheck() && defaultMaterial)
                    {
                        CSGSettings.DefaultMaterial = defaultMaterial;
                        CSGSettings.Save();
                    }
                }
            }
            GUILayout.EndVertical();
            EditorGUI.showMixedValue = false;
        }
        internal static void OnScene(SceneView sceneView)
        {
            CSGSettings.RegisterSceneView(sceneView);
            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                return;
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }
            UpdateLoop.UpdateOnSceneChange();

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                ColorSettings.isInitialized = false;
            }
            else
            if (!ColorSettings.isInitialized)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    ColorSettings.Update();
                }
            }

            if (!UpdateLoop.IsActive())
            {
                UpdateLoop.ResetUpdateRoutine();
            }

            if (Event.current.type == EventType.MouseDown ||
                Event.current.type == EventType.MouseDrag)
            {
                mousePressed = true;
            }
            else if (Event.current.type == EventType.MouseUp ||
                     Event.current.type == EventType.MouseMove)
            {
                mousePressed = false;
            }

            SceneDragToolManager.OnHandleDragAndDrop(sceneView);
            RectangleSelectionManager.Update(sceneView);
            EditModeManager.InitSceneGUI(sceneView);

            if (Event.current.type == EventType.Repaint)
            {
                MeshInstanceManager.RenderHelperSurfaces(sceneView);
            }

            if (Event.current.type == EventType.Repaint)
            {
                SceneToolRenderer.OnPaint(sceneView);
            }
            else
            //if (fallbackGUI)
            {
                SceneViewBottomBarGUI.ShowGUI(sceneView);
                SceneViewInfoGUI.DrawInfoGUI(sceneView);
            }

            EditModeManager.OnSceneGUI(sceneView);

            //if (fallbackGUI)
            {
                TooltipUtility.InitToolTip(sceneView);
                if (Event.current.type == EventType.Repaint)
                {
                    SceneViewBottomBarGUI.ShowGUI(sceneView);
                    SceneViewInfoGUI.DrawInfoGUI(sceneView);
                }
                if (!mousePressed)
                {
                    Handles.BeginGUI();
                    TooltipUtility.DrawToolTip(getLastRect: false);
                    Handles.EndGUI();
                }
            }

            if (Event.current.type == EventType.Layout)
            {
                var currentFocusControl = CSGHandles.FocusControl;
                if (prevFocusControl != currentFocusControl)
                {
                    prevFocusControl = currentFocusControl;
                    HandleUtility.Repaint();
                }
            }
        }
示例#18
0
		protected override void HandleCreateShapeEvents(SceneView sceneView, Rect sceneRect)
		{
			bool		pointOnEdge			= false;
			bool		havePlane			= false;
			bool		vertexOnGeometry	= false;
			CSGBrush	vertexOnBrush		= null;
			
			CSGPlane	hoverBuildPlane		= buildPlane;
            var camera = sceneView.camera;
            var assume2DView = CSGSettings.Assume2DView(camera);
			if (camera != null &&
				camera.pixelRect.Contains(Event.current.mousePosition))
			{
				if (!hoverDefaultPlane.HasValue ||
					settings.vertices.Length == 0)
				{
					bool forceGrid = RealtimeCSG.CSGGrid.ForceGrid;
					RealtimeCSG.CSGGrid.ForceGrid = false;
					hoverDefaultPlane = RealtimeCSG.CSGGrid.CurrentGridPlane;
					RealtimeCSG.CSGGrid.ForceGrid = forceGrid;
					firstSnappedEdges = null;
					firstSnappedBrush = null;
					firstSnappedPlanes = null;
					base.geometryModel = null;
				}
				if (editMode == EditMode.CreatePlane)
				{
					LegacyBrushIntersection intersection;
					if (!assume2DView && !havePlane &&
                        EditorWindow.mouseOverWindow == sceneView &&
                        SceneQueryUtility.FindWorldIntersection(camera, Event.current.mousePosition, out intersection))
					{
						worldPosition = intersection.worldIntersection;
						hoverBuildPlane = intersection.worldPlane;
						vertexOnBrush = intersection.brush;

						vertexOnGeometry = true;
					} else
					{
						hoverBuildPlane = hoverDefaultPlane.Value;
						vertexOnBrush = null;

						var mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
						worldPosition = hoverBuildPlane.RayIntersection(mouseRay);
						vertexOnGeometry = false;
					}
					
					ResetVisuals();
					if (snapFunction != null)
					{
						CSGBrush snappedOnBrush;
						worldPosition = snapFunction(camera, worldPosition, hoverBuildPlane, ref visualSnappedEdges, out snappedOnBrush, generatedBrushes, ignoreAllBrushes: true);
						if (snappedOnBrush != null)
						{
							pointOnEdge = (visualSnappedEdges != null &&
									  visualSnappedEdges.Count > 0);
							vertexOnBrush = snappedOnBrush;
							vertexOnGeometry = true;
						}
					}

					if (settings.vertices.Length == 1)
					{
						if (hoverBuildPlane.normal != MathConstants.zeroVector3)
						{
							editMode = EditMode.CreateShape;
							havePlane = true;
						}
					}
				} else
				{
					var mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
					worldPosition = hoverBuildPlane.RayIntersection(mouseRay);

					ResetVisuals();
					if (snapFunction != null)
					{
						CSGBrush snappedOnBrush;
						worldPosition = snapFunction(camera, worldPosition, hoverBuildPlane, ref visualSnappedEdges, out snappedOnBrush, generatedBrushes, ignoreAllBrushes: true);
						if (snappedOnBrush != null)
						{
							pointOnEdge = (visualSnappedEdges != null &&
											visualSnappedEdges.Count > 0);
							vertexOnBrush = snappedOnBrush;
						}
					}
				}

				if (geometryModel == null && vertexOnBrush != null)
				{
					if (vertexOnBrush.ChildData != null && vertexOnBrush.ChildData.Model)
						geometryModel = vertexOnBrush.ChildData.Model;
				}

				if (worldPosition != prevWorldPosition)
				{
					prevWorldPosition = worldPosition;
					if (settings.vertices.Length > 0)
					{
						if (hadSphere || (settings.vertices[0] - worldPosition).sqrMagnitude > MathConstants.EqualityEpsilon)
						{
							hadSphere = true;
							UpdateBaseShape(true);
						}
					}
					if (Event.current.type != EventType.Repaint)
						CSG_EditorGUIUtility.RepaintAll();
				}
				
				visualSnappedGrid = RealtimeCSG.CSGGrid.FindAllGridEdgesThatTouchPoint(camera, worldPosition);
				visualSnappedBrush = vertexOnBrush;
			}
			
			RealtimeCSG.CSGGrid.SetForcedGrid(camera, hoverBuildPlane);
			

			if (!SceneDragToolManager.IsDraggingObjectInScene &&
				Event.current.type == EventType.Repaint)
			{
				PaintSnapVisualisation();
				PaintCircle(sceneView, base.shapeId);
			}
			

			var type = Event.current.GetTypeForControl(base.shapeId);
			switch (type)
			{
				case EventType.Layout:
				{
					return;
				}

				case EventType.ValidateCommand:
				case EventType.KeyDown:
				{
					if (GUIUtility.hotControl == base.shapeId)
					{
						if (Keys.PerformActionKey.IsKeyPressed() ||
							Keys.DeleteSelectionKey.IsKeyPressed() ||
							Keys.CancelActionKey.IsKeyPressed())
						{
							Event.current.Use();
						}
					}
					return;
				}
				case EventType.KeyUp:
				{
					if (GUIUtility.hotControl == base.shapeId)
					{
						if (Keys.CylinderBuilderMode.IsKeyPressed() ||
							Keys.PerformActionKey.IsKeyPressed())
						{
							HotKeyReleased(); 
							Event.current.Use();
							return;
						}
						if (Keys.DeleteSelectionKey.IsKeyPressed() ||
							Keys.CancelActionKey.IsKeyPressed())
						{
							Cancel();
							Event.current.Use();
							return;
						}
					}
					return;
				}

				case EventType.MouseDown:
				{
					if (!sceneRect.Contains(Event.current.mousePosition))
						break;
					if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
						return;
					if ((GUIUtility.hotControl != 0 && GUIUtility.hotControl != shapeEditId && GUIUtility.hotControl != base.shapeId) ||
						Event.current.button != 0)
						return;
					
					Event.current.Use();
					if (settings.vertices.Length == 0)
					{
						if ((GUIUtility.hotControl == 0 ||
							GUIUtility.hotControl == base.shapeEditId) && base.shapeId != -1)
                        {
							base.CalculateWorldSpaceTangents(camera);
                            GUIUtility.hotControl = base.shapeId;
							GUIUtility.keyboardControl = base.shapeId;
							EditorGUIUtility.editingTextField = false; 
						}
					}

					if (GUIUtility.hotControl == base.shapeId && settings.vertices.Length < 2)
					{
						if (!float.IsNaN(worldPosition.x) && !float.IsInfinity(worldPosition.x) &&
							!float.IsNaN(worldPosition.y) && !float.IsInfinity(worldPosition.y) &&
							!float.IsNaN(worldPosition.z) && !float.IsInfinity(worldPosition.z))
						{
							if (hoverBuildPlane.normal.sqrMagnitude != 0)
								buildPlane = hoverBuildPlane;
							CalculateWorldSpaceTangents(camera);

							if (settings.vertices.Length == 0)
							{
								if (pointOnEdge)
								{
									firstSnappedEdges = visualSnappedEdges.ToArray();
									firstSnappedBrush = visualSnappedBrush;
									firstSnappedPlanes = null;
								} else
								{
									firstSnappedBrush = null;
									firstSnappedEdges = null;
									firstSnappedPlanes = null;
								}
								planeOnGeometry = vertexOnGeometry;
							} else
							{
								if (firstSnappedEdges != null)
								{
									if (firstSnappedPlanes == null)
										CreateSnappedPlanes();

									bool outside = true;
									for (int i = 0; i < firstSnappedPlanes.Length; i++)
									{
										if (firstSnappedPlanes[i].Distance(worldPosition) <= MathConstants.DistanceEpsilon)
										{
											outside = false;
											break;
										}
									}

									planeOnGeometry = !outside;
								}

								if (vertexOnGeometry)
								{
									var plane = hoverDefaultPlane.Value;
									var distance = plane.Distance(worldPosition);
									plane.d += distance;
									hoverDefaultPlane = plane;

									for (int i = 0; i < settings.vertices.Length; i++)
									{
										if (!settings.onGeometryVertices[i])
										{
											settings.vertices[i] = GeometryUtility.ProjectPointOnPlane(plane, settings.vertices[i]);
											settings.onGeometryVertices[i] = true;
										}
									}
								}
							}
							ArrayUtility.Add(ref settings.onGeometryVertices, vertexOnGeometry);
							settings.AddPoint(worldPosition);
							CSG_EditorGUIUtility.RepaintAll();
							if (settings.vertices.Length == 2)
							{
								HotKeyReleased();
							}
						}
					}
					return;
				}
				case EventType.MouseDrag:
				{
					if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
						break;
					if (GUIUtility.hotControl == base.shapeId && Event.current.button == 0)
					{
						Event.current.Use();
					}
					return;
				}
				case EventType.MouseUp:
				{
					if (GUIUtility.hotControl != base.shapeId)
						return;
					if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
						return;
					if (Event.current.button == 0)
					{
						Event.current.Use(); 

						ResetVisuals();
						if (settings.vertices.Length == 2)
						{
							GUIUtility.hotControl = 0;
							GUIUtility.keyboardControl = 0;
							EditorGUIUtility.editingTextField = false;

							editMode = EditMode.CreateShape;
							HotKeyReleased();
						}
					}
					return;
				}
			}
		}
示例#19
0
 public static void HalfGridSize()
 {
     CSGSettings.SnapVector *= .5f;
     CSGSettings.Save();
 }