Пример #1
0
        static void ChooseOperation(EditModeGenerate tool, bool isSceneGUI)
        {
            var  generator = tool.CurrentGenerator;
            bool enabled   = generator.HaveBrushes;

            EditorGUI.BeginDisabledGroup(!enabled);
            {
                if (isSceneGUI)
                {
                    GUILayout.BeginVertical(GUI.skin.box, Width100);
                }
                else
                {
                    GUILayout.BeginVertical(GUIStyle.none);
                }
                {
                    bool             mixedValues = !enabled;
                    CSGOperationType operation   = generator.CurrentCSGOperationType;
                    EditorGUI.BeginChangeCheck();
                    operation = CSG_EditorGUIUtility.ChooseOperation(operation, mixedValues);
                    if (EditorGUI.EndChangeCheck())
                    {
                        generator.CurrentCSGOperationType = operation;
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
Пример #2
0
        static void OnModifierKeysChanged()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            CSG_EditorGUIUtility.RepaintAll();
        }
Пример #3
0
        static void OnModifierKeysChanged()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            CSG_EditorGUIUtility.UpdateSceneViews();
        }
        static float FloatUnitsSettings(float value, GUIContent content, ToolTip tooltip, bool isSceneGUI)
        {
            var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
            var unitText     = Units.GetUnitGUIContent(distanceUnit);

            float newValue;

            EditorGUI.BeginChangeCheck();
            {
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.Label(content, width80);
                    if (isSceneGUI)
                    {
                        TooltipUtility.SetToolTip(tooltip);
                    }

                    if (!isSceneGUI)
                    {
                        newValue = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, value)));
                    }
                    else
                    {
                        newValue = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, value), width65));
                    }

                    if (GUILayout.Button(unitText, EditorStyles.miniLabel, width25))
                    {
                        distanceUnit = Units.CycleToNextUnit(distanceUnit);;
                        RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                        RealtimeCSG.CSGSettings.UpdateSnapSettings();
                        RealtimeCSG.CSGSettings.Save();
                        CSG_EditorGUIUtility.RepaintAll();
                    }
                }
                GUILayout.EndHorizontal();
                if (!isSceneGUI)
                {
                    TooltipUtility.SetToolTip(tooltip);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                return(newValue);
            }
            return(value);
        }
Пример #5
0
		void Cleanup()
		{
			if (prevSelection != null)	Selection.objects			= prevSelection;
			else						Selection.activeTransform	= null;
			prevSelection = null;
			
			if (GUIUtility.hotControl == shapeId)
			{
				GUIUtility.hotControl = 0;
				GUIUtility.keyboardControl = 0;
				EditorGUIUtility.SetWantsMouseJumping(0);
				EditorGUIUtility.editingTextField = false;
			}
			
			isFinished  = true;
			CSG_EditorGUIUtility.RepaintAll();
		}
Пример #6
0
        public static float OnEditModeSelectionGUI()
        {
            CSG_GUIStyleUtility.InitStyles();

            EditorGUI.BeginChangeCheck();
            Rect editModeBounds;
            var  newEditMode = (ToolEditMode)CSG_EditorGUIUtility.ToolbarWrapped((int)EditModeManager.EditMode, ref editModeRects, out editModeBounds, CSG_GUIStyleUtility.brushEditModeContent, CSG_GUIStyleUtility.brushEditModeTooltips);

            if (EditorGUI.EndChangeCheck())
            {
                EditModeManager.EditMode = newEditMode;
                CSG_EditorGUIUtility.RepaintAll();
            }
            GUILayout.Space(editModeBounds.height);


            return(editModeBounds.height);
        }
Пример #7
0
        void DrawListElement(Rect rect, GUIContent toggleName, int helperSurfaces, int flag)
        {
            EditorGUI.BeginChangeCheck();
            bool result = GUI.Toggle(rect, ((helperSurfaces & flag) != 0), toggleName, CSG_GUIStyleUtility.Skin.menuItem);

            if (EditorGUI.EndChangeCheck())
            {
                if (result)
                {
                    RealtimeCSG.CSGSettings.VisibleHelperSurfaces = (HelperSurfaceFlags)(helperSurfaces | flag);
                }
                else
                {
                    RealtimeCSG.CSGSettings.VisibleHelperSurfaces = (HelperSurfaceFlags)(helperSurfaces & ~flag);
                }
                MeshInstanceManager.UpdateHelperSurfaceVisibility();
                RealtimeCSG.CSGSettings.Save();
                CSG_EditorGUIUtility.RepaintAll();
            }
        }
Пример #8
0
        private void Draw(Rect rect)
        {
            var allVisibleSurfaces = (int)HelperSurfaceFlags.ShowVisibleSurfaces;
            var allHelperSurfaces  = s_Flags.allSurfaces & ~allVisibleSurfaces;

            var drawPos = new Rect(kFrameWidth, kFrameWidth, rect.width - 2 * kFrameWidth, kLineHeight);

            var helperSurfaces = (int)RealtimeCSG.CSGSettings.VisibleHelperSurfaces;

            EditorGUI.BeginChangeCheck();
            GUI.Toggle(drawPos, helperSurfaces == allVisibleSurfaces, s_Flags.onlyVisibleContent, CSG_GUIStyleUtility.Skin.menuItem);
            if (EditorGUI.EndChangeCheck())
            {
                RealtimeCSG.CSGSettings.VisibleHelperSurfaces = (HelperSurfaceFlags)allVisibleSurfaces;
                MeshInstanceManager.UpdateHelperSurfaceVisibility();
                RealtimeCSG.CSGSettings.Save();
                CSG_EditorGUIUtility.RepaintAll();
            }
            drawPos.y += kLineHeight;

            EditorGUI.BeginChangeCheck();
            GUI.Toggle(drawPos, helperSurfaces == allHelperSurfaces, s_Flags.allHelperContent, CSG_GUIStyleUtility.Skin.menuItem);
            if (EditorGUI.EndChangeCheck())
            {
                RealtimeCSG.CSGSettings.VisibleHelperSurfaces = (HelperSurfaceFlags)allHelperSurfaces;
                MeshInstanceManager.UpdateHelperSurfaceVisibility();
                RealtimeCSG.CSGSettings.Save();
                CSG_EditorGUIUtility.RepaintAll();
            }
            drawPos.y += kLineHeight;

            drawPos.y += 4;

            for (int i = 0; i < s_Flags.helperSurfaceFlagContent.Length; i++)
            {
                var flag = s_Flags.helperSurfaceFlagValues[i];
                DrawListElement(drawPos, s_Flags.helperSurfaceFlagContent[i], helperSurfaces, flag);
                drawPos.y += kLineHeight;
            }
        }
        void Cleanup()
        {
            if (prevSelection != null)
            {
                Selection.objects = prevSelection;
            }
            else
            {
                Selection.activeTransform = null;
            }
            prevSelection = null;

            if (GUIUtility.hotControl == shapeId)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;
                EditorGUIUtility.SetWantsMouseJumping(0);
                EditorGUIUtility.editingTextField = false;
            }

            isFinished = true;
            CSG_EditorGUIUtility.UpdateSceneViews();
        }
        static void OnGUIContents(GeneratorCylinder generator, bool isSceneGUI)
        {
            //GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
            //{
            //bool enabled = generator.HaveBrushes;
            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                /*
                 * EditorGUI.BeginDisabledGroup(!enabled);
                 * {
                 *      if (isSceneGUI)
                 *              GUILayout.BeginVertical(GUI.skin.box, width100);
                 *      else
                 *              GUILayout.BeginVertical(GUIStyle.none);
                 *      {
                 *              bool mixedValues = !enabled;
                 *              CSGOperationType operation = generator.CurrentCSGOperationType;
                 *              EditorGUI.BeginChangeCheck();
                 *              operation = CSG_EditorGUIUtility.ChooseOperation(operation, mixedValues);
                 *              if (EditorGUI.EndChangeCheck())
                 *              {
                 *                      generator.CurrentCSGOperationType = operation;
                 *              }
                 *      }
                 *      GUILayout.EndVertical();
                 * }
                 * EditorGUI.EndDisabledGroup();
                 */
                if (isSceneGUI)
                {
                    CylinderSettingsGUI(generator, isSceneGUI);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
                var nextUnit     = Units.CycleToNextUnit(distanceUnit);
                var unitText     = Units.GetUnitGUIContent(distanceUnit);
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.Label(HeightContent, width65);
                    if (isSceneGUI)
                    {
                        TooltipUtility.SetToolTip(HeightTooltip);
                    }
                    var height = generator.HaveHeight ? generator.Height : GeometryUtility.CleanLength(generator.DefaultHeight);
                    EditorGUI.BeginChangeCheck();
                    {
                        if (!isSceneGUI)
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height)));
                        }
                        else
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height), width65));
                        }
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (generator.HaveHeight)
                        {
                            generator.Height = height;
                        }
                        else
                        {
                            generator.DefaultHeight = height;
                        }
                    }
                    if (GUILayout.Button(unitText, EditorStyles.miniLabel, width20))
                    {
                        distanceUnit = nextUnit;
                        RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                        RealtimeCSG.CSGSettings.UpdateSnapSettings();
                        RealtimeCSG.CSGSettings.Save();
                        CSG_EditorGUIUtility.RepaintAll();
                    }
                }
                //if (!isSceneGUI)
                {
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(HeightTooltip);
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                }
                //else
                //{
                //	GUILayout.Space(12);
                //}
                {
                    EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                    {
                        GUILayout.Label(RadiusContent, width65);
                        if (isSceneGUI)
                        {
                            TooltipUtility.SetToolTip(RadiusTooltip);
                        }
                        var radius = generator.RadiusA;
                        EditorGUI.BeginChangeCheck();
                        {
                            if (!isSceneGUI)
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius)));
                            }
                            else
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius), width65));
                            }
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.RadiusA = radius;
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, width20))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
                if (!isSceneGUI)
                {
                    TooltipUtility.SetToolTip(RadiusTooltip);
                }
            }
            GUILayout.EndVertical();

            {
                generator.CircleSides = IntSettingsSlider(generator.CircleSides, 3, RealtimeCSG.CSGSettings.MaxCircleSides, SidesContent, isSceneGUI);
                TooltipUtility.SetToolTip(SidesTooltip);
            }
            {
                generator.CircleOffset = SettingsSlider(generator.CircleOffset, 0, 360, OffsetContent, isSceneGUI);
                TooltipUtility.SetToolTip(OffsetTooltip);
            }



            if (!isSceneGUI)
            {
                GUILayout.Space(5);

                CylinderSettingsGUI(generator, isSceneGUI);

                //GUILayout.Space(10);
            }                     /*else
                                   * {
                                   *    GUILayout.Space(10);
                                   * }*/
                                  /*
                                   * EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                                   * {
                                   *      GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                                   *      {
                                   *              if (GUILayout.Button(CommitContent)) { generator.DoCommit(); }
                                   *              TooltipUtility.SetToolTip(CommitTooltip);
                                   *              if (GUILayout.Button(CancelContent)) { generator.DoCancel(); }
                                   *              TooltipUtility.SetToolTip(CancelTooltip);
                                   *      }
                                   *      GUILayout.EndHorizontal();
                                   * }
                                   * EditorGUI.EndDisabledGroup();
                                   */
            //}
            //GUILayout.EndVertical();
        }
