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

Commit

Permalink
UI Toolbar and GUISkin Fixes
Browse files Browse the repository at this point in the history
Fixed #189 toolbar not showing up introduced in f82311c
Improved GUISkin handling so that the default GUIStyle are always used
	- Fixes some problems with missing styles at Runtime if not explicitly set, as well as issues when switching between dark and light modes
	- New behaviour: Always generate DefaultSkin and save to file for user to copy and modify. If OverriddenSkin.asset exists, use that style as a basis instead.
Fixed issue with XML IO for objects that can not be serialized (e.g. Texture2D in TextureCompose example)
  • Loading branch information
Seneral committed Jun 22, 2020
1 parent 9c1cae4 commit 50a78af
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 55 deletions.
4 changes: 3 additions & 1 deletion Examples/FrameworkExtends/ExtendedRTNodeEditor.cs
Expand Up @@ -91,7 +91,9 @@ private void OnGUI ()
}

// Draw Interface
editorInterface.DrawToolbarGUI(rect);
GUILayout.BeginArea(rect);
editorInterface.DrawToolbarGUI();
GUILayout.EndArea();
editorInterface.DrawModalPanel();

// End Node Editor GUI
Expand Down
4 changes: 3 additions & 1 deletion Examples/Runtime/RTNodeEditor.cs
Expand Up @@ -90,7 +90,9 @@ private void OnGUI ()
}

// Draw Interface
editorInterface.DrawToolbarGUI(rect);
GUILayout.BeginArea(rect);
editorInterface.DrawToolbarGUI();
GUILayout.EndArea();
editorInterface.DrawModalPanel();

// End Node Editor GUI
Expand Down
7 changes: 1 addition & 6 deletions Node_Editor_Framework/Editor/NodeEditorWindow.cs
Expand Up @@ -267,12 +267,7 @@ private void OnGUI()
}

// Draw Interface
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.DrawToolbarGUI();
editorInterface.DrawModalPanel();

// End Node Editor GUI
Expand Down
54 changes: 30 additions & 24 deletions Node_Editor_Framework/Runtime/Framework/Interface/NodeEditorGUI.cs
Expand Up @@ -32,35 +32,40 @@ public static partial class NodeEditorGUI

public static bool Init ()
{
List<GUIStyle> customStyles = new List<GUIStyle> ();
overrideSkin = ResourceManager.LoadResource<GUISkin> ("OverrideSkin.asset");
if (overrideSkin == null)
{ // Create default skin from scratch
if (!CreateDefaultSkin ()) return false;
overrideSkin = Object.Instantiate (defaultSkin);
}
else
{ // Use override
overrideSkin = Object.Instantiate (overrideSkin);
}

// Copy default styles in current setting, modified to fit custom style
// This mostly refers to the editor styles

defaultSkin = ResourceManager.LoadResource<GUISkin> ("DefaultSkin.asset");
if (defaultSkin == null)
return CreateDefaultSkin();
else {
defaultSkin = Object.Instantiate (defaultSkin);
// Copy default editor styles, modified to fit custom style
customStyles = new List<GUIStyle> (defaultSkin.customStyles);
foreach (GUIStyle style in GUI.skin.customStyles)
List<GUIStyle> customStyles = new List<GUIStyle> (overrideSkin.customStyles);
foreach (GUIStyle style in GUI.skin.customStyles)
{
if (overrideSkin.FindStyle(style.name) == null)
{
if (defaultSkin.FindStyle(style.name) == null)
GUIStyle modStyle = new GUIStyle (style);
if (modStyle.normal.background == null)
{
GUIStyle modStyle = new GUIStyle (style);
if (modStyle.normal.background == null)
{
modStyle.fontSize = defaultSkin.label.fontSize;
modStyle.normal.textColor = modStyle.active.textColor = modStyle.focused.textColor = modStyle.hover.textColor = defaultSkin.label.normal.textColor;
}
customStyles.Add (modStyle);
modStyle.fontSize = overrideSkin.label.fontSize;
modStyle.normal.textColor = modStyle.active.textColor = modStyle.focused.textColor = modStyle.hover.textColor = overrideSkin.label.normal.textColor;
}
customStyles.Add (modStyle);
}
defaultSkin.customStyles = customStyles.ToArray();

Background = ResourceManager.LoadTexture ("Textures/background.png");
AALineTex = ResourceManager.LoadTexture ("Textures/AALine.png");

return Background && AALineTex;
}
overrideSkin.customStyles = customStyles.ToArray();

Background = ResourceManager.LoadTexture ("Textures/background.png");
AALineTex = ResourceManager.LoadTexture ("Textures/AALine.png");

return Background && AALineTex;
}

public static bool CreateDefaultSkin ()
Expand Down Expand Up @@ -177,7 +182,8 @@ public static bool CreateDefaultSkin ()

defaultSkin.customStyles = customStyles.ToArray();
#if UNITY_EDITOR
UnityEditor.AssetDatabase.CreateAsset(Object.Instantiate (defaultSkin), ResourceManager.resourcePath + "DefaultSkin.asset");
if (!ResourceManager.resourcePath.StartsWith("Packages"))
UnityEditor.AssetDatabase.CreateAsset(Object.Instantiate (defaultSkin), ResourceManager.resourcePath + "DefaultSkin.asset");
#endif

return true;
Expand Down
Binary file not shown.

This file was deleted.

8 changes: 4 additions & 4 deletions Node_Editor_Framework/Standard/IOFormats/XMLImportExport.cs
Expand Up @@ -102,7 +102,8 @@ public override void ExportData(CanvasData data, params object[] args)
else // Serialize value-type fields in-line
{
XmlElement serializedValue = SerializeObjectToXML(node, varData.value);
serializedValue.SetAttribute("name", varData.name);
if (serializedValue != null)
serializedValue.SetAttribute("name", varData.name);
}
}
}
Expand All @@ -128,9 +129,8 @@ public override void ExportData(CanvasData data, params object[] args)
XmlElement obj = saveDoc.CreateElement("Object");
obj.SetAttribute("refID", objectData.refID.ToString());
obj.SetAttribute("type", objectData.data.GetType().FullName);
objects.AppendChild(obj);
SerializeObjectToXML(obj, objectData.data);
}
if (SerializeObjectToXML(obj, objectData.data) != null)
objects.AppendChild(obj); }

