mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Added attribute NodeWidth.
Changes the width used when rendering the node in the editor.
This commit is contained in:
parent
9c6fb74064
commit
c015b6ec4b
@ -58,7 +58,9 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual int GetWidth() {
|
public virtual int GetWidth() {
|
||||||
return 208;
|
Type type = target.GetType();
|
||||||
|
if (NodeEditorWindow.nodeWidth.ContainsKey(type)) return NodeEditorWindow.nodeWidth[type];
|
||||||
|
else return 208;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Color GetTint() {
|
public virtual Color GetTint() {
|
||||||
|
|||||||
@ -13,6 +13,10 @@ namespace XNodeEditor {
|
|||||||
public static Dictionary<Type, Color> nodeTint { get { return _nodeTint != null ? _nodeTint : _nodeTint = GetNodeTint(); } }
|
public static Dictionary<Type, Color> nodeTint { get { return _nodeTint != null ? _nodeTint : _nodeTint = GetNodeTint(); } }
|
||||||
|
|
||||||
[NonSerialized] private static Dictionary<Type, Color> _nodeTint;
|
[NonSerialized] private static Dictionary<Type, Color> _nodeTint;
|
||||||
|
/// <summary> Custom node widths defined with [NodeWidth(width)] </summary>
|
||||||
|
public static Dictionary<Type, int> nodeWidth { get { return _nodeWidth != null ? _nodeWidth : _nodeWidth = GetNodeWidth(); } }
|
||||||
|
|
||||||
|
[NonSerialized] private static Dictionary<Type, int> _nodeWidth;
|
||||||
/// <summary> All available node types </summary>
|
/// <summary> All available node types </summary>
|
||||||
public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } }
|
public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } }
|
||||||
|
|
||||||
@ -34,6 +38,17 @@ namespace XNodeEditor {
|
|||||||
return tints;
|
return tints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<Type, int> GetNodeWidth() {
|
||||||
|
Dictionary<Type, int> widths = new Dictionary<Type, int>();
|
||||||
|
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||||
|
var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeWidth), true);
|
||||||
|
if (attribs == null || attribs.Length == 0) continue;
|
||||||
|
XNode.Node.NodeWidth attrib = attribs[0] as XNode.Node.NodeWidth;
|
||||||
|
widths.Add(nodeTypes[i], attrib.width);
|
||||||
|
}
|
||||||
|
return widths;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Get all classes deriving from baseType via reflection </summary>
|
/// <summary> Get all classes deriving from baseType via reflection </summary>
|
||||||
public static Type[] GetDerivedTypes(Type baseType) {
|
public static Type[] GetDerivedTypes(Type baseType) {
|
||||||
List<System.Type> types = new List<System.Type>();
|
List<System.Type> types = new List<System.Type>();
|
||||||
|
|||||||
@ -272,6 +272,16 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||||
|
public class NodeWidth : Attribute {
|
||||||
|
public int width;
|
||||||
|
/// <summary> Specify a width for this node type </summary>
|
||||||
|
/// <param name="width"> Width </param>
|
||||||
|
public NodeWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable] private class NodePortDictionary : Dictionary<string, NodePort>, ISerializationCallbackReceiver {
|
[Serializable] private class NodePortDictionary : Dictionary<string, NodePort>, ISerializationCallbackReceiver {
|
||||||
[SerializeField] private List<string> keys = new List<string>();
|
[SerializeField] private List<string> keys = new List<string>();
|
||||||
[SerializeField] private List<NodePort> values = new List<NodePort>();
|
[SerializeField] private List<NodePort> values = new List<NodePort>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user