Пример #11
0
        static void BoxSettingsGUI(GeneratorBox generator, bool isSceneGUI)
        {
            var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
            var nextUnit     = Units.CycleToNextUnit(distanceUnit);
            var unitText     = Units.GetUnitGUIContent(distanceUnit);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        GUILayout.Label(HeightContent, Width65);
                        var height = generator.HaveHeight ? generator.Height : GeometryUtility.CleanLength(generator.DefaultHeight);
                        EditorGUI.BeginChangeCheck();
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height)));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (generator.HaveHeight)
                            {
                                generator.Height = height;
                            }
                            else
                            {
                                generator.DefaultHeight = height;
                            }
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, Width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(HeightTooltip);
                }

                EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        GUILayout.Label(LengthContent, Width65);
                        var length = generator.Length;
                        EditorGUI.BeginChangeCheck();
                        {
                            length = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, length)));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.Length = length;
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, Width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(LengthTooltip);
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        GUILayout.Label(WidthContent, Width65);
                        var width = generator.Width;
                        EditorGUI.BeginChangeCheck();
                        {
                            width = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, width)));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.Width = width;
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, Width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(WidthTooltip);
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndVertical();
        }
        static void OnGUIContents(GeneratorSphere generator, bool isSceneGUI)
        {
            var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
            var nextUnit     = Units.CycleToNextUnit(distanceUnit);
            var unitText     = Units.GetUnitGUIContent(distanceUnit);

            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                if (isSceneGUI)
                {
                    SphereSettingsGUI(generator, isSceneGUI);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                    {
                        GUILayout.Label(RadiusContent, width65);

                        if (isSceneGUI)
                        {
                            TooltipUtility.SetToolTip(RadiusTooltip);
                        }

                        var radius = generator.SphereRadius;
                        EditorGUI.BeginChangeCheck();
                        {
                            if (!isSceneGUI)
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius)));
                            }
                            else
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius), width65));
                            }
                        }

                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.SphereRadius = radius;
                        }

                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }

                GUILayout.EndHorizontal();

                if (!isSceneGUI)
                {
                    TooltipUtility.SetToolTip(RadiusTooltip);
                }


                generator.SphereSplits = IntSettingsControl
                                         (
                    generator.SphereSplits,
                    1,
                    RealtimeCSG.CSGSettings.MaxSphereSplits,
                    SplitsContent,
                    isSceneGUI
                                         );

                TooltipUtility.SetToolTip(SplitsTooltip);

                generator.SphereOffset = FloatSettingsControl
                                         (
                    generator.SphereOffset,
                    0,
                    360,
                    OffsetContent,
                    isSceneGUI
                                         );

                TooltipUtility.SetToolTip(OffsetTooltip);
            }

            GUILayout.EndVertical();

            if (!isSceneGUI)
            {
                GUILayout.Space(5);

                SphereSettingsGUI(generator, isSceneGUI);
            }
        }
