Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
GUI Fixes, editor scaling support
Browse files Browse the repository at this point in the history
- Fixed RTNodeEditor example having no root rect and thus context menus not appearing
- Fixed broken GUI when using 2019.3+ Editor Scaling feature
- Fixed spelling mistake ForceGUIDawOffScreen -> ForceGUIDrawOffScreen in Node.cs
- Changed toolbar information, made it more compact
- Moved standard NodeEditorFramework.Standard.NodeEditorInterface to the Standard folder where it belongs
  • Loading branch information
Seneral committed May 10, 2020
1 parent 19840d2 commit f82311c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Examples/Runtime/RTNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ private void OnGUI ()
}
AssureSetup();

// Start Overlay GUI for popups
// Start Overlay GUI for popups (before any other GUI)
OverlayGUI.StartOverlayGUI("RTNodeEditor");

// Set root rect (can be any number of arbitrary groups, e.g. a nested UI, but at least one)
GUI.BeginGroup(new Rect(0, 0, Screen.width, Screen.height));

// Begin Node Editor GUI and set canvas rect
NodeEditorGUI.StartNodeGUI(false);
canvasCache.editorState.canvasRect = new Rect (rect.x, rect.y + editorInterface.toolbarHeight, rect.width, rect.height - editorInterface.toolbarHeight);
Expand All @@ -92,6 +95,9 @@ private void OnGUI ()

// End Node Editor GUI
NodeEditorGUI.EndNodeGUI();

// End root rect
GUI.EndGroup();

// End Overlay GUI and draw popups
OverlayGUI.EndOverlayGUI();
Expand Down
7 changes: 6 additions & 1 deletion Node_Editor_Framework/Editor/NodeEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ private void OnGUI()
}

// Draw Interface
editorInterface.DrawToolbarGUI(new Rect(0, 0, Screen.width, 0));
float screenWidth = Screen.width;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
float scaling = UnityEditor.EditorPrefs.GetInt("CustomEditorUIScale") / 100.0f;
screenWidth = screenWidth / scaling;
#endif
editorInterface.DrawToolbarGUI(new Rect(0, 0, screenWidth, 0));
editorInterface.DrawModalPanel();

