예제 #1
0
        public void LoadGraph(NoduxLinkGraph component)
        {
            NoduxGraphOperation.ClearGraph(_graphView);
            _graphView.SetSerializeTarget(component);

            var graphNodeMap = new Dictionary <string, NoduxGraphNodeView>();

            // create nodes
            for (var i = 0; i < component.GraphContainer.Nodes.Count; i++)
            {
                var graphNode =
                    NoduxGraphNodeViewCreator.Load(_graphView.SerializedGraph, component.GraphContainer.Nodes[i], i);
                _graphView.AddElement(graphNode);
                graphNodeMap[graphNode.Guid] = graphNode;
            }

            // connect nodes
            foreach (var link in component.GraphContainer.Links)
            {
                if (link.TargetNodeGuid == null || link.SourceNodeGuid == null)
                {
                    continue;
                }
                if (!graphNodeMap.ContainsKey(link.TargetNodeGuid) || !graphNodeMap.ContainsKey(link.SourceNodeGuid))
                {
                    Debug.LogWarning($"Link nodes failed {link.SourceNodeGuid} -> {link.TargetNodeGuid}");
                    continue;
                }

                var source = graphNodeMap[link.SourceNodeGuid];
                var target = graphNodeMap[link.TargetNodeGuid];
                NoduxGraphOperation.LinkNode(_graphView, source, target);
            }
        }
예제 #2
0
        public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
        {
            var worldMousePosition = _window.rootVisualElement.ChangeCoordinatesTo(
                _window.rootVisualElement,
                context.screenMousePosition - _window.position.position
                );
            var localMousePosition = _graphView.contentViewContainer.WorldToLocal(worldMousePosition);

            switch (searchTreeEntry.userData)
            {
            case Type type:
                var nodeData = (INode)JsonUtility.FromJson("{}", type);
                var node     = NoduxGraphNodeViewCreator.Create(_graphView.SerializedGraph, nodeData, Vector2.zero);
                node.SetPosition(new Rect(localMousePosition, new Vector2(320, 160)));
                _graphView.AddElement(node);
                return(true);

            default:
                return(false);
            }
        }