Пример #13
0
        static void OnGUIContents(bool isSceneGUI, EditModeMeshEdit tool)
        {
            EditModeCommonGUI.StartToolGUI();

            var filteredSelection = EditModeManager.FilteredSelection;

            var defaultMaterial = CSGSettings.DefaultMaterial;

            GUILayout.BeginVertical(isSceneGUI ? InSceneWidth : CSG_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(CSG_GUIStyleUtility.ContentEmpty);
                {
                    if (isSceneGUI)
                    {
                        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();
                    }
                    GUILayout.BeginVertical(CSG_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(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();
                            }
                            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;
        }
Пример #14
0
        static public void OnInspectorGUI(Editor editor, UnityEngine.Object[] targets)
        {
            TooltipUtility.InitToolTip(editor);
            try
            {
                var models = new CSGModel[targets.Length];

                for (int i = targets.Length - 1; i >= 0; i--)
                {
                    models[i] = targets[i] as CSGModel;
                    if (!models[i])
                    {
                        ArrayUtility.RemoveAt(ref models, i);
                    }
                }

                CSG_GUIStyleUtility.InitStyles();
                ShowRealtimeCSGDisabledMessage();

                if (models.Length > 0 && models.Length == targets.Length)
                {
                    CSGModelComponentInspectorGUI.OnInspectorGUI(targets);
                    return;
                }

                var filteredSelection = EditModeManager.FilteredSelection;
                var targetNodes       = filteredSelection.NodeTargets;
                var targetModels      = filteredSelection.ModelTargets;
                var targetBrushes     = filteredSelection.BrushTargets;
                var targetOperations  = filteredSelection.OperationTargets;
                if (targetNodes == null)
                {
                    return;
                }



                bool?isPrefab = false;
                PrefabInstantiateBehaviour?prefabBehaviour            = PrefabInstantiateBehaviour.Reference;
                PrefabSourceAlignment?     prefabSourceAlignment      = PrefabSourceAlignment.AlignedTop;
                PrefabDestinationAlignment?prefabDestinationAlignment = PrefabDestinationAlignment.AlignToSurface;

                if (targetNodes.Length > 0)
                {
                    var gameObject = targetNodes[0].gameObject;
                    isPrefab                   = CSGPrefabUtility.IsPrefabAsset(gameObject);
                    prefabBehaviour            = targetNodes[0].PrefabBehaviour;
                    prefabSourceAlignment      = targetNodes[0].PrefabSourceAlignment;
                    prefabDestinationAlignment = targetNodes[0].PrefabDestinationAlignment;
                    for (int i = 1; i < targetNodes.Length; i++)
                    {
                        gameObject = targetNodes[i].gameObject;

                        var currentIsPrefab                   = CSGPrefabUtility.IsPrefabAsset(gameObject);
                        var currentPrefabBehaviour            = targetNodes[i].PrefabBehaviour;
                        var currentPrefabSourceAlignment      = targetNodes[i].PrefabSourceAlignment;
                        var currentPrefabDestinationAlignment = targetNodes[i].PrefabDestinationAlignment;
                        if (isPrefab.HasValue && isPrefab.Value != currentIsPrefab)
                        {
                            isPrefab = null;
                        }
                        if (prefabBehaviour.HasValue && prefabBehaviour.Value != currentPrefabBehaviour)
                        {
                            prefabBehaviour = null;
                        }
                        if (prefabSourceAlignment.HasValue && prefabSourceAlignment.Value != currentPrefabSourceAlignment)
                        {
                            prefabSourceAlignment = null;
                        }
                        if (prefabDestinationAlignment.HasValue && prefabDestinationAlignment.Value != currentPrefabDestinationAlignment)
                        {
                            prefabDestinationAlignment = null;
                        }
                    }
                }

                GUILayout.BeginVertical(GUI.skin.box);
                {
                    if (isPrefab.HasValue && isPrefab.Value)
                    {
                        EditorGUILayout.LabelField(PrefabLabelContent);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(RaySnappingLabelContent);
                        TooltipUtility.SetToolTip(RaySnappingBehaviourTooltip);
                    }

                    EditorGUI.indentLevel++;
                    {
                        if (isPrefab.HasValue && isPrefab.Value)
                        {
                            EditorGUI.showMixedValue = !prefabBehaviour.HasValue;
                            var prefabBehavour = prefabBehaviour.HasValue ? prefabBehaviour.Value : PrefabInstantiateBehaviour.Reference;
                            EditorGUI.BeginChangeCheck();
                            {
                                prefabBehavour = (PrefabInstantiateBehaviour)EditorGUILayout.EnumPopup(PrefabInstantiateBehaviourContent, prefabBehavour);
                                TooltipUtility.SetToolTip(PrefabInstantiateBehaviourTooltip);
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                                for (int i = 0; i < targetNodes.Length; i++)
                                {
                                    targetNodes[i].PrefabBehaviour = prefabBehavour;
                                }
                            }
                            EditorGUI.showMixedValue = false;
                        }


                        EditorGUI.showMixedValue = !prefabDestinationAlignment.HasValue;
                        var destinationAlignment = prefabDestinationAlignment.HasValue ? prefabDestinationAlignment.Value : PrefabDestinationAlignment.AlignToSurface;
                        EditorGUI.BeginChangeCheck();
                        {
                            destinationAlignment = (PrefabDestinationAlignment)EditorGUILayout.EnumPopup(DestinationAlignmentContent, destinationAlignment);
                            TooltipUtility.SetToolTip(DestinationAlignmentTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            for (int i = 0; i < targetNodes.Length; i++)
                            {
                                targetNodes[i].PrefabDestinationAlignment = destinationAlignment;
                            }
                        }
                        EditorGUI.showMixedValue = false;


                        EditorGUI.showMixedValue = !prefabSourceAlignment.HasValue;
                        var sourceAlignment = prefabSourceAlignment.HasValue ? prefabSourceAlignment.Value : PrefabSourceAlignment.AlignedFront;
                        EditorGUI.BeginChangeCheck();
                        {
                            sourceAlignment = (PrefabSourceAlignment)EditorGUILayout.EnumPopup(SourceAlignmentContent, sourceAlignment);
                            TooltipUtility.SetToolTip(SourceAlignmentTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            for (int i = 0; i < targetNodes.Length; i++)
                            {
                                targetNodes[i].PrefabSourceAlignment = sourceAlignment;
                            }
                        }
                        EditorGUI.showMixedValue = false;
                    }
                    EditorGUI.indentLevel--;
                }
                GUILayout.EndVertical();
                GUILayout.Space(10);


                if (targetModels.Length == 0)
                {
                    int              invalidOperationType = 999;
                    bool?            handleAsOne          = null;
                    bool             selMixedValues       = false;
                    CSGOperationType operationType        = (CSGOperationType)invalidOperationType;
                    bool             opMixedValues        = false;
                    if (targetBrushes.Length > 0)
                    {
                        operationType = targetBrushes[0].OperationType;
                    }
                    for (int b = 1; b < targetBrushes.Length; b++)
                    {
                        var brush = targetBrushes[b];
                        if (operationType != brush.OperationType)
                        {
                            opMixedValues = true;
                        }
                    }
                    foreach (var operation in targetOperations)
                    {
                        if (operationType == (CSGOperationType)invalidOperationType)
                        {
                            operationType = operation.OperationType;
                        }
                        else
                        if (operationType != operation.OperationType)
                        {
                            opMixedValues = true;
                        }

                        if (!handleAsOne.HasValue)
                        {
                            handleAsOne = operation.HandleAsOne;
                        }
                        else
                        if (handleAsOne.Value != operation.HandleAsOne)
                        {
                            selMixedValues = true;
                        }
                    }
                    GUILayout.BeginVertical(GUI.skin.box);
                    {
                        bool passThroughValue = false;
                        if (targetBrushes.Length == 0 && targetOperations.Length > 0)                         // only operations
                        {
                            bool?passThrough = targetOperations[0].PassThrough;
                            for (int i = 1; i < targetOperations.Length; i++)
                            {
                                if (passThrough.HasValue && passThrough.Value != targetOperations[i].PassThrough)
                                {
                                    passThrough = null;
                                    break;
                                }
                            }

                            opMixedValues = !passThrough.HasValue || passThrough.Value;

                            var ptMixedValues = !passThrough.HasValue;
                            passThroughValue = passThrough.HasValue ? passThrough.Value : false;
                            if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues))
                            {
                                Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                                foreach (var operation in targetOperations)
                                {
                                    operation.PassThrough = true;
                                }
                                InternalCSGModelManager.CheckForChanges();
                                EditorApplication.RepaintHierarchyWindow();
                            }

                            if (passThroughValue)
                            {
                                operationType = (CSGOperationType)255;
                            }
                        }
                        EditorGUI.BeginChangeCheck();
                        {
                            operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, opMixedValues);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            foreach (var brush in targetBrushes)
                            {
                                brush.OperationType = operationType;
                            }
                            foreach (var operation in targetOperations)
                            {
                                operation.PassThrough   = false;
                                operation.OperationType = operationType;
                            }
                            InternalCSGModelManager.CheckForChanges();
                            EditorApplication.RepaintHierarchyWindow();
                        }
                    }
                    GUILayout.EndVertical();

                    if (targetOperations.Length == 0 && targetModels.Length == 0)
                    {
                        GUILayout.Space(10);
                        if (targetBrushes.Length == 1)
                        {
                            GUILayout.BeginVertical(GUI.skin.box);
                            {
                                EditorGUI.indentLevel++;
                                OpenSurfaces = EditorGUILayout.Foldout(OpenSurfaces, SurfacesContent);
                                EditorGUI.indentLevel--;
                                if (OpenSurfaces)
                                {
                                    var targetShape     = targetBrushes[0].Shape;
                                    var texGens         = targetShape.TexGens;
                                    var texGenFlagArray = targetShape.TexGenFlags;
                                    for (int t = 0; t < texGens.Length; t++)
                                    {
                                        GUILayout.Space(2);

                                        var texGenFlags = texGenFlagArray[t];
                                        var material    = targetShape.TexGens[t].RenderMaterial;
                                        var physicsMat  = targetShape.TexGens[t].PhysicsMaterial;
                                        EditorGUI.BeginChangeCheck();
                                        {
                                            GUILayout.BeginHorizontal();
                                            {
                                                GUILayout.Space(4);
                                                material = CSG_EditorGUIUtility.MaterialImage(material);
                                                GUILayout.Space(2);
                                                GUILayout.BeginVertical();
                                                {
                                                    //EditorGUI.BeginDisabledGroup(texGenFlags != TexGenFlags.None);
                                                    {
                                                        material = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                                    }
                                                    //EditorGUI.EndDisabledGroup();
                                                    physicsMat = EditorGUILayout.ObjectField(physicsMat, typeof(PhysicMaterial), true) as PhysicMaterial;

                                                    texGenFlags = EditModeCommonGUI.OnSurfaceFlagButtons(texGenFlags);
                                                }
                                                GUILayout.EndVertical();
                                                GUILayout.Space(4);
                                            }
                                            GUILayout.EndHorizontal();
                                        }
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            var selectedBrushSurfaces = new []
                                            {
                                                new SelectedBrushSurface(targetBrushes[0], t)
                                            };
                                            using (new UndoGroup(selectedBrushSurfaces, "discarding surface"))
                                            {
                                                texGenFlagArray[t] = texGenFlags;
                                                targetShape.TexGens[t].RenderMaterial  = material;
                                                targetShape.TexGens[t].PhysicsMaterial = physicsMat;
                                            }
                                        }
                                        GUILayout.Space(4);
                                    }
                                }
                            }
                            GUILayout.EndVertical();
                        }
                    }

                    if (handleAsOne.HasValue)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = selMixedValues;
                            handleAsOne = EditorGUILayout.Toggle(HandleAsOneLabel, handleAsOne.Value);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation 'Handle as one object'");
                            foreach (var operation in targetOperations)
                            {
                                operation.HandleAsOne = handleAsOne.Value;
                            }
                            EditorApplication.RepaintHierarchyWindow();
                        }
                    }
                }

#if false
                if (targetNodes.Length == 1)
                {
                    var node  = targetNodes[0];
                    var brush = node as CSGBrush;
                    if (brush != null)
                    {
                        var brush_cache = CSGSceneManager.GetBrushCache(brush);
                        if (brush_cache == null ||
                            brush_cache.childData == null ||
                            brush_cache.childData.modelTransform == null)
                        {
                            EditorGUILayout.LabelField("brush-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("node-id: " + brush.brushNodeID);
                        }
                    }
                    var operation = node as CSGOperation;
                    if (operation != null)
                    {
                        var operation_cache = CSGSceneManager.GetOperationCache(operation);
                        if (operation_cache == null ||
                            operation_cache.childData == null ||
                            operation_cache.childData.modelTransform == null)
                        {
                            EditorGUILayout.LabelField("operation-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("operation-id: " + operation.operationNodeID);
                        }
                    }
                    var model = node as CSGModel;
                    if (model != null)
                    {
                        var model_cache = CSGSceneManager.GetModelCache(model);
                        if (model_cache == null ||
                            model_cache.meshContainer == null)
                        {
                            EditorGUILayout.LabelField("model-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("model-id: " + model.modelNodeID);
                        }
                    }
                }
#endif
            }
            finally
            {
                TooltipUtility.DrawToolTip(getLastRect: true, goUp: true);
            }
        }
Пример #15
0
        static void ShowCSGOperations(bool isSceneGUI, EditModePlace tool, FilteredSelection filteredSelection)
        {
            bool operations_enabled = (tool != null &&
                                       filteredSelection.NodeTargets.Length > 0 &&
                                       filteredSelection.NodeTargets.Length == (filteredSelection.BrushTargets.Length + filteredSelection.OperationTargets.Length));

            EditorGUI.BeginDisabledGroup(!operations_enabled);
            {
                bool             mixedValues   = tool == null || ((filteredSelection.BrushTargets.Length == 0) && (filteredSelection.OperationTargets.Length == 0));
                CSGOperationType operationType = CSGOperationType.Additive;
                if (tool != null)
                {
                    if (filteredSelection.BrushTargets.Length > 0)
                    {
                        operationType = filteredSelection.BrushTargets[0].OperationType;
                        for (int i = 1; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            if (filteredSelection.BrushTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                    else
                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        operationType = filteredSelection.OperationTargets[0].OperationType;
                    }

                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (filteredSelection.OperationTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                }

                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    bool passThroughValue = false;
                    if (tool != null &&
                        filteredSelection.BrushTargets.Length == 0 &&
                        filteredSelection.OperationTargets.Length > 0 &&
                        filteredSelection.OperationTargets.Length == filteredSelection.NodeTargets.Length)                         // only operations
                    {
                        bool?passThrough = filteredSelection.OperationTargets[0].PassThrough;
                        for (int i = 1; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (passThrough.HasValue && passThrough.Value != filteredSelection.OperationTargets[i].PassThrough)
                            {
                                passThrough = null;
                                break;
                            }
                        }

                        mixedValues = !passThrough.HasValue || passThrough.Value;

                        var ptMixedValues = !passThrough.HasValue;
                        passThroughValue = passThrough.HasValue ? passThrough.Value : false;
                        if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues))
                        {
                            Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes");
                            foreach (var operation in filteredSelection.OperationTargets)
                            {
                                operation.PassThrough = true;
                            }
                            InternalCSGModelManager.CheckForChanges();
                            EditorApplication.RepaintHierarchyWindow();
                        }

                        if (passThroughValue)
                        {
                            operationType = (CSGOperationType)255;
                        }
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, mixedValues);
                    }
                    if (EditorGUI.EndChangeCheck() && tool != null)
                    {
                        Undo.RecordObjects(filteredSelection.NodeTargets, "Changed CSG operation of nodes");
                        for (int i = 0; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            filteredSelection.BrushTargets[i].OperationType = operationType;
                        }
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            filteredSelection.OperationTargets[i].PassThrough   = false;
                            filteredSelection.OperationTargets[i].OperationType = operationType;
                        }
                        InternalCSGModelManager.CheckForChanges();
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
        static void FreeDrawSettingsGUI(GeneratorFreeDraw generator, bool isSceneGUI)
        {
            var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
            var nextUnit     = Units.CycleToNextUnit(distanceUnit);
            var unitText     = Units.GetUnitGUIContent(distanceUnit);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        GUILayout.Label(HeightContent, width65);
                        var height = generator.HaveHeight ? generator.Height : GeometryUtility.CleanLength(generator.DefaultHeight);
                        EditorGUI.BeginChangeCheck();
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height)));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (generator.HaveHeight)
                            {
                                generator.Height = height;
                            }
                            else
                            {
                                generator.DefaultHeight = height;
                            }
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, width20))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.UpdateSceneViews();
                        }
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(HeightTooltip);
                }
