/// <summary> Make a field for a serialized property. Manual node port override. </summary> public static void DrawNodePropertyField( this INode node, SerializedProperty property, GUIContent label, INodePort port, bool includeChildren = true, params GUILayoutOption[] options) { if (property == null) { return; } label = label ?? new GUIContent(property.name); // If property is not a port, display a regular property field if (port == null) { EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } else { DrawFieldPort(property, label, node, port, includeChildren, options); } }
private void BindConnections(IUniNode node, INodePort sourcePort, IContext publisher) { //data source connections allowed only for input ports if (sourcePort.Direction != PortIO.Input) { return; } var connections = sourcePort.Connections; for (var i = 0; i < connections.Count; i++) { var connection = connections[i]; var port = connection.Port; if (port == null || port.Direction == PortIO.Input || port.NodeId == Id) { continue; } var disposable = port.Broadcast(publisher). AddTo(LifeTime); LifeTime.AddDispose(disposable); } }
/// <summary> Show right-click context menu for hovered port </summary> void ShowPortContextMenu(INodePort hoveredPort) { var contextMenu = new GenericMenu(); contextMenu.AddItem(new GUIContent("Clear Connections"), false, hoveredPort.ClearConnections); contextMenu.AddItem(new GUIContent("Show Content"), false, () => ShowPortContextValues(hoveredPort.Value)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); }
public PortViewerEditor Initialize(INodePort port) { _port = port; portName = port.ItemName; UpdateValues(_port.Value as PortValue); return(this); }
public static Color GetMainPortColor(INodePort port) { if (port == null) { return(Color.magenta); } return(GameFlowPreferences.GetTypeColor(port.ValueType)); }
public static void DrawPortPairField( this INode node, INodePort input, INodePort output, NodeGuiLayoutStyle intputStyle, NodeGuiLayoutStyle outputStyle) { NodeEditorGUILayout.PortPair(input, output, intputStyle, outputStyle); }
private void ConnectToGraphPort(INodePort sourcePort, INodePort targetPort, PortIO direction) { var source = direction == PortIO.Input ? sourcePort : targetPort; var target = direction == PortIO.Input ? targetPort : sourcePort; source.Value. Broadcast(target.Value). AddTo(LifeTime); }
protected void PublishToken(INodePort port) { if (!_isStateActive || _token == null) { GameLog.LogWarning($"{ItemName} Try to Publish Token in inactive state"); return; } port.Value.Publish(_token); }
public bool IsAlreadyConnectedPort(INodePort from, INodePort to) { var result = from.IsConnectedTo(to); if (result) { Debug.LogError($"PORT {from.PortId} ALREADY CONNECTED TO {to.PortId}"); } return(!result); }
public static void PortPair(INodePort input, INodePort output, NodeGuiLayoutStyle intputStyle, NodeGuiLayoutStyle outputStyle) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); PortField(input, intputStyle); PortField(output, outputStyle); GUILayout.EndHorizontal(); }
public bool UpdatePortValue(INode node, INodePort port, object fieldValue) { if (fieldValue is IReactiveSource reactiveSource) { reactiveSource.Bind(node, port.ItemName); return(true); } return(false); }
public static void PortField(Vector2 position, INodePort port, Color color) { if (port == null) { return; } var backgroundColor = GetBackgroundPortColor(port); PortField(position, port, color, backgroundColor); }
/// <summary> Make a simple port field. </summary> public static void PortField(Vector2 position, INodePort port) { if (port == null) { return; } var col = GetMainPortColor(port); PortField(position, port, col); }
public void Visit(INodePort port) { var fullString = port.GetType().Name + " " + port.NodeIdentifier + " receives "; foreach (var previousPort in port.PreviousPorts) { fullString += previousPort.Output + " from " + previousPort.NodeIdentifier + ", "; } fullString += "so output is: " + port.Output; Console.WriteLine(fullString); }
public bool UpdatePortValue(INode node, INodePort port, object fieldValue) { foreach (var portHandler in PortHandlers) { if (portHandler.UpdatePortValue(node, port, fieldValue)) { return(true); } } return(false); }
public bool IsSavePort(INodePort from, INodePort to) { var result = to != from; if (result) { return(true); } ReportError(from, to, "SAME PORT ERROR"); return(false); }
public bool IsSameDirection(INodePort from, INodePort to) { var result = from.Direction != to.Direction; if (result) { return(true); } ReportError(from, to, $"SAME PORT DIRECTIONS {from.Direction}"); return(false); }
/// <summary> /// Returns the port that this <see cref="PortConnection"/> points to /// </summary> public INodePort GetPort() { //if (port != null) return port; var targetNode = _data?.GetNode(nodeId); if (targetNode == null) { return(null); } _port = targetNode.GetPort(fieldName); return(_port); }
public bool TypeValidation(INodePort from, INodePort to) { var result = from.ValueTypes.Count == 0 || to.ValueTypes.Count == 0 || from.ValueTypes.Any(to.Value.IsValidPortValueType); if (result) { return(true); } ReportError(from, to, $"CAN'T CONNECT BY TYPE VALIDATION"); return(false); }
public bool DrawPortPair(INode node, INodePort inputPort, INodePort outputPort) { if (outputPort == null || inputPort == null) { return(false); } var inputStyle = styleSelector.Select(inputPort); var outputStyle = styleSelector.Select(outputPort); node.DrawPortPairField(inputPort, outputPort, inputStyle, outputStyle); return(true); }
private static void DrawFieldPort( SerializedProperty property, GUIContent label, INode node, INodePort port, bool includeChildren = true, params GUILayoutOption[] options) { var rect = new Rect(); var data = node.GetPortData(node.GetType(), property.name); var portData = data.PortData; if (portData.InstancePortList) { InstancePortList(property.name, port.ValueType, property.serializedObject, portData.Direction, portData.ConnectionType); return; } ShowBackingValueField(data, property, port.IsConnected, includeChildren, null, GUILayout.MinWidth(30)); rect = GUILayoutUtility.GetLastRect(); rect.position = port.Direction == PortIO.Input ? rect.position - new Vector2(16, 0) : rect.position + new Vector2(rect.width, 0); rect.size = new Vector2(16, 16); Color backgroundColor = new Color32(90, 97, 105, 255); if (NodeEditorWindow.nodeTint.TryGetValue(port.Node.GetType(), out var tint)) { backgroundColor *= tint; } Profiler.BeginSample("DrawPortHandle"); var col = GameFlowPreferences.GetTypeColor(port.ValueType); DrawPortHandle(rect, backgroundColor, col); Profiler.EndSample(); // Register the handle position var portPos = rect.center; //TODO REMOTE NodeEditor.PortPositions[port] = portPos; portData.Despawn(); }
public static TValue GetConnectedNode <TValue>(this INodePort port) where TValue : Node { if (port == null || !port.IsConnected) { return(null); } if (!(port.Node is TValue item)) { return(null); } return(item); }
public static Color GetBackgroundPortColor(INodePort port) { Color backgroundColor = new Color32(90, 97, 105, 255); if (port == null) { return(backgroundColor); } if (NodeEditorWindow.nodeTint.TryGetValue(port.Node.GetType(), out var tint)) { backgroundColor *= tint; } return(backgroundColor); }
public static NodeGuiLayoutStyle GetDefaultPortStyle(INodePort port) { var name = port == null ? string.Empty : port.ItemName; var label = port == null ? new GUIContent(string.Empty) : new GUIContent(port.ItemName); var style = new NodeGuiLayoutStyle() { Color = GetMainPortColor(port), Background = GetBackgroundPortColor(port), Options = new GUILayoutOption[] { GUILayout.MinWidth(30) }, Label = label, Name = name, }; return(style); }
public static void PortField(Vector2 position, INodePort port, Color color, Color backgroundColor) { if (port == null) { return; } var rect = new Rect(position, new Vector2(16, 16)); DrawPortHandle(rect, backgroundColor, color); // Register the handle position var portPos = rect.center; NodeEditor.PortPositions[port] = portPos; }
public bool IsNullPort(INodePort from, INodePort to) { if (from != null && to != null) { return(true); } if (from == null) { ReportError(from, to, "FROM port is NULL"); } if (to == null) { ReportError(from, to, "TO port is NULL"); } return(false); }
/// <summary> Make a simple port field. </summary> public static void PortField(GUIContent label, INodePort port, params GUILayoutOption[] layoutOptions) { if (port == null) { return; } var defaultStyle = GetDefaultPortStyle(port); defaultStyle.Label = label; if (layoutOptions != null) { defaultStyle.Options = layoutOptions; } PortField(port, defaultStyle); }
public virtual NodeGuiLayoutStyle Select(INodePort port) { var portStyle = NodeEditorGUILayout.GetDefaultPortStyle(port); if (!(port.Node is INode uniNode)) { return(portStyle); } var portValue = port.Value; var hasData = portValue != null && portValue.HasValue; portStyle.Name = port.ItemName; portStyle.Background = port.Direction == PortIO.Input ? hasData ? new Color(128, 128, 0) : Color.green : hasData ? new Color(128, 128, 0) : Color.blue; portStyle.Color = GameFlowPreferences.GetTypeColor(port.ValueType); return(portStyle); }
public PortData GetPortData(INodePort port) { if (this.portData.TryGetValue(port, out var data)) { return(data); } var targetType = port.ValueType; targetType = targetType == null ? typeof(object) : targetType; data = new PortData() { acceptMultipleEdges = port.ConnectionType == ConnectionType.Multiple, displayName = port.ItemName, displayType = targetType, identifier = port.ItemName, }; this.portData[port] = data; return(data); }
public static void PortField(INodePort port, NodeGuiLayoutStyle portStyle) { if (port == null) { return; } if (portStyle.Options == null) { portStyle.Options = new GUILayoutOption[] { GUILayout.MinWidth(30) } } ; Vector2 position = Vector3.zero; portStyle.Label = portStyle.Label != null ? portStyle.Label : string.IsNullOrEmpty(portStyle.Name) ? new GUIContent(ObjectNames.NicifyVariableName(port.ItemName)) : new GUIContent(portStyle.Name); // If property is an input, display a regular property field and put a port handle on the left side if (port.Direction == PortIO.Input) { // Display a label EditorGUILayout.LabelField(portStyle.Label, portStyle.Options); var rect = GUILayoutUtility.GetLastRect(); position = rect.position - new Vector2(16, 0); } // If property is an output, display a text label and put a port handle on the right side else if (port.Direction == PortIO.Output) { // Display a label EditorGUILayout.LabelField(portStyle.Label, NodeEditorResources.OutputPort, portStyle.Options); var rect = GUILayoutUtility.GetLastRect(); position = rect.position + new Vector2(rect.width, 0); } PortField(position, port, portStyle.Color, portStyle.Background); }