void DrawShapeGUI() { if (m_BoldCenteredStyle == null) { m_BoldCenteredStyle = new GUIStyle("BoldLabel") { alignment = TextAnchor.MiddleCenter } } ; EditorGUILayout.LabelField(EditorShapeUtility.shapeTypes[s_ActiveShapeIndex.value], m_BoldCenteredStyle, GUILayout.ExpandWidth(true)); if (EditorShapeUtility.s_ResetUserPrefs.value) { ResetPrefs(); } var shape = currentShapeInOverlay.shape; int groupCount = EditorShapeUtility.shapeTypesGUI.Count; for (int i = 0; i < groupCount; i++) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); int index = GUILayout.Toolbar(s_ActiveShapeIndex.value - +i * EditorShapeUtility.MaxContentPerGroup, EditorShapeUtility.shapeTypesGUI[i], Styles.command); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { s_ActiveShapeIndex.value = index + i * EditorShapeUtility.MaxContentPerGroup; var type = EditorShapeUtility.availableShapeTypes[s_ActiveShapeIndex]; if (shape.GetType() != type) { if (currentShapeInOverlay == m_LastShapeCreated) { m_LastShapeCreated = null; } UndoUtility.RegisterCompleteObjectUndo(currentShapeInOverlay, "Change Shape"); Selection.activeObject = null; currentShapeInOverlay.SetShape(EditorShapeUtility.CreateShape(type), currentShapeInOverlay.pivotLocation); SetBounds(currentShapeInOverlay.size); ProBuilderEditor.Refresh(); } } } } }
void ResetPrefs() { var type = EditorShapeUtility.availableShapeTypes[s_ActiveShapeIndex]; if (currentShapeInOverlay == m_LastShapeCreated) { m_LastShapeCreated = null; } UndoUtility.RegisterCompleteObjectUndo(currentShapeInOverlay, "Change Shape"); currentShapeInOverlay.SetShape(EditorShapeUtility.CreateShape(type), currentShapeInOverlay.pivotLocation); SetBounds(currentShapeInOverlay.size); ProBuilderEditor.Refresh(); }
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; }