#if EVALUATION
                EditorGUI.BeginDisabledGroup(true);
#endif
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        GUILayout.Label(CurveSidesContent, width65);
                        var subdivisions = generator.CurveSides;
                        EditorGUI.BeginChangeCheck();
                        {
                            subdivisions = (uint)Mathf.Clamp(EditorGUILayout.IntField((int)subdivisions), 0, 32);
                        }
                        if (EditorGUI.EndChangeCheck() && generator.CurveSides != subdivisions)
                        {
                            generator.CurveSides = subdivisions;
                        }
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(CurveSidesTooltip);
                }
                {
                    GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUI.BeginDisabledGroup(!generator.HaveSelectedEdgesOrVertices);
                        {
                            var tangentState = generator.SelectedTangentState;
                            EditorGUI.BeginChangeCheck();
                            {
                                GUILayout.Label(EdgeTypeContent, width65);
                                EditorGUI.showMixedValue = !tangentState.HasValue;
                                tangentState             = (HandleConstraints)EditorGUILayout.EnumPopup(tangentState.HasValue ? tangentState.Value : HandleConstraints.Straight);
                                EditorGUI.showMixedValue = false;
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                generator.SelectedTangentState = tangentState;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndHorizontal();
                    TooltipUtility.SetToolTip(EdgeTypeTooltip);
                }
                EditorGUILayout.Space();
#if EVALUATION
                EditorGUI.EndDisabledGroup();
#endif

                EditorGUI.BeginDisabledGroup(!generator.HaveSelectedEdges);
                {
                    if (GUILayout.Button(SplitSelectedContent))
                    {
                        generator.SplitSelectedEdge();
                    }
                    TooltipUtility.SetToolTip(SplitSelectedTooltip);
                }
                EditorGUI.EndDisabledGroup();

                /*
                 * GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                 * {
                 *      if (isSceneGUI)
                 *              GUILayout.Label(AlphaContent, width75);
                 *      else
                 *              EditorGUILayout.PrefixLabel(AlphaContent);
                 *      var alpha = generator.Alpha;
                 *      EditorGUI.BeginChangeCheck();
                 *      {
                 *              alpha = EditorGUILayout.Slider(alpha, -1.0f, 3.0f);
                 *      }
                 *      if (EditorGUI.EndChangeCheck() && generator.Alpha != alpha)
                 *      {
                 *              generator.Alpha = alpha;
                 *      }
                 * }
                 * GUILayout.EndHorizontal();
                 */
            }
            GUILayout.EndVertical();
        }
Пример #17
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();
        }
