static void ChooseOperation(GenerateBrushTool 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 = GUIStyleUtility.ChooseOperation(operation, mixedValues); if (EditorGUI.EndChangeCheck()) { generator.CurrentCSGOperationType = operation; } } GUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); }
public bool UpdateRadius(TexGen surfaceTexGen, Vector3 currentSurfacePoint, bool toggleSnapping) { var handleSize = GUIStyleUtility.GetHandleSize(this.RotateCenterPoint); var vectorToCenter = currentSurfacePoint - this.RotateCenterPoint; this.RotateRadius = vectorToCenter.magnitude; vectorToCenter.Normalize(); var rotateCurrentAngle = 0.0f; if (!this.HaveRotateStartAngle) { if (this.RotateRadius > handleSize * ToolConstants.minRotateRadius) { this.HaveRotateStartAngle = true; this.RotateOriginalAngle = surfaceTexGen.RotationAngle; this.RotateStartVector = vectorToCenter; this.RotateCurrentStartAngle = GeometryUtility.SignedAngle(this.RotateSurfaceTangent, vectorToCenter, this.RotateSurfaceNormal); } this.RotateRadius = Math.Max(this.RotateRadius, handleSize * ToolConstants.minRotateRadius); } else { rotateCurrentAngle = GeometryUtility.SignedAngle(this.RotateStartVector, vectorToCenter, this.RotateSurfaceNormal); var minSize = handleSize * ToolConstants.minRotateRadius * 2; var radiusStepSize = minSize; this.RotateRadius = (Mathf.CeilToInt(((this.RotateRadius - minSize) / radiusStepSize) - 0.5f) * radiusStepSize) + minSize; } // snap texture coordinates in world/local space this.RotateCurrentSnappedAngle = GridUtility.SnappedAngle(this.RotateOriginalAngle + rotateCurrentAngle, toggleSnapping) - this.RotateOriginalAngle; return(this.HaveRotateStartAngle); }
void PaintShape(int id) { var rotation = Camera.current.transform.rotation; var temp = Handles.color; var origMatrix = Handles.matrix; { Handles.matrix = MathConstants.identityMatrix; Handles.color = ColorSettings.PointInnerStateColor[3]; { float handleSize = GUIStyleUtility.GetHandleSize(worldPosition); float scaledHandleSize = handleSize * ToolConstants.handleScale; PaintUtility.SquareDotCap(id, worldPosition, rotation, scaledHandleSize); } if (settings.vertices != null && settings.vertices.Length > 0) { Handles.color = ColorSettings.PointInnerStateColor[0]; for (int i = 0; i < settings.vertices.Length; i++) { float handleSize = GUIStyleUtility.GetHandleSize(settings.vertices[i]); float scaledHandleSize = handleSize * ToolConstants.handleScale; PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize); } PaintSquare(); PaintBounds(); } } Handles.matrix = origMatrix; Handles.color = temp; }
void PaintShape(int id) { var temp = Handles.color; var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; var rotation = Camera.current.transform.rotation; bool isValid; var realVertices = settings.GetVertices(buildPlane, worldPosition, gridTangent, gridBinormal, out isValid); if (editMode == EditMode.EditShape) { shapeIsValid = isValid; } if (realVertices != null && realVertices.Length >= 3) { var wireframeColor = ColorSettings.WireframeOutline; if (!shapeIsValid || !isValid) { wireframeColor = Color.red; } for (int i = 1; i < realVertices.Length; i++) { PaintUtility.DrawLine(realVertices[i - 1], realVertices[i], ToolConstants.oldLineScale, wireframeColor); PaintUtility.DrawDottedLine(realVertices[i - 1], realVertices[i], wireframeColor, 4.0f); } PaintUtility.DrawLine(realVertices[realVertices.Length - 1], realVertices[0], ToolConstants.oldLineScale, wireframeColor); PaintUtility.DrawDottedLine(realVertices[realVertices.Length - 1], realVertices[0], wireframeColor, 4.0f); //var color = ColorSettings.ShapeDrawingFill; //PaintUtility.DrawPolygon(MathConstants.identityMatrix, realVertices, color); } if (settings.vertices != null && settings.vertices.Length > 0) { Handles.color = ColorSettings.PointInnerStateColor[0]; for (int i = 0; i < settings.vertices.Length; i++) { float handleSize = GUIStyleUtility.GetHandleSize(settings.vertices[i]); float scaledHandleSize = handleSize * ToolConstants.handleScale; PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize); } PaintSquare(); PaintBounds(); } Handles.color = ColorSettings.PointInnerStateColor[3]; { float handleSize = GUIStyleUtility.GetHandleSize(worldPosition); float scaledHandleSize = handleSize * ToolConstants.handleScale; PaintUtility.SquareDotCap(id, worldPosition, rotation, scaledHandleSize); } Handles.matrix = origMatrix; Handles.color = temp; }
static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) { var o = EditorUtility.InstanceIDToObject(instanceID) as GameObject; if (selectionRect.Contains(Event.current.mousePosition)) { Transform t = (o == null) ? null : o.transform; OnHandleDragAndDrop(inSceneView: false, transformInInspector: t, selectionRect: selectionRect); } if (o == null) { return; } GUIStyleUtility.InitStyles(); var node = o.GetComponent <CSGNode>(); if (node == null || !node.enabled || (node.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) != 0) { return; } CSGOperationType operationType = CSGOperationType.Additive; var brush = node as CSGBrush; if (brush != null) { operationType = brush.OperationType; var skin = GUIStyleUtility.Skin; GUI.Label(selectionRect, skin.hierarchyOperations[(int)operationType], GUIStyleUtility.rightAlignedLabel); return; } var operation = node as CSGOperation; if (operation != null) { var skin = GUIStyleUtility.Skin; if (!operation.PassThrough) { operationType = operation.OperationType; var operationTypeIndex = (int)operationType; if (operationTypeIndex >= 0 && operationTypeIndex < skin.hierarchyOperations.Length) { GUI.Label(selectionRect, skin.hierarchyOperations[operationTypeIndex], GUIStyleUtility.rightAlignedLabel); } } else { GUI.Label(selectionRect, skin.hierarchyPassThrough, GUIStyleUtility.rightAlignedLabel); } return; } }
public static void OnInspectorGUI(EditorWindow window, float height) { lastGuiRect = Rect.MinMaxRect(-1, -1, -1, -1); var tool = CSGBrushEditorManager.ActiveTool as MeshEditBrushTool; GUIStyleUtility.InitStyles(); InitLocalStyles(); OnGUIContents(false, tool); }
public static void OnInspectorGUI(GenerateBrushTool tool, EditorWindow window, float height) { lastGuiRect = Rect.MinMaxRect(-1, -1, -1, -1); tool.CurrentGenerator.StartGUI(); GUIStyleUtility.InitStyles(); InitLocalStyles(); OnGUIContents(tool, false, height); tool.CurrentGenerator.FinishGUI(); }
public float GetClosestEdgeDistance(CSGPlane cameraPlane, int pointIndex0, int pointIndex1) { if (pointIndex0 < 0 || pointIndex0 >= WorldPoints.Length || pointIndex1 < 0 || pointIndex1 >= WorldPoints.Length) { return(float.PositiveInfinity); } var point0 = WorldPoints[pointIndex0]; var point1 = WorldPoints[pointIndex1]; var distance = GUIStyleUtility.DistanceToLine(cameraPlane, point0, point1) * 3.0f; var minDistance = distance; if (!(Mathf.Abs(minDistance) < 4.0f)) { return(minDistance); } var surfaceIndex1 = EdgeSurfaces[pointIndex0]; var surfaceIndex2 = EdgeSurfaces[pointIndex1]; for (var p = 0; p < PolygonCenterPoints.Length; p++) { if (p != surfaceIndex1 && p != surfaceIndex2) { continue; } var polygonCenterPoint = PolygonCenterPoints[p]; var polygonCenterPointOnLine = GeometryUtility.ProjectPointOnInfiniteLine(PolygonCenterPoints[p], point0, (point1 - point0).normalized); var direction = (polygonCenterPointOnLine - polygonCenterPoint).normalized; var nudgedPoint0 = point0 - (direction * 0.05f); var nudgedPoint1 = point1 - (direction * 0.05f); var otherDistance = GUIStyleUtility.DistanceToLine(cameraPlane, nudgedPoint0, nudgedPoint1); if (otherDistance < minDistance) { minDistance = otherDistance; } } return(minDistance); }
public static void OnInspectorGUI(EditorWindow window, float height) { lastGuiRect = Rect.MinMaxRect(-1, -1, -1, -1); var tool = CSGBrushEditorManager.ActiveTool as ClipBrushTool; doCommit = false; // unity bug workaround doCancel = false; // unity bug workaround GUIStyleUtility.InitStyles(); InitLocalStyles(); OnGUIContents(false, tool); if (tool != null) { if (doCommit) { tool.Commit(); // unity bug workaround } if (doCancel) { tool.Cancel(); // unity bug workaround } } }
static void ChooseCSGOperation(FilteredSelection filteredSelection, bool isSceneGUI, MeshEditBrushTool tool) { bool operations_enabled = tool != null && (filteredSelection.NodeTargets.Length > 0 && filteredSelection.ModelTargets.Length == 0); 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 (GUIStyleUtility.PassThroughButton(passThroughValue, ptMixedValues)) { Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes"); foreach (var operation in filteredSelection.OperationTargets) { operation.PassThrough = true; } InternalCSGModelManager.Refresh(); EditorApplication.RepaintHierarchyWindow(); } if (passThroughValue) { operationType = (CSGOperationType)255; } } EditorGUI.BeginChangeCheck(); { operationType = GUIStyleUtility.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.Refresh(); EditorApplication.RepaintHierarchyWindow(); } } GUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); }
static void OnGUIContents(bool isSceneGUI, ClipBrushTool tool) { CommonGUI.StartToolGUI(); if (tool.ClipBrushCount == 0) { GUILayout.Label(string.Format("no brushes selected", tool.ClipBrushCount), 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 = GUIStyleUtility.Skin; for (int i = 0; i < clipModeValues.Length; i++) { var selected = newClipMode == clipModeValues[i]; GUIContent content; GUIStyle style; if (selected) { style = GUIStyleUtility.selectedIconLabelStyle; content = skin.clipNamesOn[i]; } else { style = GUIStyleUtility.unselectedIconLabelStyle; content = skin.clipNames[i]; } if (GUILayout.Toggle(selected, content, style)) { newClipMode = clipModeValues[i]; } TooltipUtility.SetToolTip(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 != ClipBrushTool.EditMode.EditPoints); var defaultMaterial = CSGSettings.DefaultMaterial; GUILayout.BeginVertical(isSceneGUI ? MaterialSceneWidth : GUIStyleUtility.ContentEmpty); { GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { EditorGUI.BeginChangeCheck(); { defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial); } if (EditorGUI.EndChangeCheck() && defaultMaterial) { CSGSettings.DefaultMaterial = defaultMaterial; CSGSettings.Save(); } GUILayout.BeginVertical(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(GUIStyleUtility.ContentEmpty); { EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth); GUILayout.BeginVertical(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(GUIStyleUtility.ContentEmpty); { GUILayout.Space(5); defaultMaterial = GUIStyleUtility.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(); }
protected void HandleHeightHandles(Rect sceneRect, bool showHeightValue) { for (int p = 0; p < extrusionPoints.Length; p++) { var type = Event.current.GetTypeForControl(extrusionPoints[p].ID); switch (type) { case EventType.Repaint: { if (SceneTools.IsDraggingObjectInScene) { break; } bool isSelected = extrusionPoints[p].ID == GUIUtility.keyboardControl; var temp = Handles.color; var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; var rotation = Camera.current.transform.rotation; var state = SelectState.None; if (isSelected) { state |= SelectState.Selected; state |= SelectState.Hovering; } else if (HandleUtility.nearestControl == extrusionPoints[p].ID) { state |= SelectState.Hovering; } if (polygons != null && outlineVertices.Length >= 3) { var wireframeColor = ColorSettings.WireframeOutline; var topWireframeColor = ColorSettings.WireframeOutline; if (!shapeIsValid) { wireframeColor = Color.red; } var surfaceColor = ColorSettings.ShapeDrawingFill; if (GUIUtility.hotControl == extrusionPoints[p].ID) { topWireframeColor = ColorSettings.BoundsEdgeHover; surfaceColor = ColorSettings.PolygonInnerStateColor[(int)(SelectState.Selected | SelectState.Hovering)]; surfaceColor.a *= 0.5f; } else if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == extrusionPoints[p].ID) { topWireframeColor = ColorSettings.BoundsEdgeHover; surfaceColor = ColorSettings.PolygonInnerStateColor[(int)(SelectState.Selected)]; surfaceColor.a *= 0.5f; } var poly2dToWorldMatrix = Matrix4x4.TRS(extrusionPoints[p].Position, Quaternion.FromToRotation(MathConstants.upVector3, buildPlane.normal), MathConstants.oneVector3); for (int i = 0; i < polygons.Length; i++) { PaintUtility.DrawPolygon(poly2dToWorldMatrix, polygons[i].Vertices, surfaceColor); } poly2dToWorldMatrix = Matrix4x4.TRS(extrusionPoints[p].Position, Quaternion.identity, MathConstants.oneVector3); for (int i = 1; i < outlineVertices.Length; i++) { PaintUtility.DrawLine(poly2dToWorldMatrix, outlineVertices[i - 1], outlineVertices[i], ToolConstants.oldLineScale, topWireframeColor); PaintUtility.DrawDottedLine(poly2dToWorldMatrix, outlineVertices[i - 1], outlineVertices[i], topWireframeColor, 4.0f); } PaintUtility.DrawLine(poly2dToWorldMatrix, outlineVertices[outlineVertices.Length - 1], outlineVertices[0], ToolConstants.oldLineScale, topWireframeColor); PaintUtility.DrawDottedLine(poly2dToWorldMatrix, outlineVertices[outlineVertices.Length - 1], outlineVertices[0], topWireframeColor, 4.0f); if (p > 0) { var prevOffset = extrusionPoints[p - 1].Position; var prevPoly2dToWorldMatrix = Matrix4x4.TRS(prevOffset, Quaternion.identity, MathConstants.oneVector3); for (int i = 0; i < outlineVertices.Length; i++) { var from = prevPoly2dToWorldMatrix.MultiplyPoint(outlineVertices[i]); var to = poly2dToWorldMatrix.MultiplyPoint(outlineVertices[i]); PaintUtility.DrawLine(from, to, ToolConstants.oldLineScale, wireframeColor); PaintUtility.DrawDottedLine(from, to, wireframeColor, 4.0f); } } } var color = ColorSettings.PolygonInnerStateColor[(int)state]; if (!shapeIsValid) { color = Color.red; } var handleSize = GUIStyleUtility.GetHandleSize(extrusionPoints[p].Position); var scaledHandleSize = handleSize * ToolConstants.handleScale; if (p > 0) { PaintUtility.DrawDottedLine(extrusionPoints[p - 1].Position, extrusionPoints[p].Position, color, 4.0f); } Handles.color = color; PaintUtility.SquareDotCap(extrusionPoints[p].ID, extrusionPoints[p].Position, rotation, scaledHandleSize); var direction = haveForcedDirection ? forcedDirection : buildPlane.normal; var distance = new CSGPlane(direction, extrusionPoints[p].Position).Distance(extrusionPoints[1 - p].Position); if (distance <= MathConstants.DistanceEpsilon) { PaintUtility.DrawArrowCap(extrusionPoints[p].Position, direction, HandleUtility.GetHandleSize(extrusionPoints[p].Position)); } if (distance > -MathConstants.DistanceEpsilon) { PaintUtility.DrawArrowCap(extrusionPoints[p].Position, -direction, HandleUtility.GetHandleSize(extrusionPoints[p].Position)); } Handles.matrix = origMatrix; Handles.color = temp; if (p > 0 && showHeightValue) { var length = GetSegmentLength(extrusionPoints[p].Position, extrusionPoints[p - 1].Position, direction); PaintHeightMessage(extrusionPoints[p - 1].Position, extrusionPoints[p].Position, gridTangent, length); } break; } case EventType.Layout: { if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)) { break; } var poly2dToWorldMatrix = Matrix4x4.TRS(extrusionPoints[p].Position, Quaternion.FromToRotation(MathConstants.upVector3, buildPlane.normal), MathConstants.oneVector3); var forceOverHandle = IsMouseOverShapePolygons(poly2dToWorldMatrix); HandleUtility.AddControl(extrusionPoints[p].ID, forceOverHandle ? 3.0f : float.PositiveInfinity); var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; float handleSize = GUIStyleUtility.GetHandleSize(extrusionPoints[p].Position); float scaledHandleSize = handleSize * ToolConstants.handleScale * handle_extension; float distanceToCircle = HandleUtility.DistanceToCircle(extrusionPoints[p].Position, scaledHandleSize); HandleUtility.AddControl(extrusionPoints[p].ID, distanceToCircle); var direction = haveForcedDirection ? forcedDirection : buildPlane.normal; var distance = new CSGPlane(direction, extrusionPoints[p].Position).Distance(extrusionPoints[1 - p].Position); if (distance <= MathConstants.DistanceEpsilon) { PaintUtility.AddArrowCapControl(extrusionPoints[p].ID, extrusionPoints[p].Position, direction, HandleUtility.GetHandleSize(extrusionPoints[p].Position)); } if (distance > -MathConstants.DistanceEpsilon) { PaintUtility.AddArrowCapControl(extrusionPoints[p].ID, extrusionPoints[p].Position, -direction, HandleUtility.GetHandleSize(extrusionPoints[p].Position)); } if (generatedGameObjects != null && generatedGameObjects.Length > 0) { for (int g = generatedGameObjects.Length - 1; g >= 0; g--) { if (generatedGameObjects[g]) { continue; } ArrayUtility.RemoveAt(ref generatedGameObjects, g); } if (generatedGameObjects == null || generatedGameObjects.Length == 0) { Cancel(); } } Handles.matrix = origMatrix; break; } case EventType.MouseDown: { if (!sceneRect.Contains(Event.current.mousePosition)) { break; } if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan) || Event.current.modifiers != EventModifiers.None) { break; } if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == extrusionPoints[p].ID && Event.current.button == 0) { if (editMode != EditMode.ExtrudeShape && !StartExtrudeMode()) { Cancel(); } else { UpdateBaseShape(registerUndo: false); dragPositionStart = extrusionPoints[p].Position; GrabHeightHandle(p); BeginExtrusion(); Event.current.Use(); } } break; } case EventType.MouseDrag: case EventType.MouseMove: { if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan) { break; } if (GUIUtility.hotControl == extrusionPoints[p].ID) // && Event.current.button == 0) { Undo.RecordObject(this, "Extrude shape"); heightPosition += Event.current.delta; Vector3 worldPosition = GetHeightHandlePosition(extrusionPoints[p].Position) - heightHandleOffset; if (float.IsInfinity(worldPosition.x) || float.IsNaN(worldPosition.x) || float.IsInfinity(worldPosition.y) || float.IsNaN(worldPosition.y) || float.IsInfinity(worldPosition.z) || float.IsNaN(worldPosition.z)) { worldPosition = extrusionPoints[p].Position; } ResetVisuals(); if (raySnapFunction != null) { CSGBrush snappedOnBrush = null; worldPosition = raySnapFunction(worldPosition, new Ray(brushPosition, movePolygonDirection), ref visualSnappedEdges, out snappedOnBrush); visualSnappedBrush = snappedOnBrush; } visualSnappedGrid = RealtimeCSG.Grid.FindAllGridEdgesThatTouchPoint(worldPosition); extrusionPoints[p].Position = GeometryUtility.ProjectPointOnInfiniteLine(worldPosition, brushPosition, movePolygonDirection); if (p == 0) { MoveShape(extrusionPoints[0].Position - dragPositionStart); UpdateBaseShape(); } UpdateBrushPosition(); UpdateExtrudedShape(); GUI.changed = true; Event.current.Use(); break; } break; } case EventType.MouseUp: { forceDragHandle = false; if (GUIUtility.hotControl == extrusionPoints[p].ID && Event.current.button == 0 && (Tools.viewTool == ViewTool.None || Tools.viewTool == ViewTool.Pan)) { EndExtrusion(); if (firstClick) { firstClick = false; break; } GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; EditorGUIUtility.editingTextField = false; Event.current.Use(); ResetVisuals(); CleanupGrid(); if (!HaveExtrusion) { RevertToEditVertices(); } break; } break; } } } var shapeType = Event.current.GetTypeForControl(shapeId); HandleKeyboard(shapeType); }
public static bool OnShowGUI(BoxGenerator generator, bool isSceneGUI) { GUIStyleUtility.InitStyles(); OnGUIContents(generator, isSceneGUI); return(true); }
public static void ShowGUI(SceneView sceneView, bool haveOffset = true) { if (!localStyles) { miniTextStyle = new GUIStyle(EditorStyles.miniLabel); miniTextStyle.contentOffset = new Vector2(0, -1); textInputStyle = new GUIStyle(EditorStyles.miniTextField); textInputStyle.padding.top--; textInputStyle.margin.top += 2; localStyles = true; } GUIStyleUtility.InitStyles(); if (sceneView != null) { float height = sceneView.position.height; //Screen.height; float width = sceneView.position.width; //Screen.width; Rect bottomBarRect; if (haveOffset) { #if UNITY_5_5_OR_NEWER bottomBarRect = new Rect(0, height - (GUIStyleUtility.BottomToolBarHeight + 18), width, GUIStyleUtility.BottomToolBarHeight); #else bottomBarRect = new Rect(0, height - (GUIStyleUtility.BottomToolBarHeight + SceneView.kToolbarHeight + 1), width, GUIStyleUtility.BottomToolBarHeight); #endif } else { bottomBarRect = new Rect(0, height - (GUIStyleUtility.BottomToolBarHeight + 1), width, GUIStyleUtility.BottomToolBarHeight); } try { Handles.BeginGUI(); bool prevGUIChanged = GUI.changed; if (Event.current.type == EventType.Repaint) { GUIStyleUtility.BottomToolBarStyle.Draw(bottomBarRect, false, false, false, false); } OnBottomBarGUI(sceneView, bottomBarRect); GUI.changed = prevGUIChanged || GUI.changed; int controlID = GUIUtility.GetControlID(BottomBarGUIHash, FocusType.Keyboard, bottomBarRect); var type = Event.current.GetTypeForControl(controlID); //Debug.Log(controlID + " " + GUIUtility.hotControl + " " + type + " " + bottomBarRect.Contains(Event.current.mousePosition)); switch (type) { case EventType.MouseDown: { if (bottomBarRect.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; Event.current.Use(); } break; } case EventType.MouseMove: { if (bottomBarRect.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 (bottomBarRect.Contains(Event.current.mousePosition)) { Event.current.Use(); } break; } } //TooltipUtility.HandleAreaOffset(new Vector2(-bottomBarRect.xMin, -bottomBarRect.yMin)); } finally { Handles.EndGUI(); } } }
static void OnGUIContents(bool isSceneGUI, MeshEditBrushTool tool) { CommonGUI.StartToolGUI(); var filteredSelection = CSGBrushEditorManager.FilteredSelection; var defaultMaterial = CSGSettings.DefaultMaterial; GUILayout.BeginVertical(isSceneGUI ? InSceneWidth : 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(GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); { EditorGUI.BeginChangeCheck(); { defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: true); } if (EditorGUI.EndChangeCheck() && defaultMaterial) { CSGSettings.DefaultMaterial = defaultMaterial; CSGSettings.Save(); } } GUILayout.EndVertical(); } GUILayout.BeginVertical(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(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(GUIStyleUtility.ContentEmpty); { EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth); GUILayout.BeginVertical(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(GUIStyleUtility.ContentEmpty); { GUILayout.Space(5); defaultMaterial = GUIStyleUtility.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 OnGUIContents(bool isSceneGUI, ObjectEditBrushTool tool) { CommonGUI.StartToolGUI(); var filteredSelection = CSGBrushEditorManager.FilteredSelection; var defaultMoveOffset = CSGSettings.DefaultMoveOffset; var defaultRotateOffset = CSGSettings.DefaultRotateOffset; var displayNewCenter = GridUtility.CleanPosition((Tools.pivotRotation == PivotRotation.Local) ? tool.LocalSpacePivotCenter : tool.WorldSpacePivotCenter); GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); { GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { HandleCSGOperations(isSceneGUI, tool, filteredSelection); GUILayout.BeginVertical(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 : GUIStyleUtility.ContentEmpty; EditorGUI.BeginDisabledGroup(!tool.HaveSelection); { EditorGUI.BeginChangeCheck(); { GUILayout.Label("Offset"); defaultMoveOffset = GUIStyleUtility.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 : GUIStyleUtility.ContentEmpty; EditorGUI.BeginDisabledGroup(Tools.pivotMode == PivotMode.Center || !tool.HaveSelection); { EditorGUI.BeginChangeCheck(); { GUILayout.Label("Offset"); defaultRotateOffset = GUIStyleUtility.EulerDegreeField(defaultRotateOffset); } if (EditorGUI.EndChangeCheck()) { RealtimeCSG.CSGSettings.DefaultRotateOffset = defaultRotateOffset; RealtimeCSG.CSGSettings.Save(); } EditorGUI.BeginChangeCheck(); { GUILayout.Label("Pivot"); displayNewCenter = GUIStyleUtility.DistanceVector3Field(displayNewCenter, false, doubleFieldOptions); TooltipUtility.SetToolTip(PivotVectorTooltip); } if (EditorGUI.EndChangeCheck()) { if (Tools.pivotRotation == PivotRotation.Local) { tool.LocalSpacePivotCenter = displayNewCenter; } else { tool.WorldSpacePivotCenter = displayNewCenter; } } } EditorGUI.EndDisabledGroup(); } /* * if (Tools.current != Tool.Rotate) * { * if (!isSceneGUI || !SceneView.currentDrawingSceneView.camera.orthographic) * { * if (!isSceneGUI) * { * GUILayout.Space(10); * GUILayout.Label("Tips", EditorStyles.miniLabel); * } * * GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); * { * GUILayout.Label(Keys.VerticalMoveMode.ToString() + " to drag brush up/down", EditorStyles.miniLabel); * } * GUILayout.EndVertical(); * } * } */ } GUILayout.EndVertical(); EditorGUI.showMixedValue = false; }
static void CommitOrCancel(bool isSceneGUI, GenerateBrushTool tool) { var defaultMaterial = CSGSettings.DefaultMaterial; GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { GUILayout.Space(5); GUILayout.BeginVertical(GUILayout.MinWidth(10)); { EditorGUI.BeginChangeCheck(); { defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial); } if (EditorGUI.EndChangeCheck() && defaultMaterial) { CSGSettings.DefaultMaterial = defaultMaterial; tool.CurrentGenerator.OnDefaultMaterialModified(); CSGSettings.Save(); } } GUILayout.EndVertical(); GUILayout.Space(4); GUILayout.BeginVertical(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(GenerateBrushTool tool, bool isSceneGUI, float height) { if (!isSceneGUI) { Rect shapeModeBounds; var csg_skin = GUIStyleUtility.Skin; tool.BuilderMode = (ShapeMode)GUIStyleUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: GUIStyleUtility.shapeModeTooltips, yOffset: height, areaWidth: EditorGUIUtility.currentViewWidth - 4); GUILayout.Space(shapeModeBounds.height); CommonGUI.StartToolGUI(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); { ChooseOperation(tool, isSceneGUI); tool.CurrentGenerator.OnShowGUI(isSceneGUI); CommitOrCancel(isSceneGUI, tool); EditorGUILayout.Space(); var defaultMaterial = CSGSettings.DefaultMaterial; GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth); GUILayout.BeginVertical(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(GUIStyleUtility.ContentEmpty); { GUILayout.Space(5); EditorGUI.BeginChangeCheck(); { defaultMaterial = GUIStyleUtility.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 = GUIStyleUtility.Skin; Rect shapeModeBounds; tool.BuilderMode = (ShapeMode)GUIStyleUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: GUIStyleUtility.shapeModeTooltips, yOffset: rect.y, areaWidth: 100); GUILayout.Space(shapeModeBounds.height); ChooseOperation(tool, isSceneGUI); } GUILayout.EndVertical(); GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); { tool.CurrentGenerator.OnShowGUI(isSceneGUI); GUILayout.FlexibleSpace(); CommitOrCancel(isSceneGUI, tool); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } }
public static void OnSceneGUI(Rect windowRect, MeshEditBrushTool tool) { GUIStyleUtility.InitStyles(); InitLocalStyles(); GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); { GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); { GUILayout.FlexibleSpace(); GUIStyleUtility.ResetGUIState(); GUIStyle windowStyle = GUI.skin.window; GUILayout.BeginVertical(ContentMeshLabel, windowStyle, GUIStyleUtility.ContentEmpty); { OnGUIContents(true, tool); } GUILayout.EndVertical(); var currentArea = GUILayoutUtility.GetLastRect(); lastGuiRect = currentArea; var buttonArea = currentArea; buttonArea.x += buttonArea.width - 17; buttonArea.y += 2; buttonArea.height = 13; buttonArea.width = 13; if (GUI.Button(buttonArea, GUIContent.none, "WinBtnClose")) { CSGBrushEditorWindow.GetWindow(); } TooltipUtility.SetToolTip(GUIStyleUtility.PopOutTooltip, buttonArea); int controlID = GUIUtility.GetControlID(SceneViewMeshOverlayHash, FocusType.Keyboard, currentArea); switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: { if (currentArea.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; Event.current.Use(); } break; } case EventType.MouseMove: { if (currentArea.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 (currentArea.Contains(Event.current.mousePosition)) { Event.current.Use(); } break; } } } GUILayout.EndVertical(); } GUILayout.EndVertical(); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); }
protected override void HandleEditShapeEvents(Rect sceneRect) { if (settings.vertices.Length < 2) { if (editMode == EditMode.ExtrudeShape || editMode == EditMode.EditShape) { editMode = EditMode.CreatePlane; } } if (!SceneTools.IsDraggingObjectInScene && Event.current.type == EventType.Repaint) { if (visualSnappedEdges != null) { PaintUtility.DrawLines(visualSnappedEdges.ToArray(), ToolConstants.oldThickLineScale, ColorSettings.SnappedEdges); } if (visualSnappedGrid != null) { var _origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges); Handles.matrix = _origMatrix; } if (visualSnappedBrush != null) { var brush_cache = InternalCSGModelManager.GetBrushCache(visualSnappedBrush); if (brush_cache != null && brush_cache.compareTransformation != null && brush_cache.childData != null && brush_cache.childData.ModelTransform != null && brush_cache.childData.ModelTransform) { var brush_translation = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position; CSGRenderer.DrawOutlines(visualSnappedBrush.brushID, brush_translation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines); } } var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; PaintBounds(); Handles.matrix = origMatrix; } HandleHeightHandles(sceneRect, false); for (int i = 0; i < settings.vertices.Length; i++) { var id = settings.vertexIDs[i]; var point_type = Event.current.GetTypeForControl(id); switch (point_type) { case EventType.Repaint: { if (SceneTools.IsDraggingObjectInScene) { break; } bool isSelected = id == GUIUtility.keyboardControl; var temp = Handles.color; var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; var rotation = Camera.current.transform.rotation; if (isSelected) { Handles.color = ColorSettings.PointInnerStateColor[3]; } else if (HandleUtility.nearestControl == id) { Handles.color = ColorSettings.PointInnerStateColor[1]; } else { Handles.color = ColorSettings.PointInnerStateColor[0]; } float handleSize = GUIStyleUtility.GetHandleSize(settings.vertices[i]); float scaledHandleSize = handleSize * ToolConstants.handleScale; PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize); Handles.matrix = origMatrix; Handles.color = temp; break; } case EventType.layout: { if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)) { break; } var origMatrix = Handles.matrix; Handles.matrix = MathConstants.identityMatrix; float handleSize = GUIStyleUtility.GetHandleSize(settings.vertices[i]); float scaledHandleSize = handleSize * ToolConstants.handleScale; HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(settings.vertices[i], scaledHandleSize)); Handles.matrix = origMatrix; break; } case EventType.ValidateCommand: case EventType.keyDown: { if (GUIUtility.hotControl == id) { if (Keys.CancelActionKey.IsKeyPressed()) { Event.current.Use(); break; } } break; } case EventType.keyUp: { if (GUIUtility.hotControl == id) { if (Keys.CancelActionKey.IsKeyPressed()) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; EditorGUIUtility.editingTextField = false; Event.current.Use(); break; } } break; } case EventType.MouseDown: { if (!sceneRect.Contains(Event.current.mousePosition)) { break; } if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan) { break; } if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id && Event.current.button == 0) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; EditorGUIUtility.editingTextField = false; EditorGUIUtility.SetWantsMouseJumping(1); Event.current.Use(); break; } break; } case EventType.MouseDrag: { if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan) { break; } if (GUIUtility.hotControl == id && Event.current.button == 0) { Undo.RecordObject(this, "Modify shape"); var mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); Grid.SetForcedGrid(buildPlane); var alignedPlane = new CSGPlane(Grid.CurrentWorkGridPlane.normal, settings.vertices[0]); var worldPosition = buildPlane.Project(alignedPlane.Intersection(mouseRay)); if (float.IsInfinity(worldPosition.x) || float.IsNaN(worldPosition.x) || float.IsInfinity(worldPosition.y) || float.IsNaN(worldPosition.y) || float.IsInfinity(worldPosition.z) || float.IsNaN(worldPosition.z)) { worldPosition = settings.vertices[i]; } ResetVisuals(); if (snapFunction != null) { CSGBrush snappedOnBrush; worldPosition = snapFunction(worldPosition, buildPlane, ref base.visualSnappedEdges, out snappedOnBrush, generatedBrushes); } base.visualSnappedGrid = Grid.FindAllGridEdgesThatTouchPoint(worldPosition); settings.vertices[i] = worldPosition; CenterExtrusionPoints(buildPlane); UpdateBaseShape(); if (editMode == EditMode.ExtrudeShape) { StartExtrudeMode(); } UpdateBaseShape(); UpdateExtrudedShape(); GUI.changed = true; Event.current.Use(); break; } break; } case EventType.MouseUp: { if (GUIUtility.hotControl != id) { break; } if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan) { break; } if (Event.current.button == 0) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; EditorGUIUtility.editingTextField = false; EditorGUIUtility.SetWantsMouseJumping(0); Event.current.Use(); ResetVisuals(); //if (Length == 0 || Width == 0) //{ // Cancel(); //} break; } break; } } } }