void OnGUI() { Event e = Event.current; z_GUI.PushGUISkin(z_GUI.PolybrushSkin); if(e.type == EventType.ContextClick) OpenContextMenu(); GUILayout.Space(8); EditorGUI.BeginChangeCheck(); int toolbarIndex = (int) tool - 1; toolbarIndex = GUILayout.Toolbar(toolbarIndex, modeIcons, "Mode"); if(EditorGUI.EndChangeCheck()) { z_BrushTool newTool = (z_BrushTool) (toolbarIndex + 1); SetTool( newTool == tool ? z_BrushTool.None : (z_BrushTool)toolbarIndex + 1 ); } // Call current mode GUI if(mode != null && tool != z_BrushTool.Settings) { if(!z_Pref.GetBool(z_Pref.lockBrushSettings)) { z_GUI.PopGUISkin(); scroll = EditorGUILayout.BeginScrollView(scroll); z_GUI.PushGUISkin(z_GUI.PolybrushSkin); } // Show the settings header in z_Editor so that the preset selector can be included in the block. // Can't move preset selector to z_BrushSettingsEditor because it's a CustomEditor for z_BrushSettings, //commented out code was ommited here if(z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Settings"))) Application.OpenURL("http://procore3d.github.io/polybrush/brushSettings/"); /** * Brush preset selector */ GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); currentBrushIndex = EditorGUILayout.Popup(currentBrushIndex, availableBrushes_str, "Popup"); if(EditorGUI.EndChangeCheck()) { if(currentBrushIndex >= availableBrushes.Count) SetBrushSettings(z_BrushSettingsEditor.AddNew()); else SetBrushSettings(availableBrushes[currentBrushIndex]); } if(GUILayout.Button( gc_SaveBrushSettings, GUILayout.Width(40) )) { if(brushSettings != null && brushSettingsAsset != null) { // integer 0, 1 or 2 corresponding to ok, cancel and alt buttons int res = EditorUtility.DisplayDialogComplex("Save Brush Settings", "Overwrite brush preset or save as a new preset? ", "Save", "Save As", "Cancel"); if(res == 0) { brushSettings.CopyTo(brushSettingsAsset); EditorGUIUtility.PingObject(brushSettingsAsset); } else if(res == 1) { z_BrushSettings dup = z_BrushSettingsEditor.AddNew(); string name = dup.name; brushSettings.CopyTo(dup); dup.name = name; // want to retain the unique name generated by AddNew() SetBrushSettings(dup); EditorGUIUtility.PingObject(brushSettingsAsset); } } else { Debug.LogWarning("Something went wrong saving brush settings."); } } GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); brushEditor.OnInspectorGUI(); if(z_Pref.GetBool(z_Pref.lockBrushSettings)) { z_GUI.PopGUISkin(); scroll = EditorGUILayout.BeginScrollView(scroll); z_GUI.PushGUISkin(z_GUI.PolybrushSkin); //commented out code was ommited here /** * Mirroring */ if(z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Mirroring"))) Application.OpenURL("http://procore3d.github.io/polybrush/brushMirroring/"); GUILayout.BeginHorizontal(); brushMirror = (z_BrushMirror) z_GUILayout.BitMaskField((uint)brushMirror, System.Enum.GetNames(typeof(z_BrushMirror)), "Set Brush Mirroring"); mirrorSpace = (z_MirrorCoordinateSpace) GUILayout.Toolbar((int) mirrorSpace, mirrorSpaceGuiContent, "Command"); GUILayout.EndHorizontal(); mode.DrawGUI(brushSettings); // When using non-conforming heights in a GUIStyle the GUI will sometimes // clip the content too early - this pads the size so that doesn't happen. GUILayout.Space(16); if(EditorGUI.EndChangeCheck()) mode.OnBrushSettingsChanged(brushTarget, brushSettings); EditorGUILayout.EndScrollView(); } else { if(tool == z_BrushTool.Settings) { z_GlobalSettingsEditor.OnGUI(); } else { // ...yo dawg, heard you like FlexibleSpace GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Select an Edit Mode", z_GUI.headerTextStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); } } #if POLYBRUSH_DEBUG z_GUI.PushUnitySkin(); GUILayout.Label("DEBUG", EditorStyles.boldLabel); GUILayout.Label("target: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.gameObject.name : "null")); GUILayout.Label("vertex: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.vertexCount : 0)); GUILayout.Label("applying: " + applyingBrush); GUILayout.Label("lockBrushToFirst: " + lockBrushToFirst); GUILayout.Label("lastHoveredGameObject: " + lastHoveredGameObject); GUILayout.Space(6); foreach(var kvp in hovering) { z_BrushTarget t = kvp.Value; z_EditableObject dbg_editable = t.editableObject; GUILayout.Label("Vertex Streams: " + dbg_editable.usingVertexStreams); GUILayout.Label("Original: " + (dbg_editable.originalMesh == null ? "null" : dbg_editable.originalMesh.name)); GUILayout.Label("Active: " + (dbg_editable.editMesh == null ? "null" : dbg_editable.editMesh.name)); GUILayout.Label("Graphics: " + (dbg_editable.graphicsMesh == null ? "null" : dbg_editable.graphicsMesh.name)); } z_GUI.PopGUISkin(); #endif z_GUI.PopGUISkin(); if(wantsRepaint) { wantsRepaint = false; Repaint(); } } void OpenContextMenu() { GenericMenu menu = new GenericMenu(); menu.AddItem (new GUIContent("Open as Floating Window", ""), z_Pref.GetBool(z_Pref.floatingEditorWindow, false), () => { SetWindowFloating(true); } ); menu.AddItem (new GUIContent("Open as Dockable Window", ""), !z_Pref.GetBool(z_Pref.floatingEditorWindow, false), () => { SetWindowFloating(false); } ); menu.ShowAsContext (); } void OnProBuilderEditLevelChanged(int i) { // Top = 0, // Geometry = 1, // Texture = 2, // Plugin = 4 if(i > 0 && tool != z_BrushTool.None) SetTool(z_BrushTool.None); } void SetTool(z_BrushTool brushTool) { if(brushTool == tool && mode != null) return; if(z_ReflectionUtil.ProBuilderEditorWindow != null && brushTool != z_BrushTool.None) z_ReflectionUtil.Invoke(z_ReflectionUtil.ProBuilderEditorWindow, "SetEditLevel", BindingFlags.Public | BindingFlags.Instance, 0); if(mode != null) { // Exiting edit mode if(lastHoveredGameObject != null) { OnBrushExit( lastHoveredGameObject ); FinalizeAndResetHovering(); } mode.OnDisable(); } else { if(z_ReflectionUtil.ProBuilderEditorWindow != null && brushTool != z_BrushTool.None) z_ReflectionUtil.Invoke(z_ReflectionUtil.ProBuilderEditorWindow, "SetEditLevel", BindingFlags.Public | BindingFlags.Instance, 0); } lastHoveredGameObject = null; System.Type modeType = brushTool.GetModeType(); if(modeType != null) { mode = modes.FirstOrDefault(x => x != null && x.GetType() == modeType); if(mode == null) mode = (z_BrushMode) ScriptableObject.CreateInstance( modeType ); } tool = brushTool; if(tool != z_BrushTool.None) { Tools.current = Tool.None; mode.OnEnable(); } Repaint(); }
void OnGUI() { Event e = Event.current; z_GUI.PushGUISkin(z_GUI.PolybrushSkin); if (e.type == EventType.ContextClick) { OpenContextMenu(); } GUILayout.Space(8); EditorGUI.BeginChangeCheck(); int toolbarIndex = (int)tool - 1; toolbarIndex = GUILayout.Toolbar(toolbarIndex, modeIcons, "Mode"); if (EditorGUI.EndChangeCheck()) { z_BrushTool newTool = (z_BrushTool)(toolbarIndex + 1); SetTool(newTool == tool ? z_BrushTool.None : (z_BrushTool)toolbarIndex + 1); } // Call current mode GUI if (mode != null && tool != z_BrushTool.Settings) { if (!z_Pref.GetBool(z_Pref.lockBrushSettings)) { z_GUI.PopGUISkin(); scroll = EditorGUILayout.BeginScrollView(scroll); z_GUI.PushGUISkin(z_GUI.PolybrushSkin); } // Show the settings header in z_Editor so that the preset selector can be included in the block. // Can't move preset selector to z_BrushSettingsEditor because it's a CustomEditor for z_BrushSettings, // along with other issues. if (z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Settings"))) { Application.OpenURL("http://procore3d.github.io/polybrush/brushSettings/"); } /** * Brush preset selector */ GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); currentBrushIndex = EditorGUILayout.Popup(currentBrushIndex, availableBrushes_str, "Popup"); if (EditorGUI.EndChangeCheck()) { if (currentBrushIndex >= availableBrushes.Count) { SetBrushSettings(z_BrushSettingsEditor.AddNew()); } else { SetBrushSettings(availableBrushes[currentBrushIndex]); } } if (GUILayout.Button(gc_SaveBrushSettings, GUILayout.Width(40))) { if (brushSettings != null && brushSettingsAsset != null) { // integer 0, 1 or 2 corresponding to ok, cancel and alt buttons int res = EditorUtility.DisplayDialogComplex("Save Brush Settings", "Overwrite brush preset or save as a new preset? ", "Save", "Save As", "Cancel"); if (res == 0) { brushSettings.CopyTo(brushSettingsAsset); EditorGUIUtility.PingObject(brushSettingsAsset); } else if (res == 1) { z_BrushSettings dup = z_BrushSettingsEditor.AddNew(); string name = dup.name; brushSettings.CopyTo(dup); dup.name = name; // want to retain the unique name generated by AddNew() SetBrushSettings(dup); EditorGUIUtility.PingObject(brushSettingsAsset); } } else { Debug.LogWarning("Something went wrong saving brush settings."); } } GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); brushEditor.OnInspectorGUI(); if (z_Pref.GetBool(z_Pref.lockBrushSettings)) { z_GUI.PopGUISkin(); scroll = EditorGUILayout.BeginScrollView(scroll); z_GUI.PushGUISkin(z_GUI.PolybrushSkin); } /** * Mirroring */ if (z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Mirroring"))) { Application.OpenURL("http://procore3d.github.io/polybrush/brushMirroring/"); } GUILayout.BeginHorizontal(); brushMirror = (z_BrushMirror)z_GUILayout.BitMaskField((uint)brushMirror, System.Enum.GetNames(typeof(z_BrushMirror)), "Set Brush Mirroring"); mirrorSpace = (z_MirrorCoordinateSpace)GUILayout.Toolbar((int)mirrorSpace, mirrorSpaceGuiContent, "Command"); GUILayout.EndHorizontal(); mode.DrawGUI(brushSettings); // When using non-conforming heights in a GUIStyle the GUI will sometimes // clip the content too early - this pads the size so that doesn't happen. GUILayout.Space(16); if (EditorGUI.EndChangeCheck()) { mode.OnBrushSettingsChanged(brushTarget, brushSettings); } EditorGUILayout.EndScrollView(); } else { if (tool == z_BrushTool.Settings) { z_GlobalSettingsEditor.OnGUI(); } else { // ...yo dawg, heard you like FlexibleSpace GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Select an Edit Mode", z_GUI.headerTextStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); } } #if POLYBRUSH_DEBUG z_GUI.PushUnitySkin(); GUILayout.Label("DEBUG", EditorStyles.boldLabel); GUILayout.Label("target: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.gameObject.name : "null")); GUILayout.Label("vertex: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.vertexCount : 0)); GUILayout.Label("applying: " + applyingBrush); GUILayout.Label("lockBrushToFirst: " + lockBrushToFirst); GUILayout.Label("lastHoveredGameObject: " + lastHoveredGameObject); GUILayout.Space(6); foreach (var kvp in hovering) { z_BrushTarget t = kvp.Value; z_EditableObject dbg_editable = t.editableObject; GUILayout.Label("Vertex Streams: " + dbg_editable.usingVertexStreams); GUILayout.Label("Original: " + (dbg_editable.originalMesh == null ? "null" : dbg_editable.originalMesh.name)); GUILayout.Label("Active: " + (dbg_editable.editMesh == null ? "null" : dbg_editable.editMesh.name)); GUILayout.Label("Graphics: " + (dbg_editable.graphicsMesh == null ? "null" : dbg_editable.graphicsMesh.name)); } z_GUI.PopGUISkin(); #endif z_GUI.PopGUISkin(); if (wantsRepaint) { wantsRepaint = false; Repaint(); } }