Пример #18
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;
        }
        static void OnBottomBarGUI(SceneView sceneView, Rect barSize)
        {
            //if (Event.current.type == EventType.Layout)
            //	return;

            var  snapMode          = RealtimeCSG.CSGSettings.SnapMode;
            var  uniformGrid       = RealtimeCSG.CSGSettings.UniformGrid;
            var  moveSnapVector    = RealtimeCSG.CSGSettings.SnapVector;
            var  rotationSnap      = RealtimeCSG.CSGSettings.SnapRotation;
            var  scaleSnap         = RealtimeCSG.CSGSettings.SnapScale;
            var  showGrid          = RealtimeCSG.CSGSettings.GridVisible;
            var  lockAxisX         = RealtimeCSG.CSGSettings.LockAxisX;
            var  lockAxisY         = RealtimeCSG.CSGSettings.LockAxisY;
            var  lockAxisZ         = RealtimeCSG.CSGSettings.LockAxisZ;
            var  distanceUnit      = RealtimeCSG.CSGSettings.DistanceUnit;
            var  helperSurfaces    = RealtimeCSG.CSGSettings.VisibleHelperSurfaces;
            var  showWireframe     = RealtimeCSG.CSGSettings.IsWireframeShown(sceneView);
            var  skin              = CSG_GUIStyleUtility.Skin;
            var  updateSurfaces    = false;
            bool wireframeModified = false;

            var viewWidth = sceneView.position.width;

            float layoutHeight = barSize.height;
            float layoutX      = 6.0f;

            bool modified = false;

            GUI.changed = false;
            {
                currentRect.width  = 27;
                currentRect.y      = 0;
                currentRect.height = layoutHeight - currentRect.y;
                currentRect.y     += barSize.y;
                currentRect.x      = layoutX;
                layoutX           += currentRect.width;

                #region "Grid" button
                if (showGrid)
                {
                    showGrid = GUI.Toggle(currentRect, showGrid, skin.gridIconOn, EditorStyles.toolbarButton);
                }
                else
                {
                    showGrid = GUI.Toggle(currentRect, showGrid, skin.gridIcon, EditorStyles.toolbarButton);
                }
                //(x:6.00, y:0.00, width:27.00, height:18.00)
                TooltipUtility.SetToolTip(showGridTooltip, currentRect);
                #endregion

                if (viewWidth >= 800)
                {
                    layoutX += 6;                     //(x:33.00, y:0.00, width:6.00, height:6.00)
                }
                var prevBackgroundColor   = GUI.backgroundColor;
                var lockedBackgroundColor = skin.lockedBackgroundColor;
                if (lockAxisX)
                {
                    GUI.backgroundColor = lockedBackgroundColor;
                }

                #region "X" lock button
                currentRect.width  = 17;
                currentRect.y      = 0;
                currentRect.height = layoutHeight - currentRect.y;
                currentRect.y     += barSize.y;
                currentRect.x      = layoutX;
                layoutX           += currentRect.width;

                lockAxisX = !GUI.Toggle(currentRect, !lockAxisX, xLabel, skin.xToolbarButton);
                //(x:39.00, y:0.00, width:17.00, height:18.00)
                if (lockAxisX)
                {
                    TooltipUtility.SetToolTip(xTooltipOn, currentRect);
                }
                else
                {
                    TooltipUtility.SetToolTip(xTooltipOff, currentRect);
                }
                GUI.backgroundColor = prevBackgroundColor;
                #endregion

                #region "Y" lock button
                currentRect.x = layoutX;
                layoutX      += currentRect.width;

                if (lockAxisY)
                {
                    GUI.backgroundColor = lockedBackgroundColor;
                }
                lockAxisY = !GUI.Toggle(currentRect, !lockAxisY, yLabel, skin.yToolbarButton);
                //(x:56.00, y:0.00, width:17.00, height:18.00)
                if (lockAxisY)
                {
                    TooltipUtility.SetToolTip(yTooltipOn, currentRect);
                }
                else
                {
                    TooltipUtility.SetToolTip(yTooltipOff, currentRect);
                }
                GUI.backgroundColor = prevBackgroundColor;
                #endregion

                #region "Z" lock button
                currentRect.x = layoutX;
                layoutX      += currentRect.width;

                if (lockAxisZ)
                {
                    GUI.backgroundColor = lockedBackgroundColor;
                }
                lockAxisZ = !GUI.Toggle(currentRect, !lockAxisZ, zLabel, skin.zToolbarButton);
                //(x:56.00, y:0.00, width:17.00, height:18.00)
                if (lockAxisZ)
                {
                    TooltipUtility.SetToolTip(zTooltipOn, currentRect);
                }
                else
                {
                    TooltipUtility.SetToolTip(zTooltipOff, currentRect);
                }
                GUI.backgroundColor = prevBackgroundColor;
                #endregion
            }
            modified = GUI.changed || modified;

            if (viewWidth >= 800)
            {
                layoutX += 6;                 // (x:91.00, y:0.00, width:6.00, height:6.00)
            }
            #region "SnapMode" button
            GUI.changed = false;
            {
                currentRect.width  = 27;
                currentRect.y      = 0;
                currentRect.height = layoutHeight - currentRect.y;
                currentRect.y     += barSize.y;
                currentRect.x      = layoutX;
                layoutX           += currentRect.width;


                switch (snapMode)
                {
                case SnapMode.GridSnapping:
                {
                    var newValue = GUI.Toggle(currentRect, snapMode == SnapMode.GridSnapping, CSG_GUIStyleUtility.Skin.gridSnapIconOn, EditorStyles.toolbarButton);
                    if (GUI.changed)
                    {
                        snapMode = newValue ? SnapMode.GridSnapping : SnapMode.RelativeSnapping;
                    }
                    //(x:97.00, y:0.00, width:27.00, height:18.00)
                    TooltipUtility.SetToolTip(gridSnapModeTooltip, currentRect);
                    break;
                }

                case SnapMode.RelativeSnapping:
                {
                    var newValue = GUI.Toggle(currentRect, snapMode == SnapMode.RelativeSnapping, CSG_GUIStyleUtility.Skin.relSnapIconOn, EditorStyles.toolbarButton);
                    if (GUI.changed)
                    {
                        snapMode = newValue ? SnapMode.RelativeSnapping : SnapMode.None;
                    }
                    //(x:97.00, y:0.00, width:27.00, height:18.00)
                    TooltipUtility.SetToolTip(relativeSnapModeTooltip, currentRect);
                    break;
                }

                default:
                case SnapMode.None:
                {
                    var newValue = GUI.Toggle(currentRect, snapMode != SnapMode.None, CSG_GUIStyleUtility.Skin.noSnapIconOn, EditorStyles.toolbarButton);
                    if (GUI.changed)
                    {
                        snapMode = newValue ? SnapMode.GridSnapping : SnapMode.None;
                    }
                    //(x:97.00, y:0.00, width:27.00, height:18.00)
                    TooltipUtility.SetToolTip(noSnappingModeTooltip, currentRect);
                    break;
                }
                }
            }
            modified = GUI.changed || modified;
            #endregion

            if (viewWidth >= 460)
            {
                if (snapMode != SnapMode.None)
                {
                    #region "Position" label
                    if (viewWidth >= 500)
                    {
                        if (viewWidth >= 865)
                        {
                            currentRect.width  = 44;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            uniformGrid = GUI.Toggle(currentRect, uniformGrid, positionLargeLabel, miniTextStyle);
                            //(x:128.00, y:2.00, width:44.00, height:16.00)

                            TooltipUtility.SetToolTip(positionTooltip, currentRect);
                        }
                        else
                        {
                            currentRect.width  = 22;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            uniformGrid = GUI.Toggle(currentRect, uniformGrid, positionSmallLabel, miniTextStyle);
                            //(x:127.00, y:2.00, width:22.00, height:16.00)

                            TooltipUtility.SetToolTip(positionTooltip, currentRect);
                        }
                    }
                    #endregion

                    layoutX += 2;

                    #region "Position" field
                    if (uniformGrid || viewWidth < 515)
                    {
                        EditorGUI.showMixedValue = !(moveSnapVector.x == moveSnapVector.y && moveSnapVector.x == moveSnapVector.z);
                        GUI.changed = false;
                        {
                            currentRect.width  = 70;
                            currentRect.y      = 3;
                            currentRect.height = layoutHeight - (currentRect.y - 1);
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle));                            //, MinSnapWidth, MaxSnapWidth));
                            //(x:176.00, y:3.00, width:70.00, height:16.00)
                        }
                        if (GUI.changed)
                        {
                            modified         = true;
                            moveSnapVector.y = moveSnapVector.x;
                            moveSnapVector.z = moveSnapVector.x;
                        }
                        EditorGUI.showMixedValue = false;
                    }
                    else
                    {
                        GUI.changed = false;
                        {
                            currentRect.width  = 70;
                            currentRect.y      = 3;
                            currentRect.height = layoutHeight - (currentRect.y - 1);
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;
                            layoutX++;

                            moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle));                            //, MinSnapWidth, MaxSnapWidth));
                            //(x:175.00, y:3.00, width:70.00, height:16.00)


                            currentRect.x = layoutX;
                            layoutX      += currentRect.width;
                            layoutX++;

                            moveSnapVector.y = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.y), textInputStyle));                            //, MinSnapWidth, MaxSnapWidth));
                            //(x:247.00, y:3.00, width:70.00, height:16.00)


                            currentRect.x = layoutX;
                            layoutX      += currentRect.width;

                            moveSnapVector.z = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.z), textInputStyle));                            //, MinSnapWidth, MaxSnapWidth));
                            //(x:319.00, y:3.00, width:70.00, height:16.00)
                        }
                        modified = GUI.changed || modified;
                    }
                    #endregion

                    layoutX++;

                    #region "Position" Unit
                    DistanceUnit nextUnit = Units.CycleToNextUnit(distanceUnit);
                    GUIContent   unitText = Units.GetUnitGUIContent(distanceUnit);

                    currentRect.width  = 22;
                    currentRect.y      = 2;
                    currentRect.height = layoutHeight - currentRect.y;
                    currentRect.y     += barSize.y;
                    currentRect.x      = layoutX;
                    layoutX           += currentRect.width;

                    if (GUI.Button(currentRect, unitText, miniTextStyle))                    //(x:393.00, y:2.00, width:13.00, height:16.00)
                    {
                        distanceUnit = nextUnit;
                        modified     = true;
                    }
                    #endregion

                    layoutX += 2;

                    #region "Position" +/-
                    if (viewWidth >= 700)
                    {
                        currentRect.width  = 19;
                        currentRect.y      = 2;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, positionPlusLabel, EditorStyles.miniButtonLeft))
                        {
                            GridUtility.DoubleGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector;
                        }
                        //(x:410.00, y:2.00, width:19.00, height:15.00)
                        TooltipUtility.SetToolTip(positionPlusTooltip, currentRect);

                        currentRect.width  = 17;
                        currentRect.y      = 2;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, positionMinusLabel, EditorStyles.miniButtonRight))
                        {
                            GridUtility.HalfGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector;
                        }
                        //(x:429.00, y:2.00, width:17.00, height:15.00)
                        TooltipUtility.SetToolTip(positionMinnusTooltip, currentRect);
                    }
                    #endregion

                    layoutX += 2;

                    #region "Angle" label
                    if (viewWidth >= 750)
                    {
                        if (viewWidth >= 865)
                        {
                            currentRect.width  = 31;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            GUI.Label(currentRect, angleLargeLabel, miniTextStyle);
                            //(x:450.00, y:2.00, width:31.00, height:16.00)
                        }
                        else
                        {
                            currentRect.width  = 22;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            GUI.Label(currentRect, angleSmallLabel, miniTextStyle);
                            //(x:355.00, y:2.00, width:22.00, height:16.00)
                        }
                        TooltipUtility.SetToolTip(angleTooltip, currentRect);
                    }
                    #endregion

                    layoutX += 2;

                    #region "Angle" field
                    GUI.changed = false;
                    {
                        currentRect.width  = 70;
                        currentRect.y      = 3;
                        currentRect.height = layoutHeight - (currentRect.y - 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        rotationSnap = EditorGUI.FloatField(currentRect, rotationSnap, textInputStyle);                        //, MinSnapWidth, MaxSnapWidth);
                        //(x:486.00, y:3.00, width:70.00, height:16.00)
                        if (viewWidth <= 750)
                        {
                            TooltipUtility.SetToolTip(angleTooltip, currentRect);
                        }
                    }
                    modified = GUI.changed || modified;
                    #endregion

                    layoutX++;

                    #region "Angle" Unit
                    if (viewWidth >= 370)
                    {
                        currentRect.width  = 14;
                        currentRect.y      = 1;
                        currentRect.height = layoutHeight - currentRect.y;
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        GUI.Label(currentRect, angleUnitLabel, miniTextStyle);
                    }
                    #endregion

                    layoutX += 2;

                    #region "Angle" +/-
                    if (viewWidth >= 700)
                    {
                        currentRect.width  = 19;
                        currentRect.y      = 1;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, anglePlusLabel, EditorStyles.miniButtonLeft))
                        {
                            rotationSnap *= 2.0f; modified = true;
                        }
                        //(x:573.00, y:2.00, width:19.00, height:15.00)
                        TooltipUtility.SetToolTip(anglePlusTooltip, currentRect);


                        currentRect.width  = 17;
                        currentRect.y      = 1;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, angleMinusLabel, EditorStyles.miniButtonRight))
                        {
                            rotationSnap /= 2.0f; modified = true;
                        }
                        //(x:592.00, y:2.00, width:17.00, height:15.00)
                        TooltipUtility.SetToolTip(angleMinnusTooltip, currentRect);
                    }
                    #endregion

                    layoutX += 2;

                    #region "Scale" label
                    if (viewWidth >= 750)
                    {
                        if (viewWidth >= 865)
                        {
                            currentRect.width  = 31;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            GUI.Label(currentRect, scaleLargeLabel, miniTextStyle);
                            //(x:613.00, y:2.00, width:31.00, height:16.00)
                        }
                        else
                        {
                            currentRect.width  = 19;
                            currentRect.y      = 1;
                            currentRect.height = layoutHeight - currentRect.y;
                            currentRect.y     += barSize.y;
                            currentRect.x      = layoutX;
                            layoutX           += currentRect.width;

                            GUI.Label(currentRect, scaleSmallLabel, miniTextStyle);
                            //(x:495.00, y:2.00, width:19.00, height:16.00)
                        }
                        TooltipUtility.SetToolTip(scaleTooltip, currentRect);
                    }
                    #endregion

                    layoutX += 2;

                    #region "Scale" field
                    GUI.changed = false;
                    {
                        currentRect.width  = 70;
                        currentRect.y      = 3;
                        currentRect.height = layoutHeight - (currentRect.y - 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        scaleSnap = EditorGUI.FloatField(currentRect, scaleSnap, textInputStyle);                        //, MinSnapWidth, MaxSnapWidth);
                        //(x:648.00, y:3.00, width:70.00, height:16.00)
                        if (viewWidth <= 750)
                        {
                            TooltipUtility.SetToolTip(scaleTooltip, currentRect);
                        }
                    }
                    modified = GUI.changed || modified;
                    #endregion

                    layoutX++;

                    #region "Scale" Unit
                    if (viewWidth >= 370)
                    {
                        currentRect.width  = 15;
                        currentRect.y      = 1;
                        currentRect.height = layoutHeight - currentRect.y;
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        GUI.Label(currentRect, scaleUnitLabel, miniTextStyle);
                        //(x:722.00, y:2.00, width:15.00, height:16.00)
                    }
                    #endregion

                    layoutX += 2;

                    #region "Scale" +/-
                    if (viewWidth >= 700)
                    {
                        currentRect.width  = 19;
                        currentRect.y      = 2;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, scalePlusLabel, EditorStyles.miniButtonLeft))
                        {
                            scaleSnap *= 10.0f; modified = true;
                        }
                        //(x:741.00, y:2.00, width:19.00, height:15.00)
                        TooltipUtility.SetToolTip(scalePlusTooltip, currentRect);


                        currentRect.width  = 17;
                        currentRect.y      = 2;
                        currentRect.height = layoutHeight - (currentRect.y + 1);
                        currentRect.y     += barSize.y;
                        currentRect.x      = layoutX;
                        layoutX           += currentRect.width;

                        if (GUI.Button(currentRect, scaleMinusLabel, EditorStyles.miniButtonRight))
                        {
                            scaleSnap /= 10.0f; modified = true;
                        }
                        //(x:760.00, y:2.00, width:17.00, height:15.00)
                        TooltipUtility.SetToolTip(scaleMinnusTooltip, currentRect);
                    }
                    #endregion
                }
            }


            var prevLayoutX = layoutX;

            layoutX = viewWidth;


            #region "Rebuild"
            currentRect.width  = 27;
            currentRect.y      = 0;
            currentRect.height = layoutHeight - currentRect.y;
            currentRect.y     += barSize.y;
            layoutX           -= currentRect.width;
            currentRect.x      = layoutX;

            if (GUI.Button(currentRect, CSG_GUIStyleUtility.Skin.rebuildIcon, EditorStyles.toolbarButton))
            {
                Debug.Log("Starting complete rebuild");

                var text = new System.Text.StringBuilder();

                MaterialUtility.ResetMaterialTypeLookup();

                InternalCSGModelManager.skipCheckForChanges = true;
                RealtimeCSG.CSGSettings.Reload();
                UnityCompilerDefineManager.UpdateUnityDefines();

                InternalCSGModelManager.registerTime          = 0.0;
                InternalCSGModelManager.validateTime          = 0.0;
                InternalCSGModelManager.hierarchyValidateTime = 0.0;
                InternalCSGModelManager.updateHierarchyTime   = 0.0;

                var startTime = EditorApplication.timeSinceStartup;
                InternalCSGModelManager.ForceRebuildAll();
                InternalCSGModelManager.OnHierarchyModified();
                var hierarchy_update_endTime = EditorApplication.timeSinceStartup;
                text.AppendFormat(CultureInfo.InvariantCulture, "Full hierarchy rebuild in {0:F} ms. ", (hierarchy_update_endTime - startTime) * 1000);


                NativeMethodBindings.RebuildAll();
                var csg_endTime = EditorApplication.timeSinceStartup;
                text.AppendFormat(CultureInfo.InvariantCulture, "Full CSG rebuild done in {0:F} ms. ", (csg_endTime - hierarchy_update_endTime) * 1000);

                InternalCSGModelManager.RemoveForcedUpdates();                 // we already did this in rebuild all
                InternalCSGModelManager.UpdateMeshes(text, forceUpdate: true);

                updateSurfaces = true;
                UpdateLoop.ResetUpdateRoutine();
                RealtimeCSG.CSGSettings.Save();
                InternalCSGModelManager.skipCheckForChanges = false;

                var scenes = new HashSet <UnityEngine.SceneManagement.Scene>();
                foreach (var model in InternalCSGModelManager.Models)
                {
                    scenes.Add(model.gameObject.scene);
                }

                text.AppendFormat(CultureInfo.InvariantCulture, "{0} brushes. ", Foundation.CSGManager.TreeBrushCount);

                Debug.Log(text.ToString());
            }
            //(x:1442.00, y:0.00, width:27.00, height:18.00)
            TooltipUtility.SetToolTip(rebuildTooltip, currentRect);
            #endregion

            if (viewWidth >= 800)
            {
                layoutX -= 6;                 //(x:1436.00, y:0.00, width:6.00, height:6.00)
            }
            #region "Helper Surface Flags" Mask
            if (viewWidth >= 250)
            {
                GUI.changed = false;
                {
                    prevLayoutX += 8;                      // extra space
                    prevLayoutX += 26;                     // width of "Show wireframe" button

                    currentRect.width = Mathf.Max(20, Mathf.Min(165, (viewWidth - prevLayoutX - currentRect.width)));

                    currentRect.y      = 0;
                    currentRect.height = layoutHeight - currentRect.y;
                    currentRect.y     += barSize.y;
                    layoutX           -= currentRect.width;
                    currentRect.x      = layoutX;

                    SurfaceVisibilityPopup.Button(sceneView, currentRect);

                    //(x:1267.00, y:2.00, width:165.00, height:16.00)
                    TooltipUtility.SetToolTip(helperSurfacesTooltip, currentRect);
                }
                if (GUI.changed)
                {
                    updateSurfaces = true;
                    modified       = true;
                }
            }
            #endregion

            #region "Show wireframe" button
            GUI.changed        = false;
            currentRect.width  = 26;
            currentRect.y      = 0;
            currentRect.height = layoutHeight - currentRect.y;
            currentRect.y     += barSize.y;
            layoutX           -= currentRect.width;
            currentRect.x      = layoutX;

            if (showWireframe)
            {
                showWireframe = GUI.Toggle(currentRect, showWireframe, CSG_GUIStyleUtility.Skin.wireframe, EditorStyles.toolbarButton);
                //(x:1237.00, y:0.00, width:26.00, height:18.00)
            }
            else
            {
                showWireframe = GUI.Toggle(currentRect, showWireframe, CSG_GUIStyleUtility.Skin.wireframeOn, EditorStyles.toolbarButton);
                //(x:1237.00, y:0.00, width:26.00, height:18.00)
            }
            TooltipUtility.SetToolTip(showWireframeTooltip, currentRect);
            if (GUI.changed)
            {
                wireframeModified = true;
                modified          = true;
            }
            #endregion



            #region Capture mouse clicks in empty space
            var mousePoint = Event.current.mousePosition;
            int controlID  = GUIUtility.GetControlID(BottomBarEditorOverlayHash, FocusType.Passive, barSize);
            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:       { if (barSize.Contains(mousePoint))
                                              {
                                                  GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; Event.current.Use();
                                              }
                                              break; }

            case EventType.MouseMove:       { if (barSize.Contains(mousePoint))
                                              {
                                                  Event.current.Use();
                                              }
                                              break; }

            case EventType.MouseUp:         { if (GUIUtility.hotControl == controlID)
                                              {
                                                  GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Event.current.Use();
                                              }
                                              break; }

            case EventType.MouseDrag:       { if (GUIUtility.hotControl == controlID)
                                              {
                                                  Event.current.Use();
                                              }
                                              break; }

            case EventType.ScrollWheel: { if (barSize.Contains(mousePoint))
                                          {
                                              Event.current.Use();
                                          }
                                          break; }
            }
            #endregion



            #region Store modified values
            rotationSnap     = Mathf.Max(1.0f, Mathf.Abs((360 + (rotationSnap % 360))) % 360);
            moveSnapVector.x = Mathf.Max(1.0f / 1024.0f, moveSnapVector.x);
            moveSnapVector.y = Mathf.Max(1.0f / 1024.0f, moveSnapVector.y);
            moveSnapVector.z = Mathf.Max(1.0f / 1024.0f, moveSnapVector.z);

            scaleSnap = Mathf.Max(MathConstants.MinimumScale, scaleSnap);

            RealtimeCSG.CSGSettings.SnapMode     = snapMode;
            RealtimeCSG.CSGSettings.SnapVector   = moveSnapVector;
            RealtimeCSG.CSGSettings.SnapRotation = rotationSnap;
            RealtimeCSG.CSGSettings.SnapScale    = scaleSnap;
            RealtimeCSG.CSGSettings.UniformGrid  = uniformGrid;
