public bool DragUpdated(Transform transformInInspector, Rect selectionRect) { try { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; hoverBrushSurface = null; hoverParent = (transformInInspector == null) ? null : transformInInspector.parent; hoverSiblingIndex = (transformInInspector == null) ? int.MaxValue : transformInInspector.transform.GetSiblingIndex(); float middle = (selectionRect.yMax + selectionRect.yMin) * 0.5f; if (Event.current.mousePosition.y > middle) { hoverSiblingIndex++; } hoverRotation = MathConstants.identityQuaternion; hoverPosition = MathConstants.zeroVector3; haveNoParent = true; return(true); } finally { if (!UpdateLoop.IsActive()) { UpdateLoop.ResetUpdateRoutine(); } } }
public bool DragUpdated(SceneView sceneView) { try { DisableVisualObjects(); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; var camera = sceneView.camera; var intersection = SceneQueryUtility.FindMeshIntersection(camera, Event.current.mousePosition); var normal = intersection.worldPlane.normal; hoverPosition = intersection.worldIntersection; hoverParent = SelectionUtility.FindParentToAssignTo(intersection); hoverBrushSurface = intersection.brush != null ? new SelectedBrushSurface(intersection.brush, intersection.surfaceIndex, intersection.worldPlane) : null; hoverRotation = SelectionUtility.FindDragOrientation(sceneView, normal, sourceSurfaceAlignment, destinationSurfaceAlignment); haveNoParent = (hoverParent == null); hoverSiblingIndex = int.MaxValue; RealtimeCSG.CSGGrid.SetForcedGrid(camera, intersection.worldPlane); // Since we're snapping points to grid and do not have a relative distance, relative snapping makes no sense var doGridSnapping = RealtimeCSG.CSGSettings.ActiveSnappingMode != SnapMode.None; if (doGridSnapping) { var localPoints = new Vector3[8]; var localPlane = intersection.worldPlane; for (var i = 0; i < localPoints.Length; i++) { localPoints[i] = GeometryUtility.ProjectPointOnPlane(localPlane, (hoverRotation * projectedBounds[i]) + hoverPosition); } hoverPosition += RealtimeCSG.CSGGrid.SnapDeltaToGrid(camera, MathConstants.zeroVector3, localPoints); } hoverPosition = GeometryUtility.ProjectPointOnPlane(intersection.worldPlane, hoverPosition); // + (normal * 0.01f); EnableVisualObjects(); return(true); } finally { if (!UpdateLoop.IsActive()) { UpdateLoop.ResetUpdateRoutine(); } } }
public bool DragUpdated() { try { DisableVisualObjects(); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; var intersection = SceneQueryUtility.FindMeshIntersection(Event.current.mousePosition); var normal = intersection.plane.normal; hoverPosition = intersection.worldIntersection; hoverParent = SelectionUtility.FindParentToAssignTo(intersection); hoverBrushSurface = intersection.brush != null ? new SelectedBrushSurface(intersection.brush, intersection.surfaceIndex) : null; hoverRotation = SelectionUtility.FindDragOrientation(normal, sourceSurfaceAlignment, destinationSurfaceAlignment); haveNoParent = (hoverParent == null); hoverSiblingIndex = int.MaxValue; RealtimeCSG.CSGGrid.SetForcedGrid(intersection.plane); var toggleSnapping = (Event.current.modifiers & EventModifiers.Control) == EventModifiers.Control; var doSnapping = RealtimeCSG.CSGSettings.SnapToGrid ^ toggleSnapping; if (doSnapping) { var localPoints = new Vector3[8]; var localPlane = intersection.plane; for (var i = 0; i < localPoints.Length; i++) { localPoints[i] = GeometryUtility.ProjectPointOnPlane(localPlane, (hoverRotation * projectedBounds[i]) + hoverPosition); } hoverPosition += RealtimeCSG.CSGGrid.SnapDeltaToGrid(MathConstants.zeroVector3, localPoints); } hoverPosition = GeometryUtility.ProjectPointOnPlane(intersection.plane, hoverPosition) + (normal * 0.01f); EnableVisualObjects(); return(true); } finally { if (!UpdateLoop.IsActive()) { UpdateLoop.ResetUpdateRoutine(); } } }
internal static void OnScene(SceneView sceneView) { if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) { return; } if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } UpdateLoop.UpdateOnSceneChange(); if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) { ColorSettings.isInitialized = false; } else if (!ColorSettings.isInitialized) { if (Event.current.type == EventType.Repaint) { ColorSettings.Update(); } } if (!UpdateLoop.IsActive()) { UpdateLoop.ResetUpdateRoutine(); } if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) { mousePressed = true; } else if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseMove) { mousePressed = false; } SceneDragToolManager.OnHandleDragAndDrop(sceneView); RectangleSelectionManager.Update(sceneView); EditModeManager.InitSceneGUI(sceneView); if (Event.current.type == EventType.Repaint) { MeshInstanceManager.RenderHelperSurfaces(sceneView); } if (Event.current.type == EventType.Repaint) { SceneToolRenderer.OnPaint(sceneView); } else //if (fallbackGUI) { SceneViewBottomBarGUI.ShowGUI(sceneView); SceneViewInfoGUI.DrawInfoGUI(sceneView); } EditModeManager.OnSceneGUI(sceneView); //if (fallbackGUI) { TooltipUtility.InitToolTip(sceneView); if (Event.current.type == EventType.Repaint) { SceneViewBottomBarGUI.ShowGUI(sceneView); SceneViewInfoGUI.DrawInfoGUI(sceneView); } if (!mousePressed) { Handles.BeginGUI(); TooltipUtility.DrawToolTip(getLastRect: false); Handles.EndGUI(); } } if (Event.current.type == EventType.Layout) { var currentFocusControl = CSGHandles.FocusControl; if (prevFocusControl != currentFocusControl) { prevFocusControl = currentFocusControl; HandleUtility.Repaint(); } } }
internal static void OnScene(SceneView sceneView) { if (Event.current.type == EventType.MouseMove) { sceneView.Repaint(); } sceneView.cameraSettings.dynamicClip = false; sceneView.cameraSettings.easingEnabled = false; sceneView.cameraSettings.accelerationEnabled = false; //if (sceneView.orthographic) //{ // sceneView.camera.nearClipPlane = 1; // sceneView.camera.farClipPlane = 1001f; // var camPos = sceneView.pivot; // var camForward = sceneView.camera.transform.forward; // for (int i = 0; i < 3; i++) // { // if (!FastApproximately(camForward[i], 0, .01f)) // { // camPos[i] = 1000; // } // } // sceneView.pivot = camPos; //} if (sceneView.orthographic) { if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.F) { Event.current.Use(); sceneView.pivot = Vector3.zero; if (TryGetSelectionBounds(out Bounds bounds)) { var sz = bounds.extents.magnitude; sz = Mathf.Clamp(sz, 0.05f, 500); sceneView.pivot = bounds.center; sceneView.size = sz; } } if (sceneView.size > 500) { sceneView.size = 500; } if (sceneView.size < .05f) { sceneView.size = .05f; } } CSGSettings.RegisterSceneView(sceneView); if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG || EditorApplication.isPlayingOrWillChangePlaymode) { return; } UpdateLoop.UpdateOnSceneChange(); if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) { ColorSettings.isInitialized = false; } else if (!ColorSettings.isInitialized) { if (Event.current.type == EventType.Repaint) { ColorSettings.Update(); } } if (!UpdateLoop.IsActive()) { UpdateLoop.ResetUpdateRoutine(); } if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) { mousePressed = true; } else if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseMove) { mousePressed = false; } SceneDragToolManager.OnHandleDragAndDrop(sceneView); RectangleSelectionManager.Update(sceneView); EditModeManager.InitSceneGUI(sceneView); if (Event.current.type == EventType.Repaint) { MeshInstanceManager.UpdateHelperSurfaces(); SceneToolRenderer.OnPaint(sceneView); } else { SceneViewBottomBarGUI.ShowGUI(sceneView); SceneViewInfoGUI.DrawInfoGUI(sceneView); } //if(EditorWindow.mouseOverWindow == sceneView) { EditModeManager.OnSceneGUI(sceneView); TooltipUtility.InitToolTip(sceneView); if (!mousePressed) { Handles.BeginGUI(); TooltipUtility.DrawToolTip(getLastRect: false); Handles.EndGUI(); } if (Event.current.type == EventType.Layout) { var currentFocusControl = CSGHandles.FocusControl; if (prevFocusControl != currentFocusControl) { prevFocusControl = currentFocusControl; HandleUtility.Repaint(); } } } }