예제 #1
0
        public NodeInspector(NodeGraphView nodeGraphView)
        {
            var xmlAsset = Resources.Load <VisualTreeAsset>(ResourceAssetPaths.NodeInspector_UXML);

            xmlAsset.CloneTree(this);

            // This can probably be broken out into its own uxml
            m_nodeGraphView = nodeGraphView;

            m_nodeNameLabel = this.Q <Label>(NODE_NAME_LABEL);
            m_nodeIdLabel   = this.Q <Label>(NODE_ID_LABEL);

            m_nodeCommentField = this.Q <TextField>(COMMENT_FIELD);
            VisualElement textInput = m_nodeCommentField.Q <VisualElement>("unity-text-input");

            textInput.style.unityTextAlign = TextAnchor.UpperLeft;
            textInput.style.overflow       = Overflow.Visible;
            textInput.style.whiteSpace     = WhiteSpace.Normal;
            m_nodeCommentField.isDelayed   = true;

            m_nodeCommentField.RegisterCallback <ChangeEvent <string> >((str) => { OnCommentBoxFocusOut(); });
            m_nodeCommentField.RegisterCallback <FocusInEvent>((target) => { OnCommentBoxFocusIn(); });

            m_commentPlaceholder = this.Q <Label>(COMMENT_PLACEHOLDER);
            OnCommentBoxFocusOut();

            m_inspectorArea = this.Q <VisualElement>(INSPECTOR_AREA);

            m_imguiContainer = new IMGUIContainer();
            m_imguiContainer.onGUIHandler += OnIMGUIDraw;
            m_imguiContainer.style.display = DisplayStyle.None;
            m_inspectorArea.Add(m_imguiContainer);

            m_propertyField = new PropertyField();
            m_propertyField.style.display = DisplayStyle.None;
            m_inspectorArea.Add(m_propertyField);

            Undo.undoRedoPerformed += () =>
            {
                if (m_selectedNode != null)
                {
                    m_selectedNodeProperty.serializedObject.Update();
                    SetNode(m_selectedNode, m_selectedNodeProperty);
                }
            };
        }
        public GraphInspector(NodeGraphView nodeGraphView)
        {
            var uxmlAsset = Resources.Load <VisualTreeAsset>(ResourceAssetPaths.GraphInspector_UXML);

            uxmlAsset.CloneTree(this);

            m_graphNameLabel   = this.Q <Label>(GRAPH_NAME_LABEL);
            m_graphObjectField = this.Q <ObjectDisplayField>(GRAPH_OBJECT_FIELD);

            m_graphPropertiesArea          = this.Q <VisualElement>(GRAPH_PROPERTIES_AREA);
            m_propertyField                = new PropertyField();
            m_imguiContainer               = new IMGUIContainer();
            m_imguiContainer.onGUIHandler += OnIMGUIDraw;

            m_blackboardArea = this.Q <VisualElement>(BLACKBOARD_AREA);
            m_blackboardView = new BlackboardView(nodeGraphView);
            m_blackboardArea.Add(m_blackboardView);
        }
        public BlackboardView(NodeGraphView nodeGraphView)
        {
            windowed                = true;
            graphView               = nodeGraphView;
            addItemRequested       += OnAddClicked;
            editTextRequested      += EditBlackboardFieldName;
            Undo.undoRedoPerformed += () =>
            {
                if (m_serializedBlackboardElements != null)
                {
                    m_serializedBlackboardElements.serializedObject.Update();
                }

                ClearElements();
                LoadElements();
            };

            List <Type> blackboardElementImps = new List <Type>();

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int i = 0; i < assemblies.Length; i++)
            {
                blackboardElementImps.AddRange(assemblies[i].GetTypes().Where(x
                                                                              => typeof(BlackboardElement).IsAssignableFrom(x) &&
                                                                              x != typeof(BlackboardElement) &&
                                                                              x != typeof(ABlackboardElement <>) &&
                                                                              !x.IsAbstract));
            }

            for (int i = 0; i < blackboardElementImps.Count; i++)
            {
                //TODO: sort the element types!!!

                Type elementType = blackboardElementImps[i].BaseType.GetGenericArguments()[0];
                if (!m_blackboardElementLookup.ContainsKey(elementType))
                {
                    m_blackboardElementLookup.Add(elementType, blackboardElementImps[i]);
                }
            }
        }
예제 #4
0
 public InspectorTabElement(NodeGraphView nodeGraphView)
 {
     Add(GraphInspector = new GraphInspector(nodeGraphView));
     Add(NodeInspector  = new NodeInspector(nodeGraphView));
     NodeInspector.SetVisible(false);
 }
        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); });
        }
 public EdgeConnectorListener(NodeGraphView graphView)
 {
     m_graphView = graphView;
 }
예제 #7
0
 public void Setup(NodeGraphView nodeGraphView, GraphTypeMetadata graphTypeMetadata)
 {
     m_nodeGraphView     = nodeGraphView;
     m_graphTypeMetadata = graphTypeMetadata;
 }
예제 #8
0
        /// <summary>
        /// When the UI is enabled, it sets up all the VisualElement references and loads in the window data.
        /// </summary>
        private void OnEnable()
        {
            //==================================Load Initial Data======================================//
            var uxmlAsset = Resources.Load <VisualTreeAsset>(ResourceAssetPaths.LogicalGraphWindow_UXML);

            uxmlAsset.CloneTree(rootVisualElement);
            m_mainSplitView     = rootVisualElement.Q <UIElements.TwoPaneSplitView>(MAIN_SPLITVIEW);
            m_graphTypeMetadata = new GraphTypeMetadata();
            //=========================================================================================//=

            //==================================Register Toolbar=======================================//
            m_toolbar = rootVisualElement.Q <Toolbar>(TOOLBAR);

            // Save Button
            m_saveGraphButton = new ToolbarButton(() =>
            {
                if (m_openedGraphInstance != null)
                {
                    EditorUtility.SetDirty(m_openedGraphInstance);
                    AssetDatabase.SaveAssets();
                }
            });
            m_saveGraphButton.text = "Save";
            m_toolbar.Add(m_saveGraphButton);
            //=========================================================================================//

            //====================================Register Panels======================================//
            // Left panel is dependent on the right (NodeGraphView) so ordering is important!
            VisualElement mainPanelRight = rootVisualElement.Q <VisualElement>(MAIN_PANEL_RIGHT);
            VisualElement mainPanelLeft  = rootVisualElement.Q <VisualElement>(MAIN_PANEL_LEFT);

            // Populate right panel
            m_nodeGraphView = new NodeGraphView(m_graphTypeMetadata);
            m_nodeGraphView.StretchToParentSize();
            m_nodeGraphView.OnAddToSelection      += OnGraphElementSelectionAdded;
            m_nodeGraphView.OnRemoveFromSelection += OnGraphElementSelectionRemoved;
            m_nodeGraphView.OnClearSelection      += OnGraphElementSelectionCleared;
            mainPanelRight.Add(m_nodeGraphView);

            m_customMenuController = new CustomMenuController(mainPanelRight, m_nodeGraphView);

            // Populate left panel
            List <(string, TabContentElement)> tabs = new List <(string, TabContentElement)>();

            tabs.Add(("Library", m_libraryTab = new LibraryTabElement((string guid) => { OpenGraph(guid); }, m_customMenuController, m_graphTypeMetadata)));
            tabs.Add(("Inspector", m_inspectorTab = new InspectorTabElement(m_nodeGraphView)));
            m_nodeGraphView.OnRemoveNode += (node) => { m_inspectorTab.SetNode(null, null); };
            m_mainTabGroup = new TabGroupElement(tabs);
            m_mainTabGroup.StretchToParentSize();
            m_nodeGraphView.OnMouseClick += () => { m_mainTabGroup.SelectTab(m_inspectorTab); };
            mainPanelLeft.Add(m_mainTabGroup);

            // Other setup
            m_inspectorTab.GraphInspector.OnBlackboardElementChanged += (undoGroup) => { m_nodeGraphView.CallAllNodeViewDrawerBlackboardElementChanged(undoGroup); };
            //=========================================================================================//

            //==================================Callback Listeners=====================================//
            GraphModificationProcessor.OnGraphCreated    += OnNewGraphCreated;
            GraphModificationProcessor.OnGraphWillDelete += OnGraphWillDelete;
            //=========================================================================================//

            // Deserialize the editor window data.
            DeserializeData();
        }