GraphElement CreateElement(IGraphElementModel model)
        {
            GraphElement element = GraphElementFactory.CreateUI(m_GraphView, m_Store, model);

            if (element != null)
            {
                AddToGraphView(element);
            }

            return(element);
        }
        void RebuildAll(State state)
        {
            state.lastActionUIRebuildType = State.UIRebuildType.Full;
            Clear();

            var graphModel = state.CurrentGraphModel;

            if (graphModel == null)
            {
                return;
            }

            foreach (var nodeModel in graphModel.NodeModels)
            {
                var node = GraphElementFactory.CreateUI(m_GraphView, m_Store, nodeModel);
                if (node != null)
                {
                    AddToGraphView(node);
                }
            }

            foreach (var stickyNoteModel in ((VSGraphModel)state.CurrentGraphModel).StickyNoteModels)
            {
                var stickyNote = GraphElementFactory.CreateUI(m_GraphView, m_Store, stickyNoteModel);
                if (stickyNote != null)
                {
                    AddToGraphView(stickyNote);
                }
            }

            var ports    = m_GraphView.ports.ToList();
            var allPorts = ports.ToDictionary(p => p.userData as PortModel);

            m_GraphView.PositionDependenciesManagers.portModelToPort = allPorts;
            int index = 0;

            foreach (IEdgeModel edge in ((VSGraphModel)state.CurrentGraphModel).EdgeModels)
            {
                if (!RestoreEdge(edge, allPorts))
                {
                    Debug.LogWarning($"Edge {index} cannot be restored: {edge}");
                }
                index++;
            }

            MapModelsToNodes();

            Blackboard?.Rebuild(Blackboard.RebuildMode.BlackboardOnly);

            m_GraphView.contentViewContainer.Add(m_IconsParent);
            m_GraphView.HighlightGraphElements();
        }
Ejemplo n.º 3
0
 static void PopulateStack(GraphView graphView, Store store, IStackModel stackModel, StackNode stack)
 {
     foreach (var nodeModel in stackModel.NodeModels)
     {
         var node = GraphElementFactory.CreateUI(graphView, store, nodeModel);
         if (node != null)
         {
             stack.AddElement(node);
             ((VseGraphView)graphView).AddPositionDependency(
                 stack.stackModel,
                 (INodeModel)((IHasGraphElementModel)node).GraphElementModel);
             node.style.position = Position.Relative;
         }
     }
 }