public static bool OnGUI(ProBuilderMesh[] selection, float width) { UpdateDiffDictionary(selection); s_ScrollPosition = EditorGUILayout.BeginScrollView(s_ScrollPosition); float tempFloat = 0f; EditorGUI.BeginChangeCheck(); /** * Set Tile mode */ GUILayout.Label("Tiling & Alignment", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["fill"]; GUILayout.Label("Fill Mode", GUILayout.MaxWidth(80), GUILayout.MinWidth(80)); EditorGUI.BeginChangeCheck(); s_AutoUVSettings.fill = (AutoUnwrapSettings.Fill)EditorGUILayout.EnumPopup(s_AutoUVSettings.fill); if (EditorGUI.EndChangeCheck()) { SetFill(s_AutoUVSettings.fill, selection); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool enabled = GUI.enabled; GUI.enabled = !s_AutoUVSettings.useWorldSpace; EditorGUI.showMixedValue = s_AutoUVSettingsDiff["anchor"]; EditorGUI.BeginChangeCheck(); GUILayout.Label("Anchor", GUILayout.MaxWidth(80), GUILayout.MinWidth(80)); s_AutoUVSettings.anchor = (AutoUnwrapSettings.Anchor)EditorGUILayout.EnumPopup(s_AutoUVSettings.anchor); if (EditorGUI.EndChangeCheck()) { SetAnchor(s_AutoUVSettings.anchor, selection); } GUI.enabled = enabled; GUILayout.EndHorizontal(); GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Label("Transform", EditorStyles.boldLabel); /** * Offset */ EditorGUI.showMixedValue = s_AutoUVSettingsDiff["offsetx"] || s_AutoUVSettingsDiff["offsety"]; var tempVec2 = s_AutoUVSettings.offset; UnityEngine.GUI.SetNextControlName("offset"); s_AutoUVSettings.offset = EditorGUILayout.Vector2Field("Offset", s_AutoUVSettings.offset, GUILayout.MaxWidth(width)); if (tempVec2.x != s_AutoUVSettings.offset.x) { SetOffset(s_AutoUVSettings.offset, Axis2D.X, selection); } if (tempVec2.y != s_AutoUVSettings.offset.y) { SetOffset(s_AutoUVSettings.offset, Axis2D.Y, selection); } /** * Rotation */ tempFloat = s_AutoUVSettings.rotation; EditorGUI.showMixedValue = s_AutoUVSettingsDiff["rotation"]; GUILayout.Label(new GUIContent("Rotation", "Rotation around the center of face UV bounds."), GUILayout.MaxWidth(width - 64)); UnityEngine.GUI.SetNextControlName("rotation"); EditorGUI.BeginChangeCheck(); tempFloat = EditorGUILayout.Slider(tempFloat, 0f, 360f, GUILayout.MaxWidth(width)); if (EditorGUI.EndChangeCheck()) { SetRotation(tempFloat, selection); } /** * Scale */ EditorGUI.showMixedValue = s_AutoUVSettingsDiff["scalex"] || s_AutoUVSettingsDiff["scaley"]; tempVec2 = s_AutoUVSettings.scale; GUI.SetNextControlName("scale"); EditorGUI.BeginChangeCheck(); s_AutoUVSettings.scale = EditorGUILayout.Vector2Field("Tiling", s_AutoUVSettings.scale, GUILayout.MaxWidth(width)); if (EditorGUI.EndChangeCheck()) { if (tempVec2.x != s_AutoUVSettings.scale.x) { SetScale(s_AutoUVSettings.scale, Axis2D.X, selection); } if (tempVec2.y != s_AutoUVSettings.scale.y) { SetScale(s_AutoUVSettings.scale, Axis2D.Y, selection); } } // Draw tiling shortcuts GUILayout.BeginHorizontal(); if (GUILayout.Button(".5", EditorStyles.miniButtonLeft)) { SetScale(Vector2.one * 2f, Axis2D.XY, selection); } if (GUILayout.Button("1", EditorStyles.miniButtonMid)) { SetScale(Vector2.one, Axis2D.XY, selection); } if (GUILayout.Button("2", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .5f, Axis2D.XY, selection); } if (GUILayout.Button("4", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .25f, Axis2D.XY, selection); } if (GUILayout.Button("8", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .125f, Axis2D.XY, selection); } if (GUILayout.Button("16", EditorStyles.miniButtonRight)) { SetScale(Vector2.one * .0625f, Axis2D.XY, selection); } GUILayout.EndHorizontal(); GUILayout.Space(4); UnityEngine.GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); UnityEngine.GUI.backgroundColor = Color.white; /** * Special */ GUILayout.Label("Special", EditorStyles.boldLabel); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["useWorldSpace"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.useWorldSpace = EditorGUILayout.Toggle("World Space", s_AutoUVSettings.useWorldSpace); if (EditorGUI.EndChangeCheck()) { SetUseWorldSpace(s_AutoUVSettings.useWorldSpace, selection); } GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; // Flip U EditorGUI.showMixedValue = s_AutoUVSettingsDiff["flipU"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.flipU = EditorGUILayout.Toggle("Flip U", s_AutoUVSettings.flipU); if (EditorGUI.EndChangeCheck()) { SetFlipU(s_AutoUVSettings.flipU, selection); } // Flip V EditorGUI.showMixedValue = s_AutoUVSettingsDiff["flipV"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.flipV = EditorGUILayout.Toggle("Flip V", s_AutoUVSettings.flipV); if (EditorGUI.EndChangeCheck()) { SetFlipV(s_AutoUVSettings.flipV, selection); } EditorGUI.showMixedValue = s_AutoUVSettingsDiff["swapUV"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.swapUV = EditorGUILayout.Toggle("Swap U/V", s_AutoUVSettings.swapUV); if (EditorGUI.EndChangeCheck()) { SetSwapUV(s_AutoUVSettings.swapUV, selection); } /** * Texture Groups */ GUILayout.Label("Texture Groups", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["textureGroup"]; GUI.SetNextControlName("textureGroup"); textureGroup = UI.EditorGUIUtility.IntFieldConstrained(new GUIContent("Texture Group", "Faces in a texture group will be UV mapped as a group, just as though you had selected these faces and used the \"Planar Project\" action"), textureGroup, (int)width); if (EditorGUI.EndChangeCheck()) { SetTextureGroup(selection, textureGroup); foreach (var kvp in MeshSelection.selectedFacesInEditZone) { kvp.Key.RefreshUV(kvp.Value); } SceneView.RepaintAll(); s_AutoUVSettingsDiff["textureGroup"] = false; } if (GUILayout.Button(new GUIContent("Group Selected Faces", "This sets all selected faces to share a texture group. What that means is that the UVs on these faces will all be projected as though they are a single plane. Ideal candidates for texture groups are floors with multiple faces, walls with edge loops, flat surfaces, etc."))) { for (int i = 0; i < selection.Length; i++) { TextureGroupSelectedFaces(selection[i]); } ProBuilderEditor.Refresh(); } if (GUILayout.Button(new GUIContent("Break Selected Groups", "This resets all the selected face Texture Groups."))) { SetTextureGroup(selection, -1); foreach (var kvp in MeshSelection.selectedFacesInEditZone) { kvp.Key.ToMesh(); kvp.Key.Refresh(); kvp.Key.Optimize(); } SceneView.RepaintAll(); s_AutoUVSettingsDiff["textureGroup"] = false; ProBuilderEditor.Refresh(); } /* Select all in current texture group */ if (GUILayout.Button(new GUIContent("Select Texture Group", "Selects all faces contained in this texture group."))) { for (int i = 0; i < selection.Length; i++) { selection[i].SetSelectedFaces(System.Array.FindAll(selection[i].facesInternal, x => x.textureGroup == textureGroup)); } ProBuilderEditor.Refresh(); } if (GUILayout.Button(new GUIContent("Reset UVs", "Reset UV projection parameters."))) { UndoUtility.RecordSelection(selection, "Reset UVs"); for (int i = 0; i < selection.Length; i++) { foreach (Face face in selection[i].GetSelectedFaces()) { face.uv = AutoUnwrapSettings.tile; face.textureGroup = -1; face.elementGroup = -1; } UVEditing.SplitUVs(selection[i], selection[i].GetSelectedFaces()); } ProBuilderEditor.Refresh(); } GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; /** * Clean up */ GUILayout.EndScrollView(); EditorGUI.showMixedValue = false; return(EditorGUI.EndChangeCheck()); }
public static bool OnGUI(ProBuilderMesh[] selection, float width) { UpdateDiffDictionary(selection); s_ScrollPosition = EditorGUILayout.BeginScrollView(s_ScrollPosition); float tempFloat = 0f; EditorGUI.BeginChangeCheck(); // Set Tile mode GUILayout.Label("Tiling & Alignment", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["fill"]; GUILayout.Label(gc_FillMode, GUILayout.MaxWidth(80), GUILayout.MinWidth(80)); EditorGUI.BeginChangeCheck(); s_AutoUVSettings.fill = (AutoUnwrapSettings.Fill)EditorGUILayout.EnumPopup(s_AutoUVSettings.fill); if (EditorGUI.EndChangeCheck()) { SetFill(s_AutoUVSettings.fill, selection); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool enabled = GUI.enabled; GUI.enabled = !s_AutoUVSettings.useWorldSpace; EditorGUI.showMixedValue = s_AutoUVSettingsDiff["anchor"]; EditorGUI.BeginChangeCheck(); GUILayout.Label(gc_Anchor, GUILayout.MaxWidth(80), GUILayout.MinWidth(80)); s_AutoUVSettings.anchor = (AutoUnwrapSettings.Anchor)EditorGUILayout.EnumPopup(s_AutoUVSettings.anchor); if (EditorGUI.EndChangeCheck()) { SetAnchor(s_AutoUVSettings.anchor, selection); } GUI.enabled = enabled; GUILayout.EndHorizontal(); GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Label("Transform", EditorStyles.boldLabel); //Offset EditorGUI.showMixedValue = s_AutoUVSettingsDiff["offsetx"] || s_AutoUVSettingsDiff["offsety"]; var tempVec2 = s_AutoUVSettings.offset; UnityEngine.GUI.SetNextControlName("offset"); s_AutoUVSettings.offset = EditorGUILayout.Vector2Field(gc_Offset, s_AutoUVSettings.offset, GUILayout.MaxWidth(width)); if (tempVec2.x != s_AutoUVSettings.offset.x) { SetOffset(s_AutoUVSettings.offset, Axis2D.X, selection); } if (tempVec2.y != s_AutoUVSettings.offset.y) { SetOffset(s_AutoUVSettings.offset, Axis2D.Y, selection); } // Rotation tempFloat = s_AutoUVSettings.rotation; EditorGUI.showMixedValue = s_AutoUVSettingsDiff["rotation"]; GUILayout.Label(gc_Rotation, GUILayout.MaxWidth(width - 64)); UnityEngine.GUI.SetNextControlName("rotation"); EditorGUI.BeginChangeCheck(); tempFloat = EditorGUILayout.Slider(tempFloat, 0f, 360f, GUILayout.MaxWidth(width)); if (EditorGUI.EndChangeCheck()) { SetRotation(tempFloat, selection); } // Scale EditorGUI.showMixedValue = s_AutoUVSettingsDiff["scalex"] || s_AutoUVSettingsDiff["scaley"]; tempVec2 = s_AutoUVSettings.scale; GUI.SetNextControlName("scale"); EditorGUI.BeginChangeCheck(); s_AutoUVSettings.scale = EditorGUILayout.Vector2Field(gc_Tiling, s_AutoUVSettings.scale, GUILayout.MaxWidth(width)); if (EditorGUI.EndChangeCheck()) { if (tempVec2.x != s_AutoUVSettings.scale.x) { SetScale(s_AutoUVSettings.scale, Axis2D.X, selection); } if (tempVec2.y != s_AutoUVSettings.scale.y) { SetScale(s_AutoUVSettings.scale, Axis2D.Y, selection); } } // Draw tiling shortcuts GUILayout.BeginHorizontal(); if (GUILayout.Button(".5", EditorStyles.miniButtonLeft)) { SetScale(Vector2.one * 2f, Axis2D.XY, selection); } if (GUILayout.Button("1", EditorStyles.miniButtonMid)) { SetScale(Vector2.one, Axis2D.XY, selection); } if (GUILayout.Button("2", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .5f, Axis2D.XY, selection); } if (GUILayout.Button("4", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .25f, Axis2D.XY, selection); } if (GUILayout.Button("8", EditorStyles.miniButtonMid)) { SetScale(Vector2.one * .125f, Axis2D.XY, selection); } if (GUILayout.Button("16", EditorStyles.miniButtonRight)) { SetScale(Vector2.one * .0625f, Axis2D.XY, selection); } GUILayout.EndHorizontal(); GUILayout.Space(4); UnityEngine.GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); UnityEngine.GUI.backgroundColor = Color.white; // Special GUILayout.Label("Special", EditorStyles.boldLabel); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["useWorldSpace"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.useWorldSpace = EditorGUILayout.Toggle(gc_WorldSpace, s_AutoUVSettings.useWorldSpace); if (EditorGUI.EndChangeCheck()) { SetUseWorldSpace(s_AutoUVSettings.useWorldSpace, selection); } GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; // Flip U EditorGUI.showMixedValue = s_AutoUVSettingsDiff["flipU"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.flipU = EditorGUILayout.Toggle(gc_FlipU, s_AutoUVSettings.flipU); if (EditorGUI.EndChangeCheck()) { SetFlipU(s_AutoUVSettings.flipU, selection); } // Flip V EditorGUI.showMixedValue = s_AutoUVSettingsDiff["flipV"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.flipV = EditorGUILayout.Toggle(gc_FlipV, s_AutoUVSettings.flipV); if (EditorGUI.EndChangeCheck()) { SetFlipV(s_AutoUVSettings.flipV, selection); } EditorGUI.showMixedValue = s_AutoUVSettingsDiff["swapUV"]; EditorGUI.BeginChangeCheck(); s_AutoUVSettings.swapUV = EditorGUILayout.Toggle(gc_SwapUV, s_AutoUVSettings.swapUV); if (EditorGUI.EndChangeCheck()) { SetSwapUV(s_AutoUVSettings.swapUV, selection); } // Texture Groups GUILayout.Label("Texture Groups", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = s_AutoUVSettingsDiff["textureGroup"]; GUI.SetNextControlName("textureGroup"); textureGroup = UI.EditorGUIUtility.IntFieldConstrained(gc_TextureGroup, textureGroup, (int)width); if (EditorGUI.EndChangeCheck()) { SetTextureGroup(selection, textureGroup); foreach (var kvp in MeshSelection.selectedFacesInEditZone) { kvp.Key.RefreshUV(kvp.Value); } SceneView.RepaintAll(); s_AutoUVSettingsDiff["textureGroup"] = false; } if (GUILayout.Button(gc_GroupSelected)) { for (int i = 0; i < selection.Length; i++) { TextureGroupSelectedFaces(selection[i]); } ProBuilderEditor.Refresh(); } if (GUILayout.Button(gc_BreakSelected)) { SetTextureGroup(selection, -1); foreach (var kvp in MeshSelection.selectedFacesInEditZone) { kvp.Key.ToMesh(); kvp.Key.Refresh(); kvp.Key.Optimize(); } SceneView.RepaintAll(); s_AutoUVSettingsDiff["textureGroup"] = false; ProBuilderEditor.Refresh(); } /* Select all in current texture group */ if (GUILayout.Button(gc_SelectGroup)) { for (int i = 0; i < selection.Length; i++) { selection[i].SetSelectedFaces(System.Array.FindAll(selection[i].facesInternal, x => x.textureGroup == textureGroup)); } ProBuilderEditor.Refresh(); } if (GUILayout.Button(gc_Reset)) { UndoUtility.RecordSelection(selection, "Reset UVs"); for (int i = 0; i < selection.Length; i++) { foreach (Face face in selection[i].GetSelectedFaces()) { face.uv = AutoUnwrapSettings.tile; face.textureGroup = -1; face.elementGroup = -1; } UVEditing.SplitUVs(selection[i], selection[i].GetSelectedFaces()); } ProBuilderEditor.Refresh(); } GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.EndScrollView(); EditorGUI.showMixedValue = false; return(EditorGUI.EndChangeCheck()); }