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

Commit

Permalink
v1.0.2. GUI Fixes
Browse files Browse the repository at this point in the history
Fixed missing EditorStyles in GUISkin, so errors would be thrown when EditorGUI was used in NodeInspector
Fixed EditorGUI controls using default text color and thus not fitting into the custom style by temporarily changing EditorStyles
	- Should be bugfree, critical as they can potentially mess the whole Editor GUI up
Changed RTNodeEditor to use normal EditorGUI controls when in the EditorWindow and only fall back to custom controls in play mode
Changed GUI texture properties to be consistent
  • Loading branch information
Seneral committed Mar 27, 2020
1 parent 98a676a commit e5b9298
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Editor/NodeInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void OnInspectorGUI()
GUILayout.Space(10);

GUILayout.Label("Property Editor", boldLabelStyle);
node.DrawNodePropertyEditor();
node.DrawNodePropertyEditor(true);

if (EditorGUI.EndChangeCheck())
NodeEditor.RepaintClients();
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Framework/Core/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public virtual void NodeGUI ()
/// Used to display a custom node property editor in the GUI.
/// By default shows the standard NodeGUI.
/// </summary>
public virtual void DrawNodePropertyEditor ()
public virtual void DrawNodePropertyEditor (bool isEditorWindow = false)
{
try
{ // Draw Node GUI without disturbing knob placement
ignoreGUIKnobPlacement = true;
NodeEditorGUI.StartNodeGUI(false);
NodeEditorGUI.StartNodeGUI(isEditorWindow);
GUILayout.BeginVertical(GUI.skin.box);
NodeGUI();
GUILayout.EndVertical();
Expand Down
45 changes: 35 additions & 10 deletions Runtime/Framework/Interface/NodeEditorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public static partial class NodeEditorGUI

public static Color NE_LightColor = new Color (0.4f, 0.4f, 0.4f);
public static Color NE_TextColor = new Color(0.8f, 0.8f, 0.8f);
public static Color NE_TextColorSelected = new Color(0.6f, 0.6f, 0.6f);

public static Texture2D Background;
public static Texture2D AALineTex;

public static GUISkin nodeSkin { get { return overrideSkin ?? defaultSkin; } }
public static GUISkin overrideSkin;
public static GUISkin defaultSkin;
public static GUISkin unitySkin;
private static GUISkin defaultSkin;
private static GUISkin unitySkin;

private static Color unityTextColor, unityHoverTextColor, unityActiveTextColor, unityFocusedTextColor;


public static bool Init ()
{
Expand All @@ -35,21 +39,22 @@ public static bool Init ()
return CreateDefaultSkin();
else {
defaultSkin = Object.Instantiate (defaultSkin);

// Copy default editor styles, modified to fit custom style
/*
customStyles = new List<GUIStyle> (nodeSkin.customStyles);
customStyles = new List<GUIStyle> (defaultSkin.customStyles);
foreach (GUIStyle style in GUI.skin.customStyles)
{
if (nodeSkin.FindStyle(style.name) == null)
if (defaultSkin.FindStyle(style.name) == null)
{
GUIStyle modStyle = new GUIStyle (style);
modStyle.fontSize = nodeSkin.label.fontSize;
modStyle.normal.textColor = modStyle.active.textColor = modStyle.focused.textColor = modStyle.hover.textColor = nodeSkin.label.normal.textColor;
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);
}
}
nodeSkin.customStyles = customStyles.ToArray();*/
defaultSkin.customStyles = customStyles.ToArray();

Background = ResourceManager.LoadTexture ("Textures/background.png");
AALineTex = ResourceManager.LoadTexture ("Textures/AALine.png");
Expand Down Expand Up @@ -158,7 +163,7 @@ public static bool CreateDefaultSkin ()

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

return true;
Expand All @@ -167,16 +172,36 @@ public static bool CreateDefaultSkin ()
public static void StartNodeGUI (bool IsEditorWindow)
{
NodeEditor.checkInit(true);
// Required for gamemode switch
// Also for EditorWindow+RTNodeEditor in parallel where RTNodeEditor GUISkin setup would not be enough for the editor window as it's missing the editor styles
if (nodeSkin == null || (IsEditorWindow && nodeSkin.FindStyle("ObjectField") == null))
NodeEditor.ReInit(true);

isEditorWindow = IsEditorWindow;

unitySkin = GUI.skin;
GUI.skin = nodeSkin;
#if UNITY_EDITOR
unityTextColor = UnityEditor.EditorStyles.label.normal.textColor;
UnityEditor.EditorStyles.label.normal.textColor = NE_TextColor;
unityHoverTextColor = UnityEditor.EditorStyles.label.hover.textColor;
UnityEditor.EditorStyles.label.hover.textColor = NE_TextColor;
unityActiveTextColor = UnityEditor.EditorStyles.label.active.textColor;
UnityEditor.EditorStyles.label.active.textColor = NE_TextColorSelected;
unityFocusedTextColor = UnityEditor.EditorStyles.label.focused.textColor;
UnityEditor.EditorStyles.label.focused.textColor = NE_TextColorSelected;
#endif
}

public static void EndNodeGUI ()
{
GUI.skin = unitySkin;
#if UNITY_EDITOR
UnityEditor.EditorStyles.label.normal.textColor = unityTextColor;
UnityEditor.EditorStyles.label.hover.textColor = unityHoverTextColor;
UnityEditor.EditorStyles.label.active.textColor = unityActiveTextColor;
UnityEditor.EditorStyles.label.focused.textColor = unityFocusedTextColor;
#endif
}

#region Connection Drawing
Expand Down
14 changes: 13 additions & 1 deletion Runtime/Resources/Textures/NE_Box.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Runtime/Resources/Textures/NE_Button.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Runtime/Resources/Textures/NE_Button_Hover.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Runtime/Resources/Textures/NE_Button_Selected.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Runtime/Resources/Textures/NE_SelectedBG.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Runtime/Resources/Textures/NE_Toolbar.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Runtime/Resources/Textures/NE_ToolbarButton.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Resources/Textures/NE_ToolbarLabel.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e5b9298

Please sign in to comment.