Beispiel #1
0
 public static void DeselectAll()
 {
     if (CSGBrushEditorManager.DeselectAll())
     {
         return;
     }
     DeselectAllBrushes();
 }
Beispiel #2
0
        static void UndoRedoPerformed()
        {
            if (instance.activeTool != null)
            {
                instance.activeTool.UndoRedoPerformed();
            }

            InternalCSGModelManager.UpdateMaterialRegistration();

            CSGBrushEditorManager.UpdateSelection(forceUpdate: true);
        }
        static void UndoRedoPerformed()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (instance.activeTool != null)
            {
                instance.activeTool.UndoRedoPerformed();
            }

            CSGBrushEditorManager.UpdateSelection(forceUpdate: true);
        }
Beispiel #4
0
        internal override bool StartExtrudeMode(bool showErrorMessage = true)
        {
            // reverse buildPlane if it's different
            if (BuildPlaneIsReversed)
            {
                buildPlane = buildPlane.Negated();
                CalculateWorldSpaceTangents();
            }

            var outlineVertices = settings.GetVertices(buildPlane, worldPosition, base.gridTangent, base.gridBinormal, out shapeIsValid);

            if (!shapeIsValid)
            {
                ClearPolygons();
                //if (showErrorMessage)
                //	CSGBrushEditorManager.ShowMessage("Could not create brush from given 2D shape");
                HideGenerateBrushes();
                return(false);
            }

            var newPolygons = ShapePolygonUtility.CreateCleanPolygonsFromVertices(outlineVertices, brushPosition, buildPlane);

            if (newPolygons == null)
            {
                shapeIsValid = false;
                ClearPolygons();
                //if (showErrorMessage)
                //	CSGBrushEditorManager.ShowMessage("Could not create brush from given 2D shape");
                HideGenerateBrushes();
                return(false);
            }
            CSGBrushEditorManager.ResetMessage();
            shapeIsValid = true;

            UpdatePolygons(outlineVertices, newPolygons.ToArray());
            GenerateBrushesFromPolygons(inGridSpace: false);
            return(true);
        }
Beispiel #5
0
        static void OnScene(SceneView sceneView)
        {
            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                return;
            }
            UpdateOnSceneChange();
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint &&
                !ColorSettings.isInitialized)
            {
                ColorSettings.Update();
            }

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

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

            var s_RectSelectionID_instance = (int)s_RectSelectionID_field.GetValue(null);

            UpdateRectSelection(sceneView, s_RectSelectionID_instance);
            OnHandleDragAndDrop(inSceneView: true);

            var eventType = Event.current.GetTypeForControl(s_RectSelectionID_instance);

            var hotControl = GUIUtility.hotControl;

            if (hotControl == s_RectSelectionID_instance &&
                CSGBrushEditorManager.ActiveTool.IgnoreUnityRect)
            {
                hotControl            = 0;
                GUIUtility.hotControl = 0;
            }

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                rectClickDown      = (Event.current.button == 0 && hotControl == s_RectSelectionID_instance);
                clickMousePosition = Event.current.mousePosition;
                mouseDragged       = false;
                break;
            }

            case EventType.MouseUp:
            {
                rectClickDown = false;
                break;
            }

            case EventType.MouseMove:
            {
                rectClickDown = false;
                break;
            }

            case EventType.Used:
            {
                if (clickMousePosition != Event.current.mousePosition)
                {
                    mouseDragged = true;
                }
                if (!mouseDragged && rectClickDown &&
                    Event.current.button == 0)
                {
                    // m_RectSelection field of SceneView
                    var m_RectSelection_instance = m_RectSelection_field.GetValue(sceneView);

                    var m_RectSelecting_instance = (bool)m_RectSelecting_field.GetValue(m_RectSelection_instance);
                    if (!m_RectSelecting_instance)
                    {
                        // make sure GeneratedMeshes are not part of our selection
                        if (Selection.gameObjects != null)
                        {
                            var selectedObjects = Selection.objects;
                            var foundObjects    = new List <UnityEngine.Object>();
                            foreach (var obj in selectedObjects)
                            {
                                var component  = obj as Component;
                                var gameObject = obj as GameObject;
                                var transform  = obj as Transform;
                                if (!(component && component.GetComponent <GeneratedMeshes>()) &&
                                    !(gameObject && gameObject.GetComponent <GeneratedMeshes>()) &&
                                    !(transform && transform.GetComponent <Transform>()))
                                {
                                    foundObjects.Add(obj);
                                }
                            }
                            if (foundObjects.Count != selectedObjects.Length)
                            {
                                Selection.objects = foundObjects.ToArray();
                            }
                        }

                        SelectionUtility.DoSelectionClick();
                        Event.current.Use();
                    }
                }
                rectClickDown = false;
                break;
            }


            case EventType.ValidateCommand:
            {
                if (Event.current.commandName == "SelectAll")
                {
                    Event.current.Use();
                    break;
                }
                if (Keys.HandleSceneValidate(CSGBrushEditorManager.CurrentTool, true))
                {
                    Event.current.Use();
                    HandleUtility.Repaint();
                }
                break;
            }

            case EventType.ExecuteCommand:
            {
                if (Event.current.commandName == "SelectAll")
                {
                    var transforms = new List <UnityEngine.Object>();
                    for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++)
                    {
                        var scene = SceneManager.GetSceneAt(sceneIndex);
                        foreach (var gameObject in scene.GetRootGameObjects())
                        {
                            foreach (var transform in gameObject.GetComponentsInChildren <Transform>())
                            {
                                if ((transform.hideFlags & (HideFlags.NotEditable | HideFlags.HideInHierarchy)) == (HideFlags.NotEditable | HideFlags.HideInHierarchy))
                                {
                                    continue;
                                }
                                transforms.Add(transform.gameObject);
                            }
                        }
                    }
                    Selection.objects = transforms.ToArray();

                    Event.current.Use();
                    break;
                }
                break;
            }

            case EventType.KeyDown:
            {
                if (Keys.HandleSceneKeyDown(CSGBrushEditorManager.CurrentTool, true))
                {
                    Event.current.Use();
                    HandleUtility.Repaint();
                }
                break;
            }

            case EventType.KeyUp:
            {
                if (Keys.HandleSceneKeyUp(CSGBrushEditorManager.CurrentTool, true))
                {
                    Event.current.Use();
                    HandleUtility.Repaint();
                }
                break;
            }

            case EventType.Layout:
            {
                if (currentDragTool != null)
                {
                    currentDragTool.Layout();
                }
                break;
            }

            case EventType.Repaint:
            {
                break;
            }
            }

            //bool fallbackGUI = EditorWindow.focusedWindow != sceneView;
            //fallbackGUI =
            CSGBrushEditorManager.InitSceneGUI(sceneView);                    // || fallbackGUI;
            //fallbackGUI = true;

            /*
             * if (SceneQueryUtility._deepClickIntersections != null &&
             *      SceneQueryUtility._deepClickIntersections.Length > 0)
             * {
             *      foreach (var intersection in SceneQueryUtility._deepClickIntersections)
             *      {
             *              var triangle = intersection.triangle;
             *              Debug.DrawLine(triangle[0], triangle[1]);
             *              Debug.DrawLine(triangle[1], triangle[2]);
             *              Debug.DrawLine(triangle[2], triangle[0]);
             *      }
             * }
             */

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

            if (Event.current.type == EventType.Repaint)
            {
                if (currentDragTool != null)
                {
                    currentDragTool.OnPaint();
                }

                SceneTools.OnPaint(sceneView);
            }
            else
            //if (fallbackGUI)
            {
                BottomBarGUI.ShowGUI(sceneView);
            }


            CSGBrushEditorManager.OnSceneGUI(sceneView);

            //if (fallbackGUI)
            {
                TooltipUtility.InitToolTip(sceneView);
                if (Event.current.type == EventType.Repaint)
                {
                    BottomBarGUI.ShowGUI(sceneView);
                }
                if (!mousePressed)
                {
                    Handles.BeginGUI();
                    TooltipUtility.DrawToolTip(getLastRect: false);
                    Handles.EndGUI();
                }
            }
        }
