Beispiel #1
0
        void OnEditorUpdate()
        {
            if (deferredSelection != null)
            {
                Selection.objects = deferredSelection;
                deferredSelection = null;
                SceneView.RepaintAll();
                EditorApplication.RepaintHierarchyWindow();
            }

            if (EditMode)
            {
                frameIndex++;
                if (frameIndex > 1000)
                {
                    frameIndex -= 1000;
                }

                if (AutoRebuild && gameObject.activeInHierarchy && this.enabled)
                {
//					if(frameIndex % 30 == 0)
                    {
                        Build(false);
                    }
                }

                if (CurrentSettings.OverrideFlyCamera)
                {
                    LinearFPSCam.OnUpdate();
                }
            }
        }
Beispiel #2
0
        public void OnSceneGUI(SceneView sceneView)
        {
            Event e = Event.current;

            //			if (e.type == EventType.Repaint)
            //			{
            //				if(CurrentSettings.GridMode == GridMode.SabreCSG)
            //				{
            //					CSGGrid.Activate();
            //				}
            //			}

            if (!EditMode)
            {
                return;
            }

            // Frame rate tracking
            if (e.type == EventType.Repaint)
            {
                currentFrameDelta     = Time.realtimeSinceStartup - currentFrameTimestamp;
                currentFrameTimestamp = Time.realtimeSinceStartup;
            }

            // Raw checks for tracking mouse events (use raw so that consumed events are not ignored)
            if (e.rawType == EventType.MouseDown)
            {
                mouseIsDragging = false;
                mouseIsHeld     = true;

                if (e.button == 0 && GUIUtility.hotControl == 0)
                {
                    GUIUtility.keyboardControl = 0;
                }
            }
            else if (e.rawType == EventType.MouseDrag)
            {
                mouseIsDragging = true;
            }
            else if (e.rawType == EventType.MouseUp)
            {
                mouseIsHeld = false;
            }

//			if (CurrentSettings.BrushesVisible)
            {
                // No idea what this line of code means, but it seems to stop normal mouse selection
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            }

            if (EditMode)
            {
                // In CSG mode, prevent the normal tools, so that the user must use our tools instead
                Tools.current = UnityEditor.Tool.None;
            }

            int concaveBrushCount = 0;

            for (int i = 0; i < brushes.Count; i++)
            {
                if (brushes[i] != null && !brushes[i].IsBrushConvex)
                {
                    concaveBrushCount++;
                }
            }
            if (concaveBrushCount > 0)
            {
                Toolbar.WarningMessage = concaveBrushCount + " Concave Brush" + (concaveBrushCount > 1 ? "es" : "") + " Detected";
            }
            else
            {
                //				Toolbar.WarningMessage = "";
            }

            Toolbar.CSGModel = this;
            Toolbar.OnSceneGUI(sceneView, e);

            if (e.type == EventType.Repaint)            // || e.type == EventType.Layout)
            {
                if (tools[CurrentSettings.CurrentMode].BrushesHandleDrawing)
                {
                    SabreGraphics.GetSelectedBrushMaterial().SetPass(0);
                    // Selection
                    GL.Begin(GL.LINES);
                    Color outlineColor = Color.blue;

                    for (int brushIndex = 0; brushIndex < brushes.Count; brushIndex++)
                    {
                        Brush brush = brushes[brushIndex];
                        if (brush == null)
                        {
                            continue;
                        }
                        GameObject brushGameObject = brush.gameObject;

                        if (!brushGameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        if (Selection.Contains(brushGameObject))
                        {
                            if (brushes[brushIndex].Mode == CSGMode.Add)
                            {
                                outlineColor = Color.cyan;
                            }
                            else
                            {
                                outlineColor = Color.yellow;
                            }
                        }
                        else if (CurrentSettings.BrushesVisible)
                        {
                            if (brushes[brushIndex].Mode == CSGMode.Add)
                            {
                                outlineColor = Color.blue;
                            }
                            else
                            {
                                outlineColor = new Color32(255, 130, 0, 255);
                            }
                        }
                        else
                        {
                            continue;
                        }

                        GL.Color(outlineColor);

                        Polygon[] polygons       = brush.GetPolygons();
                        Transform brushTransform = brush.transform;

                        // Brush Outline
                        for (int i = 0; i < polygons.Length; i++)
                        {
                            Polygon polygon = polygons[i];

                            for (int j = 0; j < polygon.Vertices.Length; j++)
                            {
                                Vector3 position = brushTransform.TransformPoint(polygon.Vertices[j].Position);
                                GL.Vertex(position);

                                if (j < polygon.Vertices.Length - 1)
                                {
                                    Vector3 position2 = brushTransform.TransformPoint(polygon.Vertices[j + 1].Position);
                                    GL.Vertex(position2);
                                }
                                else
                                {
                                    Vector3 position2 = brushTransform.TransformPoint(polygon.Vertices[0].Position);
                                    GL.Vertex(position2);
                                }
                            }
                        }
                    }

                    GL.End();

                    for (int i = 0; i < brushes.Count; i++)
                    {
                        if (brushes[i] is PrimitiveBrush && brushes[i] != null && brushes[i].gameObject.activeInHierarchy)
                        {
                            ((PrimitiveBrush)brushes[i]).OnRepaint(sceneView, e);
                        }
                    }
                }
            }

            if (e.type == EventType.Repaint)
            {
                Rect rect = new Rect(0, 0, Screen.width, Screen.height);
                EditorGUIUtility.AddCursorRect(rect, SabreMouse.ActiveCursor);
            }
            //

            //		int hotControl = GUIUtility.hotControl;
            //		if(hotControl != 0)
            //			Debug.Log (hotControl);
            //		Tools.viewTool = ViewTool.None;

            PrimitiveBrush primitiveBrush = null;

            if (Selection.activeGameObject != null)
            {
                primitiveBrush = Selection.activeGameObject.GetComponent <PrimitiveBrush>();
//				primitiveBrush = Selection.activeGameObject.GetComponentInChildren<PrimitiveBrush>();
            }

            List <PrimitiveBrush> primitiveBrushes = new List <PrimitiveBrush>();

            for (int i = 0; i < Selection.gameObjects.Length; i++)
            {
                PrimitiveBrush[] matchedBrushes = Selection.gameObjects[i].GetComponents <PrimitiveBrush>();
//				PrimitiveBrush[] matchedBrushes = Selection.gameObjects[i].GetComponentsInChildren<PrimitiveBrush>();
                if (matchedBrushes.Length > 0)
                {
                    primitiveBrushes.AddRange(matchedBrushes);
                }
            }

            Tool lastTool = activeTool;

            if (tools.ContainsKey(CurrentSettings.CurrentMode))
            {
                activeTool = tools[CurrentSettings.CurrentMode];
            }
            else
            {
                activeTool = null;
            }

            if (activeTool != null)
            {
                activeTool.CSGModel           = this;
                activeTool.PrimaryTargetBrush = primitiveBrush;
                activeTool.TargetBrushes      = primitiveBrushes.ToArray();
                activeTool.OnSceneGUI(sceneView, e);

                if (activeTool != lastTool)
                {
                    if (lastTool != null)
                    {
                        lastTool.Deactivated();
                    }
                    activeTool.ResetTool();
                }
            }

//			if(e.type == EventType.DragPerform)
//			{
//				Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
//
//				RaycastHit hit = new RaycastHit();
//
//				int layerMask = 1 << LayerMask.NameToLayer("CSGMesh");
//				// Invert the layer mask
//				layerMask = ~layerMask;
//
//				// Shift mode means only add what they click (clicking nothing does nothing)
//				if (Physics.Raycast(ray, out hit, float.PositiveInfinity, layerMask))
//				{
//										OnDragDrop(hit.collider.gameObject);
//				}
//			}

            if (e.type == EventType.MouseDown)
            {
            }
            else if (e.type == EventType.MouseDrag)
            {
            }
            else if (e.type == EventType.MouseUp)
            {
                OnMouseUp(sceneView, e);
                SabreMouse.ResetCursor();
            }
            else if (e.type == EventType.KeyDown || e.type == EventType.KeyUp)
            {
                OnKeyAction(sceneView, e);
            }

            if (CurrentSettings.OverrideFlyCamera)
            {
                LinearFPSCam.OnSceneGUI(sceneView);
            }
        }