// End Node Editor GUI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "Seneral.NodeEditorFramework.Editor",
"references": [
"GUID:984eb8b4fce069a4fb617d10374722b2"
"GUID:984eb8b4fce069a4fb617d10374722b2",
"GUID:c7dd23d8a26985747bf8c6284ac6b26f"
],
"includePlatforms": [
"Editor"
Expand Down
2 changes: 1 addition & 1 deletion Node_Editor_Framework/Runtime/Framework/Core/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public virtual string Title { get {
/// <summary>
/// Specifies whether GUI requires to be updated even when the node is off-screen
/// </summary>
public virtual bool ForceGUIDawOffScreen { get { return false; } }
public virtual bool ForceGUIDrawOffScreen { get { return false; } }

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public static bool CreateDefaultSkin ()
// Box
defaultSkin.box.normal.background = GUIBox;
defaultSkin.box.normal.textColor = NE_TextColor;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
defaultSkin.box.normal.scaledBackgrounds = null;
#endif
defaultSkin.box.active.textColor = NE_TextColor;
customStyles.Add(new GUIStyle (defaultSkin.box) { name = "boxBold", fontStyle = FontStyle.Bold });

Expand All @@ -114,6 +117,11 @@ public static bool CreateDefaultSkin ()
defaultSkin.button.normal.background = GUIButton;
defaultSkin.button.hover.background = GUIButtonHover;
defaultSkin.button.active.background = GUIButtonSelected;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
defaultSkin.button.normal.scaledBackgrounds = null;
defaultSkin.button.hover.scaledBackgrounds = null;
defaultSkin.button.active.scaledBackgrounds = null;
#endif
defaultSkin.button.border = new RectOffset(1, 1, 1, 1);
defaultSkin.button.margin = new RectOffset(2, 2, 1, 1);
defaultSkin.button.padding = new RectOffset(4, 4, 1, 1);
Expand All @@ -132,6 +140,10 @@ public static bool CreateDefaultSkin ()
GUIStyle toolbar = new GUIStyle(defaultSkin.box) { name = "toolbar" };
toolbar.normal.background = GUIToolbar;
toolbar.active.background = GUIToolbar;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
toolbar.normal.scaledBackgrounds = null;
toolbar.active.scaledBackgrounds = null;
#endif
toolbar.border = new RectOffset(0, 0, 1, 1);
toolbar.margin = new RectOffset(0, 0, 0, 0);
toolbar.padding = new RectOffset(1, 1, 1, 1);
Expand All @@ -140,14 +152,16 @@ public static bool CreateDefaultSkin ()

GUIStyle toolbarLabel = new GUIStyle(defaultSkin.box) { name = "toolbarLabel" };
toolbarLabel.normal.background = GUIToolbarLabel;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
toolbarLabel.normal.scaledBackgrounds = null;
#endif
toolbarLabel.border = new RectOffset(2, 2, 0, 0);
toolbarLabel.margin = new RectOffset(0, 0, 0, 0);
toolbarLabel.padding = new RectOffset(6, 6, 2, 2);
customStyles.Add(toolbarLabel);

GUIStyle toolbarButton = new GUIStyle(toolbarLabel) { name = "toolbarButton" };
toolbarButton.normal.background = GUIToolbarButton;
toolbarButton.border = new RectOffset(2, 2, 0, 0);
toolbarButton.active.background = GUISelectedBG;
customStyles.Add(toolbarButton);

Expand Down
2 changes: 1 addition & 1 deletion Node_Editor_Framework/Runtime/Framework/NodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private static void DrawSubCanvas (NodeCanvas nodeCanvas, NodeEditorState editor
if (node == null) continue;
if (Event.current.type == EventType.Layout)
node.isClipped = !curEditorState.canvasViewport.Overlaps(node.fullAABBRect);
if (!node.isClipped || node.ForceGUIDawOffScreen)
if (!node.isClipped || node.ForceGUIDrawOffScreen)
{
node.DrawNode();
if (Event.current.type == EventType.Repaint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NodeEditorFramework.Utilities
public static class GUIScaleUtility
{
#if UNITY_2019_3_OR_NEWER
private const int HEADER_SIZE = 18;
private const int HEADER_SIZE = 23;
#else
private const int HEADER_SIZE = 23;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ public void DrawToolbarGUI(Rect rect)
GUILayout.Space(10);
GUILayout.FlexibleSpace();

GUILayout.Label(new GUIContent("" + canvasCache.nodeCanvas.saveName + " (" + (canvasCache.nodeCanvas.livesInScene ? "Scene Save" : "Asset Save") + ")",
"Opened Canvas path: " + canvasCache.nodeCanvas.savePath), GUI.skin.GetStyle("toolbarLabel"));
GUILayout.Label("Type: " + canvasCache.typeData.DisplayString, GUI.skin.GetStyle("toolbarLabel"));
curToolbarHeight = Mathf.Max(curToolbarHeight, GUILayoutUtility.GetLastRect().yMax);
GUILayout.Label(new GUIContent(canvasCache.nodeCanvas.saveName,
"Save Type: " + (canvasCache.nodeCanvas.livesInScene ? "Scene" : "Asset") + "\n" +
"Save Path: " + canvasCache.nodeCanvas.savePath), GUI.skin.GetStyle("toolbarLabel"));
GUILayout.Label(new GUIContent(canvasCache.typeData.DisplayString, "Canvas Type: " + canvasCache.typeData.DisplayString), GUI.skin.GetStyle("toolbarLabel"));
//curToolbarHeight = Mathf.Max(curToolbarHeight, GUILayoutUtility.GetLastRect().yMax);


GUI.backgroundColor = new Color(1, 0.3f, 0.3f, 1);
/*if (GUILayout.Button("Force Re-init", GUI.skin.GetStyle("toolbarButton"), GUILayout.Width(100)))
/*if (GUILayout.Button("Reinit", GUI.skin.GetStyle("toolbarButton"), GUILayout.Width(100)))
{
NodeEditor.ReInit(true);
NodeEditorGUI.CreateDefaultSkin();
Expand Down

0 comments on commit f82311c

Please sign in to comment.