public void DrawNode() { if (NodeSerializedObject == null) { NodeSerializedObject = new SerializedObject(NodeData.Node); } var headerRect = NodeData.HeaderRect; var bodyRect = NodeData.BodyRect; headerRect.position = BaseNodeWindow.GraphToScreenSpace(headerRect.position); bodyRect.position = BaseNodeWindow.GraphToScreenSpace(bodyRect.position); var labelCol = EditorStyles.label.normal.textColor; GUI.backgroundColor = NodeData.Node.NodeColor; GUILayout.BeginArea(headerRect); GUILayout.BeginVertical(NodeStyles.Instance.NodeHeader); GUI.backgroundColor = Color.white; OnNodeHeaderGUI(); GUILayout.EndArea(); GUILayout.EndVertical(); GUI.backgroundColor = NodeStyles.Instance.NodeBodyColor; GUILayout.BeginArea(bodyRect); GUILayout.BeginVertical(NodeStyles.Instance.NodeBody); GUI.backgroundColor = Color.white; EditorStyles.label.normal.textColor = NodeStyles.Instance.NodeLabelColor; OnNodeBodyGUI(); GUILayout.EndArea(); GUILayout.EndVertical(); EditorStyles.label.normal.textColor = labelCol; // Draw ports DrawPorts(); }
private void DrawPorts() { var nodeType = NodeData.Node.GetType(); var ports = NodeCache.NodePortCaches[nodeType]; var portSize = NodePreferences.Instance.PortSize; for (var i = 0; i < ports.Count; i++) { var portWrapper = ports[i]; var fieldName = portWrapper.FieldName; if (!_fieldPositions.ContainsKey(fieldName)) { continue; } var fieldRect = _fieldPositions[fieldName]; var fieldPosition = fieldRect.position; var portCol = Color.white; var portOffset = new Vector2(NodePreferences.Instance.PortOffset, (fieldRect.size.y - portSize.y) / 2); var inputPos = fieldPosition - portSize.x * Vector2.right - portOffset; var outputPos = fieldPosition + fieldRect.width * Vector2.right + portOffset; if (_inputPortDatas.ContainsKey(fieldName)) { var portData = _inputPortDatas[fieldName]; portData.Rect = new Rect(inputPos, portSize); var filedTypeName = portData.TypeName; if (!NodePreferences.Instance.FieldTypeColor.ContainsKey(filedTypeName)) { NodePreferences.Instance.FieldTypeColor.Add(filedTypeName, Color.white); } portCol = NodePreferences.Instance.FieldTypeColor[filedTypeName]; } if (_outPutPortDatas.ContainsKey(fieldName)) { var portData = _outPutPortDatas[fieldName]; portData.Rect = new Rect(outputPos, portSize); var filedTypeName = portData.TypeName; if (!NodePreferences.Instance.FieldTypeColor.ContainsKey(filedTypeName)) { NodePreferences.Instance.FieldTypeColor.Add(filedTypeName, Color.white); } portCol = NodePreferences.Instance.FieldTypeColor[filedTypeName]; } inputPos = BaseNodeWindow.GraphToScreenSpace(inputPos); outputPos = BaseNodeWindow.GraphToScreenSpace(outputPos); var backgroundCol = GUI.color; GUI.color = portCol; // Inpus if (portWrapper.InspectType == InspectType.Input || portWrapper.InspectType == InspectType.Both) { GUI.DrawTexture(new Rect(inputPos, portSize), NodeStyles.Instance.NodeInputPort); } // Outputs if (portWrapper.InspectType == InspectType.Output || portWrapper.InspectType == InspectType.Both) { GUI.DrawTexture(new Rect(outputPos, portSize), NodeStyles.Instance.NodeOutputPort); } GUI.color = backgroundCol; } }