//			RealtimeCSG.Settings.SnapVertex					= vertexSnap;
            RealtimeCSG.CSGSettings.GridVisible           = showGrid;
            RealtimeCSG.CSGSettings.LockAxisX             = lockAxisX;
            RealtimeCSG.CSGSettings.LockAxisY             = lockAxisY;
            RealtimeCSG.CSGSettings.LockAxisZ             = lockAxisZ;
            RealtimeCSG.CSGSettings.DistanceUnit          = distanceUnit;
            RealtimeCSG.CSGSettings.VisibleHelperSurfaces = helperSurfaces;

            if (wireframeModified)
            {
                RealtimeCSG.CSGSettings.SetWireframeShown(sceneView, showWireframe);
            }

            if (updateSurfaces)
            {
                MeshInstanceManager.UpdateHelperSurfaceVisibility(force: true);
            }

            if (modified)
            {
                GUI.changed = true;
                RealtimeCSG.CSGSettings.UpdateSnapSettings();
                RealtimeCSG.CSGSettings.Save();
                CSG_EditorGUIUtility.RepaintAll();
            }
            #endregion
        }
Пример #20
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();
            }
        }
Пример #21
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();
                }
            }
        }
        static void OnGUIContents(GeneratorSphere generator, bool isSceneGUI)
        {
            var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
            var nextUnit     = Units.CycleToNextUnit(distanceUnit);
            var unitText     = Units.GetUnitGUIContent(distanceUnit);

            //GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
            //{
            //bool enabled = generator.HaveBrushes;
            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                /*
                 * EditorGUI.BeginDisabledGroup(!enabled);
                 * {
                 *      if (isSceneGUI)
                 *              GUILayout.BeginVertical(GUI.skin.box, width100);
                 *      else
                 *              GUILayout.BeginVertical(GUIStyle.none);
                 *      {
                 *              bool mixedValues = !enabled;
                 *              CSGOperationType operation = generator.CurrentCSGOperationType;
                 *              EditorGUI.BeginChangeCheck();
                 *              operation = CSG_EditorGUIUtility.ChooseOperation(operation, mixedValues);
                 *              if (EditorGUI.EndChangeCheck())
                 *              {
                 *                      generator.CurrentCSGOperationType = operation;
                 *              }
                 *      }
                 *      GUILayout.EndVertical();
                 * }
                 * EditorGUI.EndDisabledGroup();
                 */
                if (isSceneGUI)
                {
                    SphereSettingsGUI(generator, isSceneGUI);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                    {
                        GUILayout.Label(RadiusContent, width65);
                        if (isSceneGUI)
                        {
                            TooltipUtility.SetToolTip(RadiusTooltip);
                        }
                        var radius = generator.SphereRadius;
                        EditorGUI.BeginChangeCheck();
                        {
                            if (!isSceneGUI)
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius)));
                            }
                            else
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius), width65));
                            }
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.SphereRadius = radius;
                        }
                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.UpdateSceneViews();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
                if (!isSceneGUI)
                {
                    TooltipUtility.SetToolTip(RadiusTooltip);
                }

                {
                    generator.SphereSplits = IntSettingsSlider(generator.SphereSplits, 1, RealtimeCSG.CSGSettings.MaxSphereSplits, SplitsContent, isSceneGUI);
                    TooltipUtility.SetToolTip(SplitsTooltip);
                }
                {
                    generator.SphereOffset = SettingsSlider(generator.SphereOffset, 0, 360, OffsetContent, isSceneGUI);
                    TooltipUtility.SetToolTip(OffsetTooltip);
                }
            }
            GUILayout.EndVertical();

            if (!isSceneGUI)
            {
                GUILayout.Space(5);

                SphereSettingsGUI(generator, isSceneGUI);

                //GUILayout.Space(10);
            }                    /* else
                                  * {
                                  *     GUILayout.Space(10);
                                  * }*/
                                 /*
                                  * EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                                  * {
                                  *      GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                                  *      {
                                  *              if (GUILayout.Button(CommitContent)) { generator.DoCommit(); }
                                  *              TooltipUtility.SetToolTip(CommitTooltip);
                                  *              if (GUILayout.Button(CancelContent)) { generator.DoCancel(); }
                                  *              TooltipUtility.SetToolTip(CancelTooltip);
                                  *      }
                                  *      GUILayout.EndHorizontal();
                                  * }
                                  * EditorGUI.EndDisabledGroup();
                                  */
            //}
            //GUILayout.EndVertical();
        }