// WRITE

Expand Down
15 changes: 4 additions & 11 deletions Node_Editor_Framework/Standard/Interface/NodeEditorInterface.cs
Expand Up @@ -37,12 +37,9 @@ public void ShowNotification(GUIContent message)

#region GUI

public void DrawToolbarGUI(Rect rect)
public void DrawToolbarGUI()
{
rect.height = toolbarHeight;
GUILayout.BeginArea (rect, GUI.skin.GetStyle("toolbar"));
GUILayout.BeginHorizontal();
float curToolbarHeight = 0;
GUILayout.BeginHorizontal(GUI.skin.GetStyle("toolbar"));

if (GUILayout.Button("File", GUI.skin.GetStyle("toolbarDropdown"), GUILayout.Width(50)))
{
Expand Down Expand Up @@ -91,9 +88,8 @@ public void DrawToolbarGUI(Rect rect)
menu.AddItem(new GUIContent("Save Canvas to Scene"), false, SaveSceneCanvasCallback);

// Show dropdown
menu.Show(new Vector2(5, toolbarHeight));
menu.Show(new Vector2(3, toolbarHeight+3));
}
curToolbarHeight = Mathf.Max(curToolbarHeight, GUILayoutUtility.GetLastRect().yMax);

GUILayout.Space(10);
GUILayout.FlexibleSpace();
Expand All @@ -102,7 +98,6 @@ public void DrawToolbarGUI(Rect rect)
"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);
Expand All @@ -117,14 +112,12 @@ public void DrawToolbarGUI(Rect rect)
GUILayout.Space(5);
if (GUILayout.Button("Quit", GUI.skin.GetStyle("toolbarButton"), GUILayout.Width(100)))
Application.Quit ();
curToolbarHeight = Mathf.Max(curToolbarHeight, GUILayoutUtility.GetLastRect().yMax);
}
GUI.backgroundColor = Color.white;

GUILayout.EndHorizontal();
GUILayout.EndArea();
if (Event.current.type == EventType.Repaint)
toolbarHeight = curToolbarHeight;
toolbarHeight = GUILayoutUtility.GetLastRect().yMax;
}

private void SaveSceneCanvasPanel()
Expand Down

0 comments on commit 50a78af

Please sign in to comment.