From 84e2af7916303cbc205017ce5ca0af0ffe9f4c75 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Sat, 16 Feb 2019 01:32:52 +0100 Subject: [PATCH] Cleanup Postfixed attribute classes with Attribute Added Attributes region --- Scripts/Editor/NodeEditorReflection.cs | 8 ++++---- Scripts/Node.cs | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs index 04c6484..21dbf7a 100644 --- a/Scripts/Editor/NodeEditorReflection.cs +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -42,9 +42,9 @@ namespace XNodeEditor { public static Dictionary GetNodeTint() { Dictionary tints = new Dictionary(); for (int i = 0; i < nodeTypes.Length; i++) { - var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeTint), true); + var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeTintAttribute), true); if (attribs == null || attribs.Length == 0) continue; - XNode.Node.NodeTint attrib = attribs[0] as XNode.Node.NodeTint; + XNode.Node.NodeTintAttribute attrib = attribs[0] as XNode.Node.NodeTintAttribute; tints.Add(nodeTypes[i], attrib.color); } return tints; @@ -53,9 +53,9 @@ namespace XNodeEditor { public static Dictionary GetNodeWidth() { Dictionary widths = new Dictionary(); for (int i = 0; i < nodeTypes.Length; i++) { - var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeWidth), true); + var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeWidthAttribute), true); if (attribs == null || attribs.Length == 0) continue; - XNode.Node.NodeWidth attrib = attribs[0] as XNode.Node.NodeWidth; + XNode.Node.NodeWidthAttribute attrib = attribs[0] as XNode.Node.NodeWidthAttribute; widths.Add(nodeTypes[i], attrib.width); } return widths; diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 4a9ace9..43d716e 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -63,7 +63,6 @@ namespace XNode { /// Used during node instantiation to fix null/misconfigured graph during OnEnable/Init. Set it before instantiating a node. Will automatically be unset during OnEnable public static NodeGraph graphHotfix; - protected void OnEnable() { if (graphHotfix != null) graph = graphHotfix; graphHotfix = null; @@ -210,6 +209,7 @@ namespace XNode { return JsonUtility.ToJson(this).GetHashCode(); } +#region Attributes /// Mark a serializable field as an input port. You can access this through [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] public class InputAttribute : Attribute { @@ -255,19 +255,19 @@ namespace XNode { } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class NodeTint : Attribute { + public class NodeTintAttribute : Attribute { public Color color; /// Specify a color for this node type /// Red [0.0f .. 1.0f] /// Green [0.0f .. 1.0f] /// Blue [0.0f .. 1.0f] - public NodeTint(float r, float g, float b) { + public NodeTintAttribute(float r, float g, float b) { color = new Color(r, g, b); } /// Specify a color for this node type /// HEX color value - public NodeTint(string hex) { + public NodeTintAttribute(string hex) { ColorUtility.TryParseHtmlString(hex, out color); } @@ -275,20 +275,21 @@ namespace XNode { /// Red [0 .. 255] /// Green [0 .. 255] /// Blue [0 .. 255] - public NodeTint(byte r, byte g, byte b) { + public NodeTintAttribute(byte r, byte g, byte b) { color = new Color32(r, g, b, byte.MaxValue); } } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class NodeWidth : Attribute { + public class NodeWidthAttribute : Attribute { public int width; /// Specify a width for this node type /// Width - public NodeWidth(int width) { + public NodeWidthAttribute(int width) { this.width = width; } } +#endregion [Serializable] private class NodePortDictionary : Dictionary, ISerializationCallbackReceiver { [SerializeField] private List keys = new List();