mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Changed NodeEditorGUILayout labels to use dynamic output GUIStyle based on EditorStyles.label
This will make it easier to change node text color
Example:
[CustomNodeEditor(typeof(MyNode))]
public class MyNodeEditor : NodeEditor {
private static GUIStyle editorLabelStyle;
public override void OnBodyGUI() {
if (editorLabelStyle == null) editorLabelStyle = new GUIStyle(EditorStyles.label);
EditorStyles.label.normal.textColor = Color.green;
base.OnBodyGUI();
EditorStyles.label.normal = editorLabelStyle.normal;
}
}
This commit is contained in:
parent
57b4287613
commit
682dccdd9d
@ -70,13 +70,13 @@ namespace XNodeEditor {
|
|||||||
switch (showBacking) {
|
switch (showBacking) {
|
||||||
case XNode.Node.ShowBackingValue.Unconnected:
|
case XNode.Node.ShowBackingValue.Unconnected:
|
||||||
// Display a label if port is connected
|
// Display a label if port is connected
|
||||||
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30));
|
||||||
// Display an editable property field if port is not connected
|
// Display an editable property field if port is not connected
|
||||||
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
break;
|
break;
|
||||||
case XNode.Node.ShowBackingValue.Never:
|
case XNode.Node.ShowBackingValue.Never:
|
||||||
// Display a label
|
// Display a label
|
||||||
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30));
|
||||||
break;
|
break;
|
||||||
case XNode.Node.ShowBackingValue.Always:
|
case XNode.Node.ShowBackingValue.Always:
|
||||||
// Display an editable property field
|
// Display an editable property field
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace XNodeEditor {
|
namespace XNodeEditor {
|
||||||
public static class NodeEditorResources {
|
public static class NodeEditorResources {
|
||||||
@ -15,9 +16,9 @@ namespace XNodeEditor {
|
|||||||
// Styles
|
// Styles
|
||||||
public static Styles styles { get { return _styles != null ? _styles : _styles = new Styles(); } }
|
public static Styles styles { get { return _styles != null ? _styles : _styles = new Styles(); } }
|
||||||
public static Styles _styles = null;
|
public static Styles _styles = null;
|
||||||
|
public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } }
|
||||||
public class Styles {
|
public class Styles {
|
||||||
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip, nodeHighlight;
|
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight;
|
||||||
|
|
||||||
public Styles() {
|
public Styles() {
|
||||||
GUIStyle baseStyle = new GUIStyle("Label");
|
GUIStyle baseStyle = new GUIStyle("Label");
|
||||||
@ -27,10 +28,6 @@ namespace XNodeEditor {
|
|||||||
inputPort.alignment = TextAnchor.UpperLeft;
|
inputPort.alignment = TextAnchor.UpperLeft;
|
||||||
inputPort.padding.left = 10;
|
inputPort.padding.left = 10;
|
||||||
|
|
||||||
outputPort = new GUIStyle(baseStyle);
|
|
||||||
outputPort.alignment = TextAnchor.UpperRight;
|
|
||||||
outputPort.padding.right = 10;
|
|
||||||
|
|
||||||
nodeHeader = new GUIStyle();
|
nodeHeader = new GUIStyle();
|
||||||
nodeHeader.alignment = TextAnchor.MiddleCenter;
|
nodeHeader.alignment = TextAnchor.MiddleCenter;
|
||||||
nodeHeader.fontStyle = FontStyle.Bold;
|
nodeHeader.fontStyle = FontStyle.Bold;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user