private Rect GetHeaderRect(FlowNode node, Vector2 offset) { NodeStyleAttribute nodeStyle = node.GetType().GetCustomAttribute <NodeStyleAttribute>(); if (nodeStyle == null) { nodeStyle = new NodeStyleAttribute(true); } Texture2D icon = Resources.Load <Texture2D>(nodeStyle.iconPath); Vector2 size = Vector2.zero; if (nodeStyle.displayHeader) { size = EditorStyles.label.CalcSize(new GUIContent(ObjectNames.NicifyVariableName(node.name))); size.x += NODE_CONTENT_OFFSET * 2; if (icon != null) { size.x += icon.width + NODE_CONTENT_OFFSET; } size.y = NODE_HEADER_HEIGHT; } size.x = Mathf.Clamp(size.x, NODE_MIN_WIDTH, float.PositiveInfinity); return(new Rect(node.position.x + offset.x, node.position.y + offset.y, size.x, size.y)); }
private void DrawNodeHeader(Rect rect, FlowNode node, bool selected) { NodeStyleAttribute nodeStyle = node.GetType().GetCustomAttribute <NodeStyleAttribute>(); if (nodeStyle == null) { nodeStyle = new NodeStyleAttribute(true); } if (!nodeStyle.displayHeader) { return; } Styles.nodeHeaderText.fontStyle = selected ? FontStyle.Bold : FontStyle.Normal; Texture2D icon = Resources.Load <Texture2D>(nodeStyle.iconPath); if (icon != null) { GUI.Label(new Rect(rect.x + NODE_CONTENT_OFFSET, rect.y + NODE_HEADER_HEIGHT * 0.5f - icon.height * 0.5f, icon.width, icon.height), icon); } GUI.Label(new Rect(rect.x + NODE_CONTENT_OFFSET + (icon != null ? icon.width + 3 : 0), rect.y, rect.width, NODE_HEADER_HEIGHT), node.name, Styles.nodeHeaderText); if (Event.current.type == EventType.Repaint) { Styles.seperator.Draw(new Rect(rect.x, rect.y + NODE_HEADER_HEIGHT, rect.width, 1), false, false, false, false); } }
protected override Rect GetNodeRect(FlowNode node, Vector2 offset) { NodeStyleAttribute nodeStyle = node.GetType().GetCustomAttribute <NodeStyleAttribute>(); if (nodeStyle == null) { nodeStyle = new NodeStyleAttribute(true); } Texture2D icon = Resources.Load <Texture2D>(nodeStyle.iconPath); Vector2 size = Vector2.zero; Vector2 headerSize = Vector2.zero; if (nodeStyle.displayHeader) { headerSize = EditorStyles.label.CalcSize(new GUIContent(ObjectNames.NicifyVariableName(node.name))); headerSize.x += NODE_CONTENT_OFFSET * 2; if (headerSize.x > NODE_MIN_WIDTH) { headerSize.x += NODE_CONTENT_OFFSET; } if (icon != null) { headerSize.x += icon.width + NODE_CONTENT_OFFSET; } headerSize.y = NODE_HEADER_HEIGHT; } size.x = Mathf.Clamp(headerSize.x, NODE_MIN_WIDTH, float.PositiveInfinity); float maxWidth = GetContentWidth(node); float width = maxWidth + NODE_CONTENT_OFFSET * 2 + (!nodeStyle.displayHeader && icon != null?icon.width + NODE_CONTENT_OFFSET:0f); if (width > size.x) { size.x = width; } size.y = Mathf.Clamp(headerSize.y + node.InputPorts.Count * NODE_LINE_HEIGHT, NODE_LINE_HEIGHT, float.MaxValue); return(new Rect(node.position.x + offset.x, node.position.y + offset.y, size.x, size.y)); }
private Rect GetPortRect(Port port) { Rect rect = GetNodeRect(port.node, this.m_GraphOffset); int index = port.node.Ports.IndexOf(port); if (port.direction == PortDirection.Input) { Vector2 inputPosition = new Vector2(rect.x - NODE_PORT_OFFSET, rect.y + NODE_LINE_HEIGHT * 0.5f - NODE_PORT_SIZE * 0.5f) + new Vector2(0f, GetHeaderRect(port.node, this.m_GraphOffset).height + NODE_LINE_HEIGHT * index); return(new Rect(inputPosition.x, inputPosition.y, NODE_PORT_SIZE, NODE_PORT_SIZE)); } else { NodeStyleAttribute nodeStyle = port.node.GetType().GetCustomAttribute <NodeStyleAttribute>(); int height = (nodeStyle != null && !nodeStyle.displayHeader) ? NODE_LINE_HEIGHT : NODE_HEADER_HEIGHT; Vector2 outputPosition = new Vector2(rect.x + rect.width + NODE_PORT_OFFSET - NODE_PORT_SIZE, rect.y - NODE_PORT_SIZE * 0.5f) + new Vector2(0f, height * 0.5f); return(new Rect(outputPosition.x, outputPosition.y, NODE_PORT_SIZE, NODE_PORT_SIZE)); } }
private void DrawPortFields(Rect rect, FlowNode node) { float labelWidth = GetLabelWidth(node); float fieldWidth = GetFieldWidth(node); for (int i = 0; i < node.Ports.Count; i++) { Port port = node.GetPort(i); if (port.direction == PortDirection.Input) { Rect labelRect = new Rect(rect.x + NODE_CONTENT_OFFSET, rect.y + NODE_LINE_HEIGHT * i + GetHeaderRect(node, this.m_GraphOffset).height + (NODE_LINE_HEIGHT - NODE_FIELD_HEIGHT) * 0.5f, labelWidth, NODE_FIELD_HEIGHT); if (port.Connections.Count == 0) { FieldInfo field = port.node.GetType().GetField(port.fieldName); object value = field.GetValue(port.node); if (port.label) { GUI.Label(labelRect, ObjectNames.NicifyVariableName(port.fieldName), Styles.nodeText); } Rect fieldRect = new Rect(rect.x + NODE_CONTENT_OFFSET + (port.label?labelWidth + NODE_CONTENT_OFFSET:0f), rect.y + NODE_LINE_HEIGHT * i + GetHeaderRect(node, this.m_GraphOffset).height + (NODE_LINE_HEIGHT - NODE_FIELD_HEIGHT) * 0.5f, fieldWidth, NODE_FIELD_HEIGHT); EditorGUI.BeginChangeCheck(); if (port.fieldType == typeof(float)) { value = EditorGUI.FloatField(fieldRect, (float)value); } else if (port.fieldType == typeof(string)) { value = EditorGUI.TextField(fieldRect, (string)value); } else if (port.fieldType == typeof(AnimationCurve)) { value = EditorGUI.CurveField(fieldRect, (AnimationCurve)value); } if (EditorGUI.EndChangeCheck()) { field.SetValue(port.node, value); GraphUtility.Save(this.m_Graph); PrefabUtility.RecordPrefabInstancePropertyModifications(this.m_Target); } } else { GUI.Label(labelRect, ObjectNames.NicifyVariableName(port.fieldName), Styles.nodeText); } } NodeStyleAttribute nodeStyle = node.GetType().GetCustomAttribute <NodeStyleAttribute>(); if (nodeStyle == null) { nodeStyle = new NodeStyleAttribute(true); } Texture2D icon = Resources.Load <Texture2D>(nodeStyle.iconPath); if (!nodeStyle.displayHeader && icon != null) { GUI.Label(new Rect(rect.x + rect.width - NODE_CONTENT_OFFSET - icon.width, rect.y + rect.height * 0.5f - icon.height * 0.5f, icon.width, icon.height), icon); } if (Event.current.type == EventType.Repaint) // && port.drawPort) { if (i > 0 && i < node.Ports.Count - 1) { Styles.seperator.Draw(new Rect(rect.x, rect.y + GetHeaderRect(node, this.m_GraphOffset).height + i * NODE_LINE_HEIGHT, !nodeStyle.displayHeader && icon != null ? GetContentWidth(node) + NODE_CONTENT_OFFSET * 1.6f:rect.width, 1f), false, false, false, false); } } } }