Пример #23
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.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 (!IgnoreDepthForRayCasts(sceneView) && !havePlane &&
                        SceneQueryUtility.FindWorldIntersection(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(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.RayIntersection(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.RayIntersection(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)
                {
                    if (vertexOnBrush.ChildData != null && vertexOnBrush.ChildData.Model)
                    {
                        geometryModel = vertexOnBrush.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)
                    {
                        CSG_EditorGUIUtility.UpdateSceneViews();
                    }
                }

                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();
                        CSG_EditorGUIUtility.UpdateSceneViews();
                        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;
            }
            }
        }
        internal static void OnHandleDragAndDrop(bool inSceneView, Transform transformInInspector = null, Rect?selectionRect = null)
        {
            switch (Event.current.type)
            {
            case EventType.DragUpdated:
            {
                if (!draggingInScene)
                {
                    ValidateDrop(inSceneView, transformInInspector);
                }

                if (currentDragTool != null)
                {
                    if (!currentDragTool.ValidateDropPoint(inSceneView))
                    {
                        if (currentDragTool != null && currentDragToolActive)
                        {
                            currentDragTool.DragExited(inSceneView);
                        }
                        currentDragToolActive = false;
                    }
                    else
                    {
                        currentDragToolActive   = true;
                        IsDraggingObjectInScene = true;
                        DragAndDrop.visualMode  = DragAndDropVisualMode.Generic;
                        if (inSceneView)
                        {
                            if (currentDragTool.DragUpdated())
                            {
                                HandleUtility.Repaint();
                            }
                        }
                        else
                        {
                            if (currentDragTool.DragUpdated(transformInInspector, selectionRect.Value))
                            {
                                CSG_EditorGUIUtility.RepaintAll();
                            }
                        }
                        Event.current.Use();
                        draggingInScene = true;
                    }
                }
                break;
            }

            case EventType.DragPerform:
            {
                if (currentDragTool != null)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                    if (currentDragToolActive)
                    {
                        currentDragTool.DragPerform(inSceneView);
                        currentDragTool.Reset();
                        Event.current.Use();
                    }
                    currentDragTool             = null;
                    currentTransformInInspector = null;
                    draggingInScene             = false;
                }
                break;
            }

            case EventType.DragExited:
                //case EventType.MouseMove:
            {
                if (currentDragTool != null)
                {
                    currentDragTool.DragExited(inSceneView);
                    Event.current.Use();
                    IsDraggingObjectInScene     = false;
                    currentDragTool             = null;
                    currentTransformInInspector = null;
                    draggingInScene             = false;
                    CSG_EditorGUIUtility.RepaintAll();
                }
                break;
            }
            }
        }
Пример #25
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;
				}
			}
		}
Пример #26
0
        static void OnEditModeSelectionSceneGUI()
        {
            CSG_GUIStyleUtility.InitStyles();
            if (CSG_GUIStyleUtility.brushEditModeNames == null ||
                CSG_GUIStyleUtility.brushEditModeNames.Length == 0)
            {
                return;
            }

            var oldSkin = GUI.skin;

            CSG_GUIStyleUtility.SetDefaultGUISkin();
            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                GUIStyle windowStyle = GUI.skin.window;

                float topBarSize = 20;
#if UNITY_2018_3_OR_NEWER
                if (CSGPrefabUtility.AreInPrefabMode())
                {
                    topBarSize += 25;
                }
#endif


                var bounds = new Rect(10, 10 + topBarSize, 500, 40);

                GUILayout.BeginArea(bounds, ContentTitleLabel, windowStyle);
                {
                    //GUILayout.Space(bounds.height);
                    Rect editModeBounds;

                    CSG_GUIStyleUtility.InitStyles();
                    EditorGUI.BeginChangeCheck();
                    var newEditMode = (ToolEditMode)CSG_EditorGUIUtility.ToolbarWrapped((int)EditModeManager.EditMode, ref editModeRects, out editModeBounds, CSG_GUIStyleUtility.brushEditModeContent, CSG_GUIStyleUtility.brushEditModeTooltips, yOffset: 20, areaWidth: bounds.width);
                    //var newEditMode = (ToolEditMode)GUILayout.Toolbar((int)CSGBrushEditorManager.EditMode, GUIStyleUtility.brushEditModeContent, GUIStyleUtility.brushEditModeTooltips);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditModeManager.EditMode = newEditMode;
                        CSG_EditorGUIUtility.RepaintAll();
                    }

                    var buttonArea = bounds;
                    buttonArea.x      = bounds.width - 17;
                    buttonArea.y      = 2;
                    buttonArea.height = 13;
                    buttonArea.width  = 13;
                    if (GUI.Button(buttonArea, GUIContent.none, "WinBtnClose"))
                    {
                        EditModeToolWindowSceneGUI.GetWindow();
                    }
                    TooltipUtility.SetToolTip(CSG_GUIStyleUtility.PopOutTooltip, buttonArea);

                    var versionWidth = CSG_GUIStyleUtility.versionLabelStyle.CalcSize(VersionLabel);
                    var versionArea  = bounds;
                    versionArea.x      = bounds.width - (17 + versionWidth.x);
                    versionArea.y      = 1;
                    versionArea.height = 15;
                    versionArea.width  = versionWidth.x;
                    GUI.Label(versionArea, VersionLabel, CSG_GUIStyleUtility.versionLabelStyle);
                }
                GUILayout.EndArea();

                int controlID = GUIUtility.GetControlID(SceneViewBrushEditorOverlayHash, FocusType.Keyboard, bounds);
                switch (Event.current.GetTypeForControl(controlID))
                {
                case EventType.MouseDown:       { if (bounds.Contains(Event.current.mousePosition))
                                                  {
                                                      GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; EditorGUIUtility.editingTextField = false; Event.current.Use();
                                                  }
                                                  break; }

                case EventType.MouseMove:       { if (bounds.Contains(Event.current.mousePosition))
                                                  {
                                                      Event.current.Use();
                                                  }
                                                  break; }

                case EventType.MouseUp:         { if (GUIUtility.hotControl == controlID)
                                                  {
                                                      GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Event.current.Use();
                                                  }
                                                  break; }

                case EventType.MouseDrag:       { if (GUIUtility.hotControl == controlID)
                                                  {
                                                      Event.current.Use();
                                                  }
                                                  break; }

                case EventType.ScrollWheel: { if (bounds.Contains(Event.current.mousePosition))
                                              {
                                                  Event.current.Use();
                                              }
                                              break; }
                }
            }
            GUILayout.EndHorizontal();
            GUI.skin = oldSkin;
        }
Пример #27
0
        static void OnGUIContents(bool isSceneGUI, EditModePlace tool)
        {
            EditModeCommonGUI.StartToolGUI();

            var filteredSelection   = EditModeManager.FilteredSelection;
            var defaultMoveOffset   = CSGSettings.DefaultMoveOffset;
            var defaultRotateOffset = CSGSettings.DefaultRotateOffset;
            var displayNewCenter    = GridUtility.CleanPosition((Tools.pivotRotation == PivotRotation.Local) ?
                                                                tool.LocalSpacePivotCenter :
                                                                tool.WorldSpacePivotCenter);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    ShowCSGOperations(isSceneGUI, tool, filteredSelection);
                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUI.BeginDisabledGroup(!tool.HaveSelection);
                        {
                            if (Tools.current == Tool.Move)
                            {
                                EditorGUI.BeginDisabledGroup(defaultMoveOffset.sqrMagnitude < MathConstants.EqualityEpsilonSqr);
                                {
                                    if (GUILayout.Button(MoveByOffsetContent))
                                    {
                                        tool.MoveByOffset(RealtimeCSG.CSGSettings.DefaultMoveOffset);
                                    }
                                    TooltipUtility.SetToolTip(MoveByOffsetTooltip);
                                    if (GUILayout.Button(CloneMoveByOffsetContent))
                                    {
                                        tool.CloneMoveByOffset(RealtimeCSG.CSGSettings.DefaultMoveOffset);
                                    }
                                    TooltipUtility.SetToolTip(CloneMoveByOffsetTooltip);
                                }
                                EditorGUI.EndDisabledGroup();
                            }
                            else
                            if (Tools.current == Tool.Rotate)
                            {
                                EditorGUI.BeginDisabledGroup(defaultMoveOffset.sqrMagnitude < MathConstants.EqualityEpsilonSqr);
                                {
                                    if (GUILayout.Button(RotateByOffsetContent))
                                    {
                                        tool.RotateByOffset(Quaternion.Euler(RealtimeCSG.CSGSettings.DefaultRotateOffset));
                                    }
                                    TooltipUtility.SetToolTip(RotateByOffsetTooltip);
                                    if (GUILayout.Button(CloneRotateByOffsetContent))
                                    {
                                        tool.CloneRotateByOffset(Quaternion.Euler(RealtimeCSG.CSGSettings.DefaultRotateOffset));
                                    }
                                    TooltipUtility.SetToolTip(CloneRotateByOffsetTooltip);
                                }
                                EditorGUI.EndDisabledGroup();
                                if (GUILayout.Button(RecenterPivotContent))
                                {
                                    tool.RecenterPivot();
                                }
                                TooltipUtility.SetToolTip(RecenterPivotTooltip);
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5);
                if (Tools.current == Tool.Move)
                {
                    var doubleFieldOptions = isSceneGUI ? MaxWidth150 : CSG_GUIStyleUtility.ContentEmpty;
                    EditorGUI.BeginDisabledGroup(!tool.HaveSelection);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label(MoveOffsetContent);
                            defaultMoveOffset = CSG_EditorGUIUtility.DistanceVector3Field(defaultMoveOffset, false, doubleFieldOptions);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            RealtimeCSG.CSGSettings.DefaultMoveOffset = defaultMoveOffset;
                            RealtimeCSG.CSGSettings.Save();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                if (Tools.current == Tool.Rotate)
                {
                    var doubleFieldOptions = isSceneGUI ? MaxWidth150 : CSG_GUIStyleUtility.ContentEmpty;
                    EditorGUI.BeginDisabledGroup(Tools.pivotMode == PivotMode.Center || !tool.HaveSelection);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label(RotationCenterContent);
                            defaultRotateOffset = CSG_EditorGUIUtility.EulerDegreeField(defaultRotateOffset);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            RealtimeCSG.CSGSettings.DefaultRotateOffset = defaultRotateOffset;
                            RealtimeCSG.CSGSettings.Save();
                        }

                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label(PivotCenterContent);
                            displayNewCenter = CSG_EditorGUIUtility.DistanceVector3Field(displayNewCenter, false, doubleFieldOptions);
                            TooltipUtility.SetToolTip(PivotVectorTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Tools.pivotRotation == PivotRotation.Local)
                            {
                                tool.LocalSpacePivotCenter = displayNewCenter;
                            }
                            else
                            {
                                tool.WorldSpacePivotCenter = displayNewCenter;
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
            GUILayout.EndVertical();
            EditorGUI.showMixedValue = false;
        }
        static void OnGUIContents(GeneratorCylinder generator, bool isSceneGUI)
        {
            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
            {
                if (isSceneGUI)
                {
                    CylinderSettingsGUI(generator, isSceneGUI);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit;
                var nextUnit     = Units.CycleToNextUnit(distanceUnit);
                var unitText     = Units.GetUnitGUIContent(distanceUnit);

                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.Label(HeightContent, width65);

                    if (isSceneGUI)
                    {
                        TooltipUtility.SetToolTip(HeightTooltip);
                    }

                    var height = generator.HaveHeight ? generator.Height : GeometryUtility.CleanLength(generator.DefaultHeight);
                    EditorGUI.BeginChangeCheck();
                    {
                        if (!isSceneGUI)
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height)));
                        }
                        else
                        {
                            height = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, height), width65));
                        }
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (generator.HaveHeight)
                        {
                            generator.Height = height;
                        }
                        else
                        {
                            generator.DefaultHeight = height;
                        }
                    }

                    if (GUILayout.Button(unitText, EditorStyles.miniLabel, width25))
                    {
                        distanceUnit = nextUnit;
                        RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                        RealtimeCSG.CSGSettings.UpdateSnapSettings();
                        RealtimeCSG.CSGSettings.Save();
                        CSG_EditorGUIUtility.RepaintAll();
                    }
                }
                GUILayout.EndHorizontal();

                TooltipUtility.SetToolTip(HeightTooltip);

                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    EditorGUI.BeginDisabledGroup(!generator.CanCommit);
                    {
                        GUILayout.Label(RadiusContent, width65);

                        if (isSceneGUI)
                        {
                            TooltipUtility.SetToolTip(RadiusTooltip);
                        }

                        var radius = generator.RadiusA;
                        EditorGUI.BeginChangeCheck();
                        {
                            if (!isSceneGUI)
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius)));
                            }
                            else
                            {
                                radius = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, radius), width65));
                            }
                        }

                        if (EditorGUI.EndChangeCheck())
                        {
                            generator.RadiusA = radius;
                        }

                        if (GUILayout.Button(unitText, EditorStyles.miniLabel, width25))
                        {
                            distanceUnit = nextUnit;
                            RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit;
                            RealtimeCSG.CSGSettings.UpdateSnapSettings();
                            RealtimeCSG.CSGSettings.Save();
                            CSG_EditorGUIUtility.RepaintAll();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                if (!isSceneGUI)
                {
                    TooltipUtility.SetToolTip(RadiusTooltip);
                }
            }

            GUILayout.EndVertical();
            {
                generator.CircleSides = IntSettingsControl
                                        (
                    generator.CircleSides,
                    3,
                    RealtimeCSG.CSGSettings.MaxCircleSides,
                    SidesContent,
                    isSceneGUI
                                        );

                TooltipUtility.SetToolTip(SidesTooltip);
            }
            generator.CircleOffset = FloatSettingsControl
                                     (
                generator.CircleOffset,
                0,
                360,
                OffsetContent,
                isSceneGUI
                                     );

            TooltipUtility.SetToolTip(OffsetTooltip);


            if (!isSceneGUI)
            {
                GUILayout.Space(5);

                CylinderSettingsGUI(generator, isSceneGUI);
            }
        }