Beispiel #6
0
 static void OnSelectionChanged()
 {
     CSGBrushEditorManager.UpdateSelection();
 }
        static void InitTools()
        {
            if (instance)
            {
                return;
            }


            var values = Enum.GetValues(typeof(ToolEditMode)).Cast <ToolEditMode>().ToList();

            values.Sort();
            firstEditMode = values[0];
            lastEditModes = values[values.Count - 1];

            Undo.undoRedoPerformed -= UndoRedoPerformed;
            Undo.undoRedoPerformed += UndoRedoPerformed;

            EditorApplication.modifierKeysChanged -= OnModifierKeysChanged;
            EditorApplication.modifierKeysChanged += OnModifierKeysChanged;


            var managers = FindObjectsOfType <CSGBrushEditorManager>().ToArray();

            for (int i = 0; i < managers.Length; i++)
            {
                DestroyImmediate(managers[i]);
            }
            instance           = ScriptableObject.CreateInstance <CSGBrushEditorManager>();
            instance.hideFlags = scriptableObjectHideflags;

            var types = new Type[]
            {
                typeof(ObjectEditBrushTool),
                typeof(GenerateBrushTool),
                typeof(MeshEditBrushTool),
                typeof(ClipBrushTool),
                typeof(SurfaceEditBrushTool)
            };

            if (types.Length != values.Count)
            {
                Debug.LogWarning("types.Length != values.Count");
            }

            brushTools = new IBrushTool[values.Count];
            for (int j = 0; j < types.Length; j++)
            {
                var objects = FindObjectsOfType(types[j]).ToArray();
                for (int i = 0; i < objects.Length; i++)
                {
                    DestroyImmediate(objects[i]);
                }

                var obj = ScriptableObject.CreateInstance(types[j]);
                brushTools[j] = obj as IBrushTool;
                if (brushTools[j] == null)
                {
                    Debug.LogWarning("brushTools[j] == null");
                    continue;
                }
                if (!(brushTools[j] is ScriptableObject))
                {
                    Debug.LogWarning("!(brushTools[j] is ScriptableObject)");
                    continue;
                }
                obj.hideFlags = scriptableObjectHideflags;
            }

            GenerateBrushTool.ShapeCommitted -= OnShapeCommittedEvent;
            GenerateBrushTool.ShapeCommitted += OnShapeCommittedEvent;
            GenerateBrushTool.ShapeCancelled -= OnShapeCancelledEvent;
            GenerateBrushTool.ShapeCancelled += OnShapeCancelledEvent;

            RealtimeCSG.CSGSettings.Reload();
            instance.editMode = RealtimeCSG.CSGSettings.EditMode;

            CSGBrushEditorManager.UpdateSelection(true);
            InitTargets();
        }