From 24ba9b3468b0e3ea1b0ecefb4861c602bab247ce Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Sat, 12 Jan 2019 08:40:46 +1000 Subject: [PATCH 1/2] BlockInspector and BlockEditor changes to display correctly in 2019.1.0a13 - GUILayout.*Area no longer used was resulting in 0 pixels drawn - Inspector height calc no longer driven by layout option that was filling 0 pixels - Resize bar changes to correctly position and minimise incorrect values --- Assets/Fungus/Scripts/Editor/BlockEditor.cs | 5 ++-- .../Fungus/Scripts/Editor/BlockInspector.cs | 30 +++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/BlockEditor.cs b/Assets/Fungus/Scripts/Editor/BlockEditor.cs index 5850dfd6..9d714fd9 100644 --- a/Assets/Fungus/Scripts/Editor/BlockEditor.cs +++ b/Assets/Fungus/Scripts/Editor/BlockEditor.cs @@ -62,9 +62,10 @@ namespace Fungus.EditorUtils serializedObject.Update(); SerializedProperty blockNameProperty = serializedObject.FindProperty("blockName"); - Rect blockLabelRect = new Rect(45, 5, 120, 16); + //calc position as size of what we want to draw pushed up into the top bar of the inspector + Rect blockLabelRect = new Rect(45, -GUI.skin.window.padding.bottom - EditorGUIUtility.singleLineHeight * 2, 120, 16); EditorGUI.LabelField(blockLabelRect, new GUIContent("Block Name")); - Rect blockNameRect = new Rect(45, 21, 180, 16); + Rect blockNameRect = new Rect(45, blockLabelRect.y + EditorGUIUtility.singleLineHeight, 180, 16); EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent("")); // Ensure block name is unique for this Flowchart diff --git a/Assets/Fungus/Scripts/Editor/BlockInspector.cs b/Assets/Fungus/Scripts/Editor/BlockInspector.cs index c27bb949..ecc55eb5 100644 --- a/Assets/Fungus/Scripts/Editor/BlockInspector.cs +++ b/Assets/Fungus/Scripts/Editor/BlockInspector.cs @@ -103,10 +103,6 @@ namespace Fungus.EditorUtils float width = EditorGUIUtility.currentViewWidth; float height = windowHeight; - // Using a custom rect area to get the correct 5px indent for the scroll views - Rect blockRect = new Rect(5, topPanelHeight, width - 5, height + 10); - GUILayout.BeginArea(blockRect); - blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.BlockViewHeight)); activeBlockEditor.DrawBlockGUI(flowchart); GUILayout.EndScrollView(); @@ -121,7 +117,6 @@ namespace Fungus.EditorUtils inspectCommand != null && !inspectCommand.ParentBlock.Equals(block)) { - GUILayout.EndArea(); Repaint(); return; } @@ -143,6 +138,9 @@ namespace Fungus.EditorUtils /// protected void UpdateWindowHeight() { +#if UNITY_2019_1_OR_NEWER + windowHeight = Screen.height * EditorGUIUtility.pixelsPerPoint; +#else EditorGUILayout.BeginVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); @@ -151,13 +149,14 @@ namespace Fungus.EditorUtils { windowHeight = tempRect.height; } +#endif } public void DrawCommandUI(Flowchart flowchart, Command inspectCommand) { ResizeScrollView(flowchart); - GUILayout.Space(7); + EditorGUILayout.Space(); activeBlockEditor.DrawButtonToolbar(); @@ -191,11 +190,9 @@ namespace Fungus.EditorUtils GUILayout.EndScrollView(); - GUILayout.EndArea(); - // Draw the resize bar after everything else has finished drawing // This is mainly to avoid incorrect indenting. - Rect resizeRect = new Rect(0, topPanelHeight + flowchart.BlockViewHeight + 1, Screen.width, 4f); + Rect resizeRect = new Rect(0, flowchart.BlockViewHeight, EditorGUIUtility.currentViewWidth, 4f); GUI.color = new Color(0.64f, 0.64f, 0.64f); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.height = 1; @@ -210,16 +207,19 @@ namespace Fungus.EditorUtils private void ResizeScrollView(Flowchart flowchart) { - Rect cursorChangeRect = new Rect(0, flowchart.BlockViewHeight + 1, Screen.width, 4f); + Rect cursorChangeRect = new Rect(0, flowchart.BlockViewHeight + 1, EditorGUIUtility.currentViewWidth, 4f); EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical); - if (Event.current.type == EventType.MouseDown && cursorChangeRect.Contains(Event.current.mousePosition)) + if (cursorChangeRect.Contains(Event.current.mousePosition)) { - resize = true; + if (Event.current.type == EventType.MouseDown) + { + resize = true; + } } - if (resize) + if (resize && Event.current.type == EventType.Repaint) { Undo.RecordObject(flowchart, "Resize view"); flowchart.BlockViewHeight = Event.current.mousePosition.y; @@ -231,7 +231,7 @@ namespace Fungus.EditorUtils // This isn't standard Unity UI behavior but it is robust and safe. if (resize && Event.current.type == EventType.MouseDrag) { - Rect windowRect = new Rect(0, 0, Screen.width, Screen.height); + Rect windowRect = new Rect(0, 0, EditorGUIUtility.currentViewWidth, windowHeight); if (!windowRect.Contains(Event.current.mousePosition)) { resize = false; @@ -259,7 +259,7 @@ namespace Fungus.EditorUtils // Make sure block view is always clamped to visible area float height = flowchart.BlockViewHeight; height = Mathf.Max(200, height); - height = Mathf.Min(Screen.height - 200,height); + height = Mathf.Min(windowHeight - 200,height); flowchart.BlockViewHeight = height; } From a1353af961a5bdf9ecade74c692bc864d34cc21f Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Sat, 12 Jan 2019 10:31:31 +1000 Subject: [PATCH 2/2] BlockInspector correct top panel height in 2018_3 BlockEditor only force unique name if it has changed --- Assets/Fungus/Scripts/Editor/BlockEditor.cs | 33 ++++++++++++------- .../Fungus/Scripts/Editor/BlockInspector.cs | 27 +++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/BlockEditor.cs b/Assets/Fungus/Scripts/Editor/BlockEditor.cs index 9d714fd9..a010a3a2 100644 --- a/Assets/Fungus/Scripts/Editor/BlockEditor.cs +++ b/Assets/Fungus/Scripts/Editor/BlockEditor.cs @@ -63,18 +63,26 @@ namespace Fungus.EditorUtils SerializedProperty blockNameProperty = serializedObject.FindProperty("blockName"); //calc position as size of what we want to draw pushed up into the top bar of the inspector - Rect blockLabelRect = new Rect(45, -GUI.skin.window.padding.bottom - EditorGUIUtility.singleLineHeight * 2, 120, 16); - EditorGUI.LabelField(blockLabelRect, new GUIContent("Block Name")); - Rect blockNameRect = new Rect(45, blockLabelRect.y + EditorGUIUtility.singleLineHeight, 180, 16); - EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent("")); - - // Ensure block name is unique for this Flowchart - var block = target as Block; - string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block); - if (uniqueName != block.BlockName) - { - blockNameProperty.stringValue = uniqueName; + //Rect blockLabelRect = new Rect(45, -GUI.skin.window.padding.bottom - EditorGUIUtility.singleLineHeight * 2, 120, 16); + //EditorGUI.LabelField(blockLabelRect, new GUIContent("Block Name")); + //Rect blockNameRect = new Rect(45, blockLabelRect.y + EditorGUIUtility.singleLineHeight, 180, 16); + //EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent("")); + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PrefixLabel(new GUIContent("Block Name"), EditorStyles.largeLabel); + EditorGUI.BeginChangeCheck(); + blockNameProperty.stringValue = EditorGUILayout.TextField(blockNameProperty.stringValue); + if(EditorGUI.EndChangeCheck()) + { + // Ensure block name is unique for this Flowchart + var block = target as Block; + string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block); + if (uniqueName != block.BlockName) + { + blockNameProperty.stringValue = uniqueName; + } } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); } @@ -120,7 +128,8 @@ namespace Fungus.EditorUtils SerializedProperty descriptionProp = serializedObject.FindProperty("description"); EditorGUILayout.PropertyField(descriptionProp); - + EditorGUILayout.Space(); + DrawEventHandlerGUI(flowchart); block.UpdateIndentLevels(); diff --git a/Assets/Fungus/Scripts/Editor/BlockInspector.cs b/Assets/Fungus/Scripts/Editor/BlockInspector.cs index ecc55eb5..1ef5a062 100644 --- a/Assets/Fungus/Scripts/Editor/BlockInspector.cs +++ b/Assets/Fungus/Scripts/Editor/BlockInspector.cs @@ -28,7 +28,11 @@ namespace Fungus.EditorUtils protected Vector2 commandScrollPos; protected bool resize = false; protected bool clamp = false; - protected float topPanelHeight = 50; +#if UNITY_2019_1_OR_NEWER + protected float topPanelHeight = 0; +#else + protected float topPanelHeight = 48; +#endif protected float windowHeight = 0f; // Cache the block and command editors so we only create and destroy them @@ -96,14 +100,12 @@ namespace Fungus.EditorUtils activeBlockEditor = Editor.CreateEditor(block) as BlockEditor; } - activeBlockEditor.DrawBlockName(flowchart); - UpdateWindowHeight(); float width = EditorGUIUtility.currentViewWidth; - float height = windowHeight; blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.BlockViewHeight)); + activeBlockEditor.DrawBlockName(flowchart); activeBlockEditor.DrawBlockGUI(flowchart); GUILayout.EndScrollView(); @@ -138,18 +140,7 @@ namespace Fungus.EditorUtils /// protected void UpdateWindowHeight() { -#if UNITY_2019_1_OR_NEWER windowHeight = Screen.height * EditorGUIUtility.pixelsPerPoint; -#else - EditorGUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - EditorGUILayout.EndVertical(); - Rect tempRect = GUILayoutUtility.GetLastRect(); - if (Event.current.type == EventType.Repaint) - { - windowHeight = tempRect.height; - } -#endif } public void DrawCommandUI(Flowchart flowchart, Command inspectCommand) @@ -192,7 +183,7 @@ namespace Fungus.EditorUtils // Draw the resize bar after everything else has finished drawing // This is mainly to avoid incorrect indenting. - Rect resizeRect = new Rect(0, flowchart.BlockViewHeight, EditorGUIUtility.currentViewWidth, 4f); + Rect resizeRect = new Rect(0, flowchart.BlockViewHeight + topPanelHeight, EditorGUIUtility.currentViewWidth, 4f); GUI.color = new Color(0.64f, 0.64f, 0.64f); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.height = 1; @@ -207,7 +198,7 @@ namespace Fungus.EditorUtils private void ResizeScrollView(Flowchart flowchart) { - Rect cursorChangeRect = new Rect(0, flowchart.BlockViewHeight + 1, EditorGUIUtility.currentViewWidth, 4f); + Rect cursorChangeRect = new Rect(0, flowchart.BlockViewHeight + 1 + topPanelHeight, EditorGUIUtility.currentViewWidth, 4f); EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical); @@ -222,7 +213,7 @@ namespace Fungus.EditorUtils if (resize && Event.current.type == EventType.Repaint) { Undo.RecordObject(flowchart, "Resize view"); - flowchart.BlockViewHeight = Event.current.mousePosition.y; + flowchart.BlockViewHeight = Event.current.mousePosition.y - topPanelHeight; } ClampBlockViewHeight(flowchart);