mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
Added NodeHeightAttribute for minimum height.
This commit is contained in:
parent
133d15703a
commit
524bcc389b
@ -118,6 +118,12 @@ namespace XNodeEditor {
|
|||||||
else return 208;
|
else return 208;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual int GetMinHeight()
|
||||||
|
{
|
||||||
|
Type type = target.GetType();
|
||||||
|
return type.TryGetAttributeHeight(out int height) ? height : 80;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Returns color for target node </summary>
|
/// <summary> Returns color for target node </summary>
|
||||||
public virtual Color GetTint() {
|
public virtual Color GetTint() {
|
||||||
// Try get color from [NodeTint] attribute
|
// Try get color from [NodeTint] attribute
|
||||||
|
|||||||
@ -397,6 +397,7 @@ namespace XNodeEditor {
|
|||||||
if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) selectedReroutes = selection;
|
if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) selectedReroutes = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Rect lastRect;
|
||||||
private void DrawNodes() {
|
private void DrawNodes() {
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
if (e.type == EventType.Layout) {
|
if (e.type == EventType.Layout) {
|
||||||
@ -491,6 +492,14 @@ namespace XNodeEditor {
|
|||||||
nodeEditor.OnHeaderGUI();
|
nodeEditor.OnHeaderGUI();
|
||||||
nodeEditor.OnBodyGUI();
|
nodeEditor.OnBodyGUI();
|
||||||
|
|
||||||
|
//Fill remaining vertical space
|
||||||
|
if (e.type == EventType.Repaint)
|
||||||
|
{
|
||||||
|
lastRect = GUILayoutUtility.GetLastRect();
|
||||||
|
}
|
||||||
|
float remainingSpace = nodeEditor.GetMinHeight() - lastRect.yMax - 17;
|
||||||
|
if (remainingSpace > 0) GUILayout.Space(remainingSpace);
|
||||||
|
|
||||||
//If user changed a value, notify other scripts through onUpdateNode
|
//If user changed a value, notify other scripts through onUpdateNode
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
if (NodeEditor.onUpdateNode != null) NodeEditor.onUpdateNode(node);
|
if (NodeEditor.onUpdateNode != null) NodeEditor.onUpdateNode(node);
|
||||||
|
|||||||
@ -14,6 +14,7 @@ namespace XNodeEditor {
|
|||||||
public static class NodeEditorReflection {
|
public static class NodeEditorReflection {
|
||||||
[NonSerialized] private static Dictionary<Type, Color> nodeTint;
|
[NonSerialized] private static Dictionary<Type, Color> nodeTint;
|
||||||
[NonSerialized] private static Dictionary<Type, int> nodeWidth;
|
[NonSerialized] private static Dictionary<Type, int> nodeWidth;
|
||||||
|
[NonSerialized] private static Dictionary<Type, int> nodeHeight;
|
||||||
[NonSerialized] private static Dictionary<Type, GUIContent> nodeHeader;
|
[NonSerialized] private static Dictionary<Type, GUIContent> nodeHeader;
|
||||||
/// <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(); } }
|
||||||
@ -48,6 +49,14 @@ namespace XNodeEditor {
|
|||||||
return nodeWidth.TryGetValue(nodeType, out width);
|
return nodeWidth.TryGetValue(nodeType, out width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Get custom node heights defined with [NodeHeight(height)] </summary>
|
||||||
|
public static bool TryGetAttributeHeight(this Type nodeType, out int height) {
|
||||||
|
if (nodeHeight == null) {
|
||||||
|
CacheAttributes<int, XNode.Node.NodeHeightAttribute>(ref nodeHeight, x => x.height);
|
||||||
|
}
|
||||||
|
return nodeHeight.TryGetValue(nodeType, out height);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Get custom node headers defined with [NodeHeader] </summary>
|
/// <summary> Get custom node headers defined with [NodeHeader] </summary>
|
||||||
public static bool TryGetAttributeHeader(this Type nodeType, out GUIContent content)
|
public static bool TryGetAttributeHeader(this Type nodeType, out GUIContent content)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace XNode.Flow.Events
|
namespace XNode.Flow.Events
|
||||||
{
|
{
|
||||||
[NodeTint(1.0F,0.25F,0.25F), NodeWidth(75)]
|
[NodeTint(1.0F,0.25F,0.25F), NodeWidth(80), NodeHeight(80)]
|
||||||
public class StartNode : OutFlowNode
|
public class StartNode : OutFlowNode
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -389,6 +389,17 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Specify a minimum height for this node type </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||||
|
public class NodeHeightAttribute : Attribute {
|
||||||
|
public int height;
|
||||||
|
/// <summary> Specify a minimum height for this node type </summary>
|
||||||
|
/// <param name="height"> Minimum Height </param>
|
||||||
|
public NodeHeightAttribute(int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Specify header GUIContent for this node type </summary>
|
/// <summary> Specify header GUIContent for this node type </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||||
public class NodeHeaderAttribute : Attribute
|
public class NodeHeaderAttribute : Attribute
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user