public void Initialize(AbstractNode node, SerializedProperty serializedNode, EdgeConnectorListener connectorListener) { viewDataKey = node.id.ToString(); target = node; m_SerializedNode = serializedNode; m_ConnectorListener = connectorListener; styleSheets.Add(Resources.Load <StyleSheet>("Styles/NodeView")); AddToClassList("nodeView"); SetPosition(new Rect(node.graphPosition, Vector2.one)); title = node.name; // Custom OnDestroy() handler via https://forum.unity.com/threads/request-for-visualelement-ondestroy-or-onremoved-event.718814/ RegisterCallback <DetachFromPanelEvent>((e) => OnDestroy()); RegisterCallback <TooltipEvent>(OnTooltip); UpdatePorts(); OnInitialize(); // TODO: Don't do it this way. Move to an OnInitialize somewhere else. if (node is FuncNode func) { func.Awake(); } }
internal void Initialize(Node node, CanvasView canvas, EdgeConnectorListener connectorListener) { viewDataKey = node.ID; Target = node; Canvas = canvas; ReflectionData = NodeReflection.GetNodeType(node.GetType()); ConnectorListener = connectorListener; styleSheets.Add(Resources.Load <StyleSheet>("BlueGraphEditor/NodeView")); AddToClassList("nodeView"); // Add a class name matching the node's name (e.g. `.node-My-Branch`) var ussSafeName = Regex.Replace(Target.Name, @"[^a-zA-Z0-9]+", "-").Trim('-'); AddToClassList($"node-{ussSafeName}"); var errorContainer = new VisualElement { name = "error" }; errorContainer.Add(new VisualElement { name = "error-icon" }); errorMessage = new Label { name = "error-label" }; errorContainer.Add(errorMessage); Insert(0, errorContainer); SetPosition(new Rect(node.Position, Vector2.one)); title = node.Name; if (!ReflectionData.Deletable) { capabilities &= ~Capabilities.Deletable; } if (!ReflectionData.Moveable) { capabilities &= ~Capabilities.Movable; } // Custom OnDestroy() handler via https://forum.unity.com/threads/request-for-visualelement-ondestroy-or-onremoved-event.718814/ RegisterCallback <DetachFromPanelEvent>((e) => Destroy()); RegisterCallback <TooltipEvent>(OnTooltip); node.OnErrorEvent += RefreshErrorState; node.OnValidateEvent += OnValidate; ReloadPorts(); ReloadEditables(); RefreshErrorState(); OnInitialize(); }
public PortListView(AbstractNode parent_node, Type list_type, string list_name, SerializedProperty serializedNode, EdgeConnectorListener connectorListener, Action onPropertyChange, Action updateBinding) { m_ConnectorListener = connectorListener; m_SerializedList = serializedNode.FindPropertyRelative(list_name); m_OnPropertyChange = onPropertyChange; m_UpdateBinding = updateBinding; items = new List <PortView>(); list_container = new VisualElement(); this.list_name = list_name; this.list_type = list_type; this.parent_node = parent_node; add_button = new Button(() => { var size = m_SerializedList.arraySize; // Add an output port for this array element m_UpdateBinding(); this.parent_node.AddPort(new Port { name = $"{list_name}[{size}]", isInput = false, acceptsMultipleConnections = false, type = list_type, fieldName = $"{m_SerializedList.propertyPath}.Array.data[{size}]" }); m_SerializedList.serializedObject.Update(); m_UpdateBinding(); m_SerializedList.InsertArrayElementAtIndex(size); m_SerializedList.serializedObject.ApplyModifiedProperties(); m_UpdateBinding(); m_OnPropertyChange(); }); add_button.text = list_name; add_button.style.color = new StyleColor(Color.white); add_button.style.backgroundColor = new StyleColor(Color.green); this.hierarchy.Add(add_button); this.hierarchy.Add(list_container); var property = m_SerializedList.Copy(); var endProperty = property.GetEndProperty(); //We prefill the container since we know we will need this property.NextVisible(true); // Expand the first child. do { if (SerializedProperty.EqualContents(property, endProperty)) { break; } if (property.propertyType == SerializedPropertyType.ArraySize) { item_size = property.intValue; bindingPath = property.propertyPath; break; } }while (property.NextVisible(false)); // Never expand children. UpdateCreatedItems(); this.Bind(m_SerializedList.serializedObject); }
public CanvasView(GraphEditorWindow window) { EditorWindow = window; name = "bluegraph-canvas"; styleSheets.Add(Resources.Load <StyleSheet>("BlueGraphEditor/Variables")); styleSheets.Add(Resources.Load <StyleSheet>("BlueGraphEditor/CanvasView")); AddToClassList("canvasView"); edgeConnectorListener = new EdgeConnectorListener(this); searchWindow = ScriptableObject.CreateInstance <SearchWindow>(); searchWindow.Target = this; SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); this.AddManipulator(new ContentDragger()); this.AddManipulator(new SelectionDragger()); this.AddManipulator(new RectangleSelector()); this.AddManipulator(new ClickSelector()); // Add event handlers for shortcuts and changes RegisterCallback <KeyUpEvent>(OnGraphKeyUp); RegisterCallback <MouseMoveEvent>(OnGraphMouseMove); graphViewChanged = OnGraphViewChanged; RegisterCallback <AttachToPanelEvent>(c => { Undo.undoRedoPerformed += OnUndoRedo; }); RegisterCallback <DetachFromPanelEvent>(c => { Undo.undoRedoPerformed -= OnUndoRedo; }); nodeCreationRequest = (ctx) => OpenSearch(ctx.screenMousePosition); // Add handlers for (de)serialization serializeGraphElements = OnSerializeGraphElements; canPasteSerializedData = OnTryPasteSerializedData; unserializeAndPaste = OnUnserializeAndPaste; RegisterCallback <GeometryChangedEvent>(OnFirstResize); title = new Label("BLUEGRAPH"); title.AddToClassList("canvasViewTitle"); Add(title); // Add a grid renderer *behind* content containers Insert(0, new GridBackground()); }