public static ANode CreateNode(Type nodeType, AiBehaviour blackboard) { ANode n = ScriptableObject.CreateInstance(nodeType) as ANode; n.name = n.GetType().Name; n.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(n, blackboard); EditorUtility.SetDirty(n); AssetDatabase.SaveAssets(); return(n); }
public void SetNode(ANode node, SerializedProperty serializedNode) { UnselectNode(); if (node == null || serializedNode == null) { return; } m_selectedNode = node; m_selectedNodeProperty = serializedNode; m_nodeNameLabel.text = AddSpacesToSentence(node.GetType().Name); m_nodeIdLabel.text = node.Id; m_nodeCommentField.bindingPath = serializedNode.FindPropertyRelative("m_comment").propertyPath; m_nodeCommentField.Bind(serializedNode.serializedObject); m_commentPlaceholder.style.display = (string.IsNullOrEmpty(serializedNode.FindPropertyRelative("m_comment").stringValue)) ? DisplayStyle.Flex : DisplayStyle.None; if (node.UseIMGUIPropertyDrawer) { m_imguiContainer.style.display = DisplayStyle.Flex; } else { if (m_propertyField != null) { m_inspectorArea.Remove(m_propertyField); } m_propertyField = new PropertyField(m_selectedNodeProperty); m_propertyField.Bind(m_selectedNodeProperty.serializedObject); m_propertyField.style.display = DisplayStyle.Flex; // This requires Unity 2020.2 to work correctly https://forum.unity.com/threads/uielements-developer-guide.648043/#post-6073137 m_propertyField.RegisterCallback <SerializedPropertyChangeEvent>(x => { m_nodeGraphView.GetNodeViewById(node.Id)?.HandleOnSerializedPropertyChanged(); }); m_inspectorArea.Add(m_propertyField); } }
private void DrawNodeWindow(int id) { Event e = Event.current; if (_node == null) { return; } GUI.Label(new Rect(0, gSize.y / 2f - 12, _rect.width, 24), new GUIContent(_node.GetType().Name, EditorGUIUtility.ObjectContent(_node, _node.GetType()).image)); GUI.Label(new Rect(gSize.x - 14f, -1f, 16f, 16f), new GUIContent((Texture2D)EditorGUIUtility.Load(_currentIcon))); if (e.type == EventType.MouseUp && e.button == 1) { OnRightClicked(_node); e.Use(); } if (e.type == EventType.MouseDown && e.button == 0) { OnLeftClicked(_node); } EditorUtility.SetDirty(_node); GUI.DragWindow(); }
public ClipboardElement(ANode node) { ElementType = node.GetType().AssemblyQualifiedName; Data = JsonUtility.ToJson(node); }
private NodeView CreateNodeView(ANode node, SerializedProperty serializedNode = null) { if (serializedNode == null) { int index = NodeGraph.NodeCollection.GetNodeIndex(node); if (index == -1) { Debug.Log("wtf "); } serializedNode = m_nodeListProp.GetArrayElementAtIndex(index); } NodeView nodeView = new NodeView(node, serializedNode, this, m_edgeConectorListener, Activator.CreateInstance(GraphTypeMetadata.GetNodeViewDrawerType(node.GetType())) as NodeViewDrawer); AddElement(nodeView); m_nodeViews.Add(node.Id, nodeView); return(nodeView); }
public NodeView(ANode node, SerializedProperty serializedNode, NodeGraphView nodeGraphView, IEdgeConnectorListener edgeConnectorListener, NodeViewDrawer nodeViewDrawer) : base() { if (serializedNode == null) { return; } Node = node; NodeType = Node.GetType(); SerializedNode = serializedNode; m_nodeGraphView = nodeGraphView; m_edgeConnectorListener = edgeConnectorListener; NodeId = SerializedNode.FindPropertyRelative(ANode.IdVarname).stringValue; m_nodeViewDrawer = nodeViewDrawer; m_nodeDisplayContainers = new NodeDisplayContainers(this, m_nodeViewDrawer); m_nodeViewDrawer.SetNodeView(this, SerializedNode, nodeGraphView.NodeGraph, m_nodeDisplayContainers); m_nodeViewDrawer.OnSetup(); title = m_nodeViewDrawer.DisplayName; bool isEntryNode = (typeof(BuiltInNodes.EntryNode)).IsAssignableFrom(NodeType); if (isEntryNode) { this.capabilities = this.capabilities & (~Capabilities.Deletable); } if (!isEntryNode) { //Add ports m_inport = new PortView(this, Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(bool), 0, m_nodeViewDrawer.NodeColor, m_edgeConnectorListener); m_inport.portName = ""; m_nodeDisplayContainers.SetInport(m_inport); } CreateOutports(); // Draw node m_nodeViewDrawer.Repaint(m_outports); RefreshExpandedState(); RefreshPorts(); Vector2 pos = SerializedNode.FindPropertyRelative(ANode.PositionVarName).vector2Value; SetPosition(new Rect(pos, Vector2.zero)); //this.RegisterCallback<GeometryChangedEvent>((GeometryChangedEvent gce) => { Debug.Log(gce.newRect.position); }); }