public static void CenterPivotOnSelection() { var selectedNodes = ChiselSelectionManager.SelectedNodes; if (selectedNodes != null && selectedNodes.Count != 0) { var center = PIvotUtility.FindSelectionWorldSpaceCenter(selectedNodes); PIvotUtility.MovePivotTo(selectedNodes, center); } }
public override void OnSceneGUI(SceneView sceneView, Rect dragArea) { var evt = Event.current; switch (evt.type) { case EventType.KeyDown: { if (evt.keyCode == ChiselKeyboardDefaults.kCancelKey) { if (GUIUtility.hotControl == 0) { evt.Use(); break; } } break; } case EventType.KeyUp: { if (evt.keyCode == ChiselKeyboardDefaults.kCancelKey) { if (GUIUtility.hotControl == 0) { Selection.activeTransform = null; evt.Use(); GUIUtility.ExitGUI(); // avoids a nullreference exception in sceneview break; } } break; } } var position = Tools.handlePosition; var rotation = Tools.handleRotation; EditorGUI.BeginChangeCheck(); var handleIDs = new SceneHandles.PositionHandleIDs(); SceneHandles.Initialize(ref handleIDs); Snapping.FindCustomSnappingPointsRayMethod = FindCustomSnappingRayPoints; Snapping.FindCustomSnappingPointsMethod = FindCustomSnappingPoints; Snapping.CustomSnappedEvent = OnCustomSnappedEvent; var newPosition = SceneHandles.PositionHandle(ref handleIDs, position, rotation); Snapping.FindCustomSnappingPointsRayMethod = null; Snapping.FindCustomSnappingPointsMethod = null; Snapping.CustomSnappedEvent = null; if (EditorGUI.EndChangeCheck()) { var nodes = ChiselSelectionManager.SelectedNodes; if (nodes == null || nodes.Count == 0) { return; } PIvotUtility.MovePivotTo(nodes, newPosition); } if (Event.current.type == EventType.Repaint) { var handleSize = UnityEditor.HandleUtility.GetHandleSize(position); HandleRendering.DrawCameraAlignedCircle(position, handleSize * 0.1f, Color.white, Color.black); if ((handleIDs.combinedState & (ControlState.Focused | ControlState.Active)) != ControlState.None) { var prevColor = Handles.color; var selectedColor = UnityEditor.Handles.selectedColor; selectedColor.a = 0.5f; Handles.color = selectedColor; //if ((handleIDs.xAxisIndirectState & (ControlState.Focused | ControlState.Active)) != ControlState.None) // HandleRendering.DrawInfiniteLine(position, Axis.X); //if ((handleIDs.yAxisIndirectState & (ControlState.Focused | ControlState.Active)) != ControlState.None) // HandleRendering.DrawInfiniteLine(position, Axis.Y); //if ((handleIDs.zAxisIndirectState & (ControlState.Focused | ControlState.Active)) != ControlState.None) // HandleRendering.DrawInfiniteLine(position, Axis.Z); DrawCustomSnappedEvent(); Handles.color = prevColor; } } }