static void DoOrientationHandles(ProBuilderShape proBuilderShape, bool updatePrefs) { if (GUIUtility.hotControl != 0 && !k_OrientationControlIDs.Contains(GUIUtility.hotControl)) { return; } foreach (var f in faces) { if (f.IsVisible && EditorShapeUtility.PointerIsInFace(f)) { if (DoOrientationHandle(f, proBuilderShape)) { UndoUtility.RecordComponents <Transform, ProBuilderMesh, ProBuilderShape>(proBuilderShape.GetComponents(typeof(Component)), "Rotate Shape"); proBuilderShape.RotateInsideBounds(s_ShapeRotation); ProBuilderEditor.Refresh(); if (updatePrefs) { DrawShapeTool.SaveShapeParams(proBuilderShape); } } } } }
void SetPolyEditMode(PolyShape.PolyEditMode mode) { if (polygon == null) { return; } PolyShape.PolyEditMode old = polygon.polyEditMode; if (mode != old) { GUIUtility.hotControl = 0; // Entering edit mode after the shape has been finalized once before, which means // possibly reverting manual changes. Store undo state so that if this was // not intentional user can revert. if (old == PolyShape.PolyEditMode.None && polygon.m_Points.Count > 2) { if (ProBuilderEditor.instance != null) { ProBuilderEditor.instance.ClearElementSelection(); } UndoUtility.RecordComponents <ProBuilderMesh, PolyShape>(polygon.GetComponents(typeof(Component)), "Edit Polygon Shape"); } polygon.polyEditMode = mode; // If coming from Path -> Height set the mouse / origin offset if (old == PolyShape.PolyEditMode.Path && mode == PolyShape.PolyEditMode.Height && Event.current != null) { Vector3 up = polygon.transform.up; Vector3 origin = polygon.transform.TransformPoint(Math.Average(polygon.m_Points)); Ray r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); Vector3 p = Math.GetNearestPointRayRay(origin, up, r.origin, r.direction); float extrude = Vector3.Distance(origin, p) * Mathf.Sign(Vector3.Dot(p - origin, up)); s_HeightMouseOffset = polygon.extrude - EditorSnapping.MoveSnap(extrude); } else if (old == PolyShape.PolyEditMode.Path && mode == PolyShape.PolyEditMode.None) { var go = polygon.gameObject; EditorApplication.delayCall += () => DestroyImmediate(go); return; } RebuildPolyShapeMesh(polygon); //Dirty the polygon for serialization (fix for transition between prefab and scene mode) if (polygon != null) { UnityEditor.EditorUtility.SetDirty(polygon); } } }
static void ApplyProperties(ProBuilderShape proBuilderShape, Vector3 newCenterPosition, Vector3 newSize) { var bounds = new Bounds(); bounds.center = newCenterPosition; bounds.size = newSize; UndoUtility.RecordComponents <Transform, ProBuilderMesh, ProBuilderShape>(proBuilderShape.GetComponents(typeof(Component)), "Resize Shape"); proBuilderShape.UpdateBounds(bounds); ProBuilderEditor.Refresh(false); }
public void DrawShapeGUI(DrawShapeTool tool = null) { if (target == null || serializedObject == null) { return; } serializedObject.Update(); int editedShapesCount = 0; foreach (var comp in targets) { editedShapesCount += ((ShapeComponent)comp).isEditable ? 0 : 1; } if (editedShapesCount > 0) { EditorGUILayout.BeginVertical(); EditorGUILayout.HelpBox( L10n.Tr( "You have manually modified Shape(s). Revert manual changes to access to procedural parameters"), MessageType.Info); if (GUILayout.Button("Reset Shape")) { foreach (var comp in targets) { var shapeComponent = comp as ShapeComponent; UndoUtility.RecordComponents <Transform, ProBuilderMesh, ShapeComponent>(shapeComponent.GetComponents(typeof(Component)), "Reset Shape"); shapeComponent.UpdateComponent(); ProBuilderEditor.Refresh(); } } EditorGUILayout.EndHorizontal(); } if (editedShapesCount == targets.Length) { GUI.enabled = false; } }
static void ApplyMaterial(IEnumerable <ProBuilderMesh> selection, Material mat) { if (mat == null) { return; } UndoUtility.RecordComponents <MeshRenderer, ProBuilderMesh>(selection, "Set Material"); foreach (var mesh in selection) { var applyPerFace = ProBuilderEditor.selectMode.ContainsFlag(SelectMode.Face) && mesh.faceCount > 0; mesh.SetMaterial(applyPerFace ? mesh.GetSelectedFaces() : mesh.facesInternal, mat); InternalMeshUtility.FilterUnusedSubmeshIndexes(mesh); mesh.Rebuild(); mesh.Optimize(); } if (ProBuilderEditor.instance != null && MeshSelection.selectedFaceCount > 0) { EditorUtility.ShowNotification("Set Material\n" + mat.name); } }
public void DrawShapeParametersGUI(DrawShapeTool tool = null) { if (target == null || serializedObject == null) { return; } serializedObject.Update(); var foldoutEnabled = tool == null ? s_foldoutEnabled : DrawShapeTool.s_SettingsEnabled.value; foldoutEnabled = EditorGUILayout.Foldout(foldoutEnabled, m_ShapePropertyLabel, true); if (tool == null) { s_foldoutEnabled = foldoutEnabled; } else { DrawShapeTool.s_SettingsEnabled.value = foldoutEnabled; } if (foldoutEnabled) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); m_ActiveShapeIndex = HasMultipleShapeTypes ? -1 : Mathf.Max(-1, Array.IndexOf(EditorShapeUtility.availableShapeTypes, m_CurrentShapeType)); m_ActiveShapeIndex = EditorGUILayout.Popup(m_ActiveShapeIndex, EditorShapeUtility.shapeTypes); if (EditorGUI.EndChangeCheck()) { var type = EditorShapeUtility.availableShapeTypes[m_ActiveShapeIndex]; foreach (var comp in targets) { ShapeComponent shapeComponent = ((ShapeComponent)comp); Shape shape = shapeComponent.shape; if (shape.GetType() != type) { if (tool != null) { DrawShapeTool.s_ActiveShapeIndex.value = m_ActiveShapeIndex; } UndoUtility.RecordComponents <Transform, ProBuilderMesh, ShapeComponent>(shapeComponent.GetComponents(typeof(Component)), "Change Shape"); shapeComponent.SetShape(EditorShapeUtility.CreateShape(type), shapeComponent.pivotLocation); ProBuilderEditor.Refresh(); } } } if (tool) { EditorGUILayout.PropertyField(m_ShapePivotProperty, k_ShapePivotLabel); } EditorGUILayout.PropertyField(m_ShapeSizeXProperty, k_ShapeSizeXLabel); if (HasMultipleShapeTypes || (m_CurrentShapeType != typeof(Plane) && m_CurrentShapeType != typeof(Sprite))) { EditorGUILayout.PropertyField(m_ShapeSizeYProperty, k_ShapeSizeYLabel); } EditorGUILayout.PropertyField(m_ShapeSizeZProperty, k_ShapeSizeZLabel); EditorGUI.indentLevel--; } if (!HasMultipleShapeTypes) { EditorGUILayout.PropertyField(m_ShapeProperty, new GUIContent("Shape Properties"), true); } if (serializedObject.ApplyModifiedProperties()) { foreach (var comp in targets) { var shapeComponent = comp as ShapeComponent; if (shapeComponent.isEditable) { UndoUtility.RecordComponents <Transform, ProBuilderMesh, ShapeComponent>(shapeComponent.GetComponents(typeof(Component)), "Resize Shape"); shapeComponent.UpdateComponent(); if (tool != null) { tool.SetBounds(shapeComponent.size); DrawShapeTool.SaveShapeParams(shapeComponent); } ProBuilderEditor.Refresh(); } } } GUI.enabled = true; }
public override void OnInspectorGUI() { switch (polygon.polyEditMode) { case PolyShape.PolyEditMode.None: { if (GUILayout.Button("Edit Poly Shape")) { ProBuilderEditor.selectMode = SelectMode.Object; polygon.polyEditMode = PolyShape.PolyEditMode.Edit; PolyShapeTool tool = CreateInstance <PolyShapeTool>(); tool.polygon = polygon; ToolManager.SetActiveTool(tool); Undo.RegisterCreatedObjectUndo(tool, "Open Polyshape Tool"); } EditorGUILayout.HelpBox( "Editing a poly shape will erase any modifications made to the mesh!\n\nIf you accidentally enter Edit Mode you can Undo to get your changes back.", MessageType.Warning); break; } case PolyShape.PolyEditMode.Path: { EditorGUILayout.HelpBox("\nClick To Add Points\n\nPress 'Enter' or 'Space' to Set Height\n", MessageType.Info); break; } case PolyShape.PolyEditMode.Height: { EditorGUILayout.HelpBox("\nMove Mouse to Set Height\n\nPress 'Enter' or 'Space' to Finalize\n", MessageType.Info); break; } case PolyShape.PolyEditMode.Edit: { EditorGUILayout.HelpBox("\nMove Poly Shape points to update the shape\n\nPress 'Enter' or 'Space' to Finalize\n", MessageType.Info); break; } } EditorGUI.BeginChangeCheck(); float extrude = polygon.extrude; extrude = EditorGUILayout.FloatField("Extrusion", extrude); bool flipNormals = polygon.flipNormals; flipNormals = EditorGUILayout.Toggle("Flip Normals", flipNormals); if (EditorGUI.EndChangeCheck()) { if (polygon.polyEditMode == PolyShape.PolyEditMode.None) { if (ProBuilderEditor.instance != null) { ProBuilderEditor.instance.ClearElementSelection(); } UndoUtility.RecordComponents <ProBuilderMesh, PolyShape>(polygon.GetComponents(typeof(Component)), "Edit Polygon Shape"); } else { UndoUtility.RecordObject(polygon, "Change Polygon Shape Settings"); } polygon.extrude = extrude; polygon.flipNormals = flipNormals; RebuildPolyShapeMesh(polygon); } }