public void AddNodes(NodeComponent nodeComponent, TreeViewItem parentItem, IList <TreeViewItem> rows, bool isChildren = true) { if (nodeTreesMap.TryGetValue(nodeComponent, out var childItem)) { var tree = new HierarchyRefNodeTree(childItem, -1); if (isChildren) { parentItem.AddChild(tree); } else { parentItem.parent.AddChild(tree); } rows.Add(tree); return; } var drawer = HierarchyDrawer.FindDrawer(nodeComponent.GetType()); drawer.manager = this; //Create Node Tree childItem = drawer.CreateNodeTree(nodeComponent); if (isChildren) { AddSummary(nodeComponent.comment, childItem, parentItem, rows); parentItem.AddChild(childItem); } else { AddSummary(nodeComponent.comment, childItem, parentItem.parent, rows); parentItem.parent.AddChild(childItem); } rows.Add(childItem); nodeTreesMap[nodeComponent] = childItem; drawer.AddChildNodes(nodeComponent, childItem, rows); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); NodeComponent comp = target as NodeComponent; if (comp == null) { return; } EditorGUI.BeginChangeCheck(); if (comp is MacroNode) { MacroNode node = comp as MacroNode; VariableEditorUtility.DrawVariable(node.variables, node, (v) => { node.variables = v; }, null); VariableEditorUtility.DrawCustomList( node.inputFlows, "Input Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.outputFlows, "Output Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.inputValues, "Input Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); VariableEditorUtility.DrawCustomList( node.outputValues, "Output Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); } else if (comp is LinkedMacroNode) { LinkedMacroNode node = comp as LinkedMacroNode; if (node.macroAsset != null) { VariableEditorUtility.DrawLinkedVariables(node, node.macroAsset, publicOnly: false); EditorGUI.BeginDisabledGroup(true); VariableEditorUtility.DrawCustomList( node.inputFlows, "Input Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.outputFlows, "Output Flows", (position, index, element) => { //Draw Element EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)))); }, null, null); VariableEditorUtility.DrawCustomList( node.inputValues, "Input Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); VariableEditorUtility.DrawCustomList( node.outputValues, "Output Values", (position, index, element) => { //Draw Element position.width -= EditorGUIUtility.labelWidth; EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType()))); position.x += EditorGUIUtility.labelWidth; uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element); }, null, null); EditorGUI.EndDisabledGroup(); } } uNodeGUIUtility.ShowField("comment", comp, comp); if (comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false).Length > 0) { DescriptionAttribute descriptionEvent = (DescriptionAttribute)comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false)[0]; if (descriptionEvent.description != null && descriptionEvent != null) { GUI.backgroundColor = Color.yellow; EditorGUILayout.HelpBox("Description: " + descriptionEvent.description, MessageType.None); GUI.backgroundColor = Color.white; } } if (EditorGUI.EndChangeCheck()) { uNodeEditorUtility.MarkDirty(comp); uNodeGUIUtility.GUIChanged(comp); } }
public virtual void AddChildNodes(NodeComponent nodeComponent, TreeViewItem parentTree, IList <TreeViewItem> rows) { var fields = EditorReflectionUtility.GetFields(nodeComponent.GetType()); foreach (var field in fields) { var fieldType = field.FieldType; if (field.IsDefinedAttribute(typeof(FieldConnectionAttribute))) { var attributes = EditorReflectionUtility.GetAttributes(field); var FCA = ReflectionUtils.GetAttribute <FieldConnectionAttribute>(attributes); bool isFlow = nodeComponent is Node && (nodeComponent as Node).IsFlowNode(); if (FCA.hideOnFlowNode && isFlow) { continue; } if (FCA.hideOnNotFlowNode && !isFlow) { continue; } if (fieldType == typeof(MemberData)) { if (FCA.isFlowConnection) { MemberData member = field.GetValueOptimized(nodeComponent) as MemberData; if (member != null) { if (!FCA.isFinishedFlow && field.Name != nameof(MultipurposeNode.onFinished)) { if (FCA.displayFlowInHierarchy) { var flowItem = CreateFlowTree( nodeComponent, field.Name, member, FCA.label != null ? FCA.label.text : field.Name ); parentTree.AddChild(flowItem); rows.Add(flowItem); manager.AddNodeTree(member, flowItem, rows); } else { manager.AddNodeTree(member, parentTree, rows); } } else { manager.AddNodeTree(member, parentTree, rows, false); } } } } else if (fieldType == typeof(List <MemberData>) && FCA.isFlowConnection) { List <MemberData> members = field.GetValueOptimized(nodeComponent) as List <MemberData>; if (members != null && members.Count > 0) { foreach (var member in members) { if (member != null && member.isAssigned && member.IsTargetingPinOrNode) { Node n = member.GetTargetNode(); if (n != null) { manager.AddNodes(n, parentTree, rows, isChildren: !FCA.isFinishedFlow && field.Name != nameof(MultipurposeNode.onFinished)); } } } } } } else if (fieldType == typeof(EventData)) { var blocks = field.GetValueOptimized(nodeComponent) as EventData; AddBlocks(blocks, field.Name, parentTree, rows); } } }
private static string GenerateFlowCode(IFlowGenerate flowInput, NodeComponent source) { if (flowInput == null) { throw new ArgumentNullException("flowInput"); } if (source == null) { throw new ArgumentNullException("source"); } string data; try { data = flowInput.GenerateCode(); if (setting.fullComment && !string.IsNullOrEmpty(data)) { data = data.Insert(0, "//" + source.gameObject.name + " : " + flowInput.ToString() + " | Type:" + ParseType(source.GetType()).AddLineInEnd()); } data = data.AddLineInFirst(); } catch (Exception ex) { if (!generatorData.hasError) { if (setting != null && setting.isAsync) { generatorData.errors.Add(ex); //In case async return error commentaries. return("/*Error from node: " + source.gameObject.name + " : " + flowInput.ToString() + " */"); } Debug.LogError("Error from node:" + source.gameObject.name + " : " + flowInput.ToString() + " |Type:" + source.GetType() + "\nError:" + ex.ToString(), source); } generatorData.hasError = true; throw; } if (includeGraphInformation) { data = WrapWithInformation(data, source); } return(data); }