private static void AddNode(Canvas canvas, NodePort parentInput, ExpressionTreeNode expressionNode, List<NumberParam> variables, Point location, Int32 levelStep, Int32 minY, Int32 maxY) { Int32 leafs = (expressionNode.LeftNode != null ? 1 : 0) + (expressionNode.RightNode != null ? 1 : 0); NodeBase node = null; if (expressionNode.Token.IsNumber) { node = new VisiTypes.Number(Double.Parse(expressionNode.Token.TokenBody)); canvas.AddNode(node, location); } if (expressionNode.Token.IsVariable) { Boolean exist = false; foreach (NumberParam param in variables) { if (param.Name == expressionNode.Token.TokenBody) { exist = true; node = param; break; } } if (!exist) { node = new NumberParam(); ((NumberParam)node).Name = expressionNode.Token.TokenBody; ((NumberParam)node).Header = expressionNode.Token.TokenBody; variables.Add((NumberParam)node); canvas.AddNode(node, location); } } if (expressionNode.Token.IsOperator) { node = new Operator(expressionNode.Token.OperatorDescriptor); canvas.AddNode(node, location); switch (leafs) { case 1: { AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, location.Y), levelStep, minY, maxY); break; } case 2: { Int32 y2 = (maxY - minY) / 2; AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, minY + y2 / 2), levelStep, minY, minY + y2); AddNode(canvas, node.GetInput(1), expressionNode.RightNode, variables, new Point(location.X - levelStep, maxY - y2 / 2), levelStep, maxY - y2, maxY); break; } } } if (parentInput != null && node != null) { parentInput.Connection = node.GetOutput(0); } }
public override object GetValue(NodePort port) { return(this); }
// Return the correct value of an output port when requested public override object GetValue(NodePort port) { return(UpdateFeature()); }
public override object GetValue(NodePort port) { return(GetInputValue <bool>("a").Equals(GetInputValue <bool>("b"))); }
public override object GetValue(NodePort port) { return(base.GetValue(port)); }
public override object GetValue(NodePort port) { return(port.fieldName == nameof(this.output) ? this.GetOutput() : base.GetValue(port)); }
// Add Connector private ConnectorViewModel Connect(NodeViewModel headnode, NodeViewModel tailnode, NodePort headport = null, NodePort tailport = null, ConnectorViewModel connector = null, ConnectorPort connectorheadport = null, ConnectorPort connectortailport = null, String label1 = null, String label2 = null, Style style = null, Thickness margin = new Thickness()) { ConnectorViewModel Connectorviewmodel = new ConnectorViewModel(); Connectorviewmodel.ZIndex = -1; Connectorviewmodel.SourceNode = headnode; Connectorviewmodel.TargetNode = tailnode; //To Represent Annotation Properties Connectorviewmodel.Annotations = new ObservableCollection <IAnnotation>() { new TextAnnotationViewModel() { Text = label2, WrapText = TextWrapping.Wrap, TextHorizontalAlignment = TextAlignment.Center, UnitWidth = 170, Margin = margin, ReadOnly = true, } }; if (headport != null) { Connectorviewmodel.SourcePort = headport; } else { Connectorviewmodel.SourcePort = connectorheadport; } if (tailport != null) { Connectorviewmodel.TargetPort = tailport; } else { Connectorviewmodel.TargetPort = connectortailport; } if (tailnode != null) { Connectorviewmodel.SourceConnector = connector; } else { Connectorviewmodel.TargetConnector = connector; } Connectorviewmodel.TargetDecoratorStyle = View.Resources["DecoratorStyle"] as Style; if ((label1 == "c3") || (label1 == "c4") || (label1 == "c5") || (label1 == "c6")) { Connectorviewmodel.TargetDecorator = null; Connectorviewmodel.TargetDecoratorStyle = null; } if (style != null) { Connectorviewmodel.ConnectorGeometryStyle = style; } (Connectors as ObservableCollection <ConnectorViewModel>).Add(Connectorviewmodel); return(Connectorviewmodel); }
//INodeNoodles: Label das conexões public virtual string GetNoodleLabel(NodePort port) { return(this.name); }
public override void OnRemoveConnection(NodePort port) { base.OnRemoveConnection(port); DoDisConnectToList(port, ref inputs); }
public override void OnCreateConnection(NodePort from, NodePort to) { base.OnCreateConnection(from, to); UpdateTexture(); }
public override void OnRemoveConnection(NodePort port) { base.OnRemoveConnection(port); PreviewTexture = null; }
public override object GetValue(NodePort port) { return(_folderRefs.Distinct().ToArray()); }
public override void OnRemoveConnection(NodePort port) { UpdateAllOutputNodes(); }
#pragma warning restore 0649 public override void OnCreateConnection(NodePort @from, NodePort to) { UpdateAllOutputNodes(); }
public override object GetValue(NodePort port) { return(GetInputValue("x", x) - GetInputValue("y", y)); }
public override void OnCreateConnection(NodePort from, NodePort to) { base.OnCreateConnection(from, to); DoCreateConnectToList(from, to, ref inputs, "inputs"); }
public override object GetValue(NodePort port) { return(Texture); }
public static void DrawOutputs(XNode.Node target, SerializedObject serializedObject) { NodePort outputPort = target.GetOutputPort("output"); serializedObject.FindProperty("outputFoldout").boolValue = EditorGUILayout.Foldout(serializedObject.FindProperty("outputFoldout").boolValue, "Outputs [" + outputPort.ConnectionCount + "]", true); bool outputFoldout = serializedObject.FindProperty("outputFoldout").boolValue; GUIStyle labelStyle = new GUIStyle(EditorStyles.label); GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButton); labelStyle.wordWrap = true; if (outputFoldout) { for (int i = 0; i < outputPort.ConnectionCount; i++) { EditorGUILayout.BeginHorizontal(); NodePort outputConnectionPort = outputPort.GetConnection(i); Node outputConnectionNode = outputPort.GetConnection(i).node; if (outputConnectionNode is Answer) { string label = (outputConnectionNode as Answer).dialogue; label = label.Replace("\n", ""); label = label.Substring(0, Mathf.Min(32, label.Length)); EditorGUILayout.LabelField(string.Format("[{0}] {1}", "Answer", label, labelStyle)); } else if (outputConnectionNode is Dialogue) { string label = (outputConnectionNode as Dialogue).dialogue; label = label.Replace("\n", ""); label = label.Substring(0, Mathf.Min(32, label.Length)); EditorGUILayout.LabelField(string.Format("[{0}] {1}", "Dialogue", label, labelStyle)); } else if (outputConnectionNode is Group) { string label = (outputConnectionNode as Group).name; label = label.Replace("\n", ""); label = label.Substring(0, Mathf.Min(32, label.Length)); EditorGUILayout.LabelField(string.Format("[{0}] {1}", "Group", label, labelStyle)); } if (GUILayout.Button("^", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { if (i <= 0) { return; } outputPort.SwitchConnections(i, i - 1); } if (GUILayout.Button("v", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { if (i >= outputPort.ConnectionCount - 1) { return; } outputPort.SwitchConnections(i, i + 1); } EditorGUILayout.EndHorizontal(); } } }
private static void AddNode(Canvas canvas, NodePort parentInput, ExpressionTreeNode expressionNode, List <NumberParam> variables, Point location, Int32 levelStep, Int32 minY, Int32 maxY) { Int32 leafs = (expressionNode.LeftNode != null ? 1 : 0) + (expressionNode.RightNode != null ? 1 : 0); NodeBase node = null; if (expressionNode.Token.IsNumber) { node = new VisiTypes.Number(Double.Parse(expressionNode.Token.TokenBody)); canvas.AddNode(node, location); } if (expressionNode.Token.IsVariable) { Boolean exist = false; foreach (NumberParam param in variables) { if (param.Name == expressionNode.Token.TokenBody) { exist = true; node = param; break; } } if (!exist) { node = new NumberParam(); ((NumberParam)node).Name = expressionNode.Token.TokenBody; ((NumberParam)node).Header = expressionNode.Token.TokenBody; variables.Add((NumberParam)node); canvas.AddNode(node, location); } } if (expressionNode.Token.IsOperator) { node = new Operator(expressionNode.Token.OperatorDescriptor); canvas.AddNode(node, location); switch (leafs) { case 1: { AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, location.Y), levelStep, minY, maxY); break; } case 2: { Int32 y2 = (maxY - minY) / 2; AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, minY + y2 / 2), levelStep, minY, minY + y2); AddNode(canvas, node.GetInput(1), expressionNode.RightNode, variables, new Point(location.X - levelStep, maxY - y2 / 2), levelStep, maxY - y2, maxY); break; } } } if (parentInput != null && node != null) { parentInput.Connection = node.GetOutput(0); } }
public void UpdateData <T>() { // Check if context type has change if (!string.Equals(typeof(T).AssemblyQualifiedName, _declaringTypeName)) { _declaringTypeName = typeof(T).AssemblyQualifiedName; foreach (KeyValuePair <string, SerializableInfo> pair in InfoDictionary) { pair.Value.DeclaringTypeName = _declaringTypeName; } } // Handle fields FieldInfo[] fieldInfos = typeof(T).GetFields(SerializableInfo.DefaultBindingFlags); foreach (FieldInfo fieldInfo in fieldInfos) { if (PortDictionary.ContainsKey(fieldInfo.Name)) { continue; } SerializableInfo serializableFieldInfo = new SerializableInfo(fieldInfo); PortDictionary.Add(fieldInfo.Name, serializableFieldInfo.PortName); NodePort newPort = AddDynamicOutput(serializableFieldInfo.Type, ConnectionType.Multiple, TypeConstraint.None, serializableFieldInfo.PortName); InfoDictionary.Add(serializableFieldInfo.PortName, serializableFieldInfo); // Redirect port using FormerlySerializedAsAttribute FormerlySerializedAsAttribute attribute = fieldInfo.GetCustomAttribute <FormerlySerializedAsAttribute>(); if (attribute != null && PortDictionary.ContainsKey(attribute.oldName)) { GetPort(PortDictionary[attribute.oldName]).SwapConnections(newPort); } } // Handle properties PropertyInfo[] propertyInfos = typeof(T).GetProperties(SerializableInfo.DefaultBindingFlags); foreach (PropertyInfo propertyInfo in propertyInfos) { if (PortDictionary.ContainsKey(propertyInfo.Name)) { continue; } SerializableInfo serializablePropertyInfo = new SerializableInfo(propertyInfo); PortDictionary.Add(propertyInfo.Name, serializablePropertyInfo.PortName); NodePort newPort = AddDynamicOutput(serializablePropertyInfo.Type, ConnectionType.Multiple, TypeConstraint.None, serializablePropertyInfo.PortName); InfoDictionary.Add(serializablePropertyInfo.PortName, serializablePropertyInfo); // Redirect port using FormerlySerializedAsAttribute FormerlySerializedAsAttribute attribute = propertyInfo.GetCustomAttribute <FormerlySerializedAsAttribute>(); if (attribute != null && PortDictionary.ContainsKey(attribute.oldName)) { GetPort(PortDictionary[attribute.oldName]).SwapConnections(newPort); } } // Remove old ports for (int i = PortDictionary.Count - 1; i >= 0; i--) { if (fieldInfos.Any(info => info.Name == PortDictionary.ElementAt(i).Key)) { continue; } if (propertyInfos.Any(info => info.Name == PortDictionary.ElementAt(i).Key)) { continue; } RemoveDynamicPort(PortDictionary.ElementAt(i).Value); InfoDictionary.Remove(PortDictionary.ElementAt(i).Value); PortDictionary.Remove(PortDictionary.ElementAt(i).Key); } }
// Create Nodes,Ports and Connections private void CreateNodesandConnections() { // Create Nodes NodeViewModel node1 = AddNode(50, 100, 100, 50, label: "Employee"); NodeViewModel node2 = AddNode(50, 100, 300, 50, label: "Team Lead"); NodeViewModel node3 = AddNode(50, 100, 500, 50, label: "Dashboard"); NodeViewModel node4 = AddNode(50, 100, 700, 50, label: "Manager"); NodeViewModel node8 = AddNode(50, 100, 100, 500); NodeViewModel node9 = AddNode(50, 100, 300, 500); NodeViewModel node10 = AddNode(50, 100, 500, 500); NodeViewModel node11 = AddNode(50, 100, 700, 500); // Connect Nodes and Ports ConnectorViewModel connector3 = Connect(node1, node8, label1: "c3", style: View.Resources["GetGrayLineStyle"] as Style); ConnectorViewModel connector4 = Connect(node2, node9, label1: "c4", style: View.Resources["GetGrayLineStyle"] as Style); ConnectorViewModel connector5 = Connect(node3, node10, label1: "c5", style: View.Resources["GetGrayLineStyle"] as Style); ConnectorViewModel connector6 = Connect(node4, node11, label1: "c6", style: View.Resources["GetGrayLineStyle"] as Style); NodeViewModel node5 = AddNode(180, 10, 300, 250, style: View.Resources["GetNodeStyle"] as Style); NodeViewModel node6 = AddNode(25, 10, 500, 250, style: View.Resources["GetNodeStyle"] as Style); NodeViewModel node7 = AddNode(48, 10, 700, 348, style: View.Resources["GetNodeStyle"] as Style); NodeViewModel node26 = AddNode(240, 10, 100, 278, style: View.Resources["GetNodeStyle"] as Style); // Create Ports to the Nodes and Connectors NodePort port1 = addPort(node5, 0, 0.053); NodePort port111 = addPort(node5, 1, 0.5); NodePort port12 = addPort(node5, 1, 0.938); NodePort port2 = addPort(node6, 0, 0.5); NodePort port3 = addPort(node7, 0, 0.1); NodePort port10 = addPort(node7, 0, 0.91); NodePort port11 = addPort(node26, 1, 0.049); NodePort port7 = addPort(node26, 1, 0.97); node5.Ports = new ObservableCollection <INodePort>() { port1, port111, port12 }; node6.Ports = new ObservableCollection <INodePort>() { port2 }; node7.Ports = new ObservableCollection <INodePort>() { port3, port10 }; node26.Ports = new ObservableCollection <INodePort>() { port11, port7 }; ConnectorViewModel connector1 = Connect(node5, node6, headport: port111, tailport: port2, label2: "Check Employee availability and task status", style: View.Resources["GetBlueLineStyle"] as Style, margin: new Thickness(0, 20, 0, 0)); ConnectorViewModel connector2 = Connect(node5, node7, headport: port12, tailport: port3, label2: "Forward Leave Request", style: View.Resources["GetBlueLineStyle"] as Style, margin: new Thickness(0, 10, 0, 0)); ConnectorViewModel connector7 = Connect(node26, node5, headport: port11, tailport: port1, label2: "Leave Request", style: View.Resources["GetBlueLineStyle"] as Style, margin: new Thickness(0, 10, 0, 0)); ConnectorPort port5 = addPort(connector4, 0.78); ConnectorPort port6 = addPort(connector4, 0.73); connector4.Ports = new ObservableCollection <IConnectorPort>() { port5, port6 }; ConnectorViewModel connector8 = Connect(null, node26, tailport: port7, connector: connector4, connectorheadport: port5, label2: "Leave Approval", style: View.Resources["GetLineDashStyle"] as Style, margin: new Thickness(0, -10, 0, 0)); ConnectorViewModel connector10 = Connect(node7, null, headport: port10, connector: connector4, connectortailport: port6, label2: "No Objection", style: View.Resources["GetLineDashStyle"] as Style, margin: new Thickness(0, -10, 0, 0)); }
/// <summary> /// Updates the ports fields displayed in the editor /// </summary> internal void UpdatePortFields(MonoBehaviour gameComponent, bool overrideScript = false) { if (gameComponent == null) { return; } if (overrideScript) { // Update the script present in the node (although this might return null if it is a clone and gets destroyed?) SetScript(gameComponent); } // Gets all fields information from the game component (using System.Reflection) FieldInfo[] serializedFields = m_ScriptInternal.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); // Go through all the fields for (int i = 0; i < serializedFields.Length; i++) { var fieldToUse = serializedFields[i]; // Check if the field is marked with the "SendToIMLController" attribute SendToIMLController dataForIMLController = Attribute.GetCustomAttribute(fieldToUse, typeof(SendToIMLController)) as SendToIMLController; // We check now if the field is marked with the "PullFromIMLController" attribute PullFromIMLController dataFromIMLController = Attribute.GetCustomAttribute(fieldToUse, typeof(PullFromIMLController)) as PullFromIMLController; // Define flags to identify attribute behaviour bool isInputData = false, isOutputData = false; // Update flags if (dataForIMLController != null) { isInputData = true; } if (dataFromIMLController != null) { isOutputData = true; } // If the field is marked as either input or output... if (isInputData || isOutputData) { // Debug type of that value in console //Debug.Log(fieldToUse.Name + " Used in IMLComponent, With Type: " + fieldToUse.FieldType + ", With Value: " + fieldToUse.GetValue(gameComponent).ToString()); // Make sure that the dictionaries are initialised if (m_PortsPerFieldInfo == null) { m_PortsPerFieldInfo = new NodePortFieldInfoDictionary(); } // Check if the dictionary DOESN'T contain a fieldInfo for this reflected value, and then create nodes and dictionary values if (!m_PortsPerFieldInfo.ContainsValue(fieldToUse)) { // Secondly, we create a port (based on its type) for this fieldInfo and add it to the node NodePort newPort = null; // Add port to node if (isInputData) { newPort = AddDynamicOutput(fieldToUse.FieldType, fieldName: fieldToUse.Name); } else if (isOutputData) { newPort = AddDynamicInput(fieldToUse.FieldType, fieldName: fieldToUse.Name); } // Add that to the dictionary m_PortsPerFieldInfo.Add(newPort, fieldToUse); } // If the dictionary already contains a fieldInfo (and it is output), update it else if (isOutputData) { // Get the port linked to that field info var port = m_PortsPerFieldInfo.GetKey(fieldToUse); FieldInfo field; m_PortsPerFieldInfo.TryGetValue(port, out field); // Set value by reflection field.SetValue(m_ScriptInternal, port.GetInputValue()); } } } }
// Return the correct value of an output port when requested public override object GetValue(NodePort port) { arrayToOutput = Value; return(arrayToOutput); }
// Return the correct value of an output port when requested public override object GetValue(NodePort port) { FloatToOutput = Value; return(FloatToOutput); }
public void PlanRemoveTileInput(int id, NodePort np) { _toRemove[np] = id; }
public override object GetValue(NodePort port) { NodeVariables.Texture Texture = GetInputValue("Texture", this.Texture); return(Texture); }
public override object GetValue(NodePort port) { return(Execute()); }
public override void OnRemoveConnection(NodePort port) { Update(); }
// Return the correct value of an output port when requested public override object GetValue(NodePort port) { return(null); // Replace this }
public override object GetValue(NodePort port) { return(_outputFolders?.Distinct().ToArray()); }
/* * UpdateParentNode */ public void UpdateParentNode() { if (_parentNode != null) { NodePort[] oldInputs = new NodePort[_parentNode.InputsLength]; _parentNode.Inputs.CopyTo(oldInputs, 0); NodePort[] oldOutputs = null; if (_parentNode.Outputs != null) { oldOutputs = new NodePort[_parentNode.OutputsLength]; _parentNode.Outputs.CopyTo(oldOutputs, 0); } Int32 inputCount = 0; Int32 outputCount = 0; for (Int32 i = 0; i < _nodes.Count; i++) { NodeBase currentNode = _nodes[i]; if (currentNode is ProgramInput) { inputCount++; } else if (currentNode is ProgramOutput) { outputCount++; } } _parentNode.CreateInputs(inputCount + 1); if ((inputCount + 1) >= oldInputs.Length) { /* Set new inputs equal to old inputs. */ for (Int32 i = 0; i < oldInputs.Length; i++) { _parentNode.Inputs[i] = oldInputs[i]; } /* Add new inputs. */ for (Int32 i = oldInputs.Length; i < inputCount + 1; i++) { _parentNode.SetInput(i, "", 0.0); } } else { /* An input was removed. */ for (Int32 i = 0; i < inputCount + 1; i++) { _parentNode.Inputs[i] = oldInputs[i]; } } _parentNode.CreateOutputs(outputCount); if (oldOutputs != null) { if (outputCount >= oldOutputs.Length) { for (Int32 i = 0; i < oldOutputs.Length; i++) { _parentNode.Outputs[i] = oldOutputs[i]; } for (Int32 i = oldOutputs.Length; i < outputCount; i++) { _parentNode.SetOutput(i, "", 0.0); } } else { /* An output was removed. */ for (Int32 i = 0; i < outputCount; i++) { _parentNode.Outputs[i] = oldOutputs[i]; } } } else { /* All new outputs. */ for (Int32 i = 0; i < outputCount; i++) { _parentNode.SetOutput(i, "", 0.0); } } } }
public override object GetValue(NodePort port) { return(Previous); }