Browse Source

BlockInspector correct top panel height in 2018_3

BlockEditor only force unique name if it has changed
master
desktop-maesty/steve 6 years ago
parent
commit
a1353af961
  1. 33
      Assets/Fungus/Scripts/Editor/BlockEditor.cs
  2. 27
      Assets/Fungus/Scripts/Editor/BlockInspector.cs

33
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -63,18 +63,26 @@ namespace Fungus.EditorUtils
SerializedProperty blockNameProperty = serializedObject.FindProperty("blockName"); SerializedProperty blockNameProperty = serializedObject.FindProperty("blockName");
//calc position as size of what we want to draw pushed up into the top bar of the inspector //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); //Rect blockLabelRect = new Rect(45, -GUI.skin.window.padding.bottom - EditorGUIUtility.singleLineHeight * 2, 120, 16);
EditorGUI.LabelField(blockLabelRect, new GUIContent("Block Name")); //EditorGUI.LabelField(blockLabelRect, new GUIContent("Block Name"));
Rect blockNameRect = new Rect(45, blockLabelRect.y + EditorGUIUtility.singleLineHeight, 180, 16); //Rect blockNameRect = new Rect(45, blockLabelRect.y + EditorGUIUtility.singleLineHeight, 180, 16);
EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent("")); //EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent(""));
EditorGUILayout.BeginHorizontal();
// Ensure block name is unique for this Flowchart EditorGUILayout.PrefixLabel(new GUIContent("Block Name"), EditorStyles.largeLabel);
var block = target as Block; EditorGUI.BeginChangeCheck();
string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block); blockNameProperty.stringValue = EditorGUILayout.TextField(blockNameProperty.stringValue);
if (uniqueName != block.BlockName) if(EditorGUI.EndChangeCheck())
{ {
blockNameProperty.stringValue = uniqueName; // 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(); serializedObject.ApplyModifiedProperties();
} }
@ -120,7 +128,8 @@ namespace Fungus.EditorUtils
SerializedProperty descriptionProp = serializedObject.FindProperty("description"); SerializedProperty descriptionProp = serializedObject.FindProperty("description");
EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.PropertyField(descriptionProp);
EditorGUILayout.Space();
DrawEventHandlerGUI(flowchart); DrawEventHandlerGUI(flowchart);
block.UpdateIndentLevels(); block.UpdateIndentLevels();

27
Assets/Fungus/Scripts/Editor/BlockInspector.cs

@ -28,7 +28,11 @@ namespace Fungus.EditorUtils
protected Vector2 commandScrollPos; protected Vector2 commandScrollPos;
protected bool resize = false; protected bool resize = false;
protected bool clamp = 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; protected float windowHeight = 0f;
// Cache the block and command editors so we only create and destroy them // 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 = Editor.CreateEditor(block) as BlockEditor;
} }
activeBlockEditor.DrawBlockName(flowchart);
UpdateWindowHeight(); UpdateWindowHeight();
float width = EditorGUIUtility.currentViewWidth; float width = EditorGUIUtility.currentViewWidth;
float height = windowHeight;
blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.BlockViewHeight)); blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.BlockViewHeight));
activeBlockEditor.DrawBlockName(flowchart);
activeBlockEditor.DrawBlockGUI(flowchart); activeBlockEditor.DrawBlockGUI(flowchart);
GUILayout.EndScrollView(); GUILayout.EndScrollView();
@ -138,18 +140,7 @@ namespace Fungus.EditorUtils
/// </summary> /// </summary>
protected void UpdateWindowHeight() protected void UpdateWindowHeight()
{ {
#if UNITY_2019_1_OR_NEWER
windowHeight = Screen.height * EditorGUIUtility.pixelsPerPoint; 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) public void DrawCommandUI(Flowchart flowchart, Command inspectCommand)
@ -192,7 +183,7 @@ namespace Fungus.EditorUtils
// Draw the resize bar after everything else has finished drawing // Draw the resize bar after everything else has finished drawing
// This is mainly to avoid incorrect indenting. // 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.color = new Color(0.64f, 0.64f, 0.64f);
GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture);
resizeRect.height = 1; resizeRect.height = 1;
@ -207,7 +198,7 @@ namespace Fungus.EditorUtils
private void ResizeScrollView(Flowchart flowchart) 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); EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical);
@ -222,7 +213,7 @@ namespace Fungus.EditorUtils
if (resize && Event.current.type == EventType.Repaint) if (resize && Event.current.type == EventType.Repaint)
{ {
Undo.RecordObject(flowchart, "Resize view"); Undo.RecordObject(flowchart, "Resize view");
flowchart.BlockViewHeight = Event.current.mousePosition.y; flowchart.BlockViewHeight = Event.current.mousePosition.y - topPanelHeight;
} }
ClampBlockViewHeight(flowchart); ClampBlockViewHeight(flowchart);

Loading…
Cancel
Save