Пример #1
0
        private void LoadData(string path)
        {
            string json = File.ReadAllText(path);

            ReddotData[] reddotDatas = Newtonsoft.Json.JsonConvert.DeserializeObject <ReddotData[]>(json);

            Dictionary <string, ReddotNode> nodeDic = new Dictionary <string, ReddotNode>();

            foreach (var item in reddotDatas)
            {
                var node = new ReddotNode(item.key, item.name);
                nodeDic.Add(item.key, node);
                graphView.AddElement(node);

                var rect = node.GetPosition();
                rect.x = item.position.x;
                rect.y = item.position.y;
                node.SetPosition(rect);
            }

            foreach (var item in reddotDatas)
            {
                if (item.children != null)
                {
                    foreach (var child in item.children)
                    {
                        var edge = nodeDic[item.key].AddChild(nodeDic[child]);
                        graphView.Add(edge);
                    }
                }
            }
        }
Пример #2
0
        public ReddotGraphView(EditorWindow editorWindow)
        {
            ReddotPort.graphView = this;
            m_editorWindow       = editorWindow;
            var nodeStyle = AssetDatabase.LoadAssetAtPath <StyleSheet>(@"Assets\XFramework\Extend\Core\Modules\UI\Reddot\Editor\NarrativeGraph.uss");

            styleSheets.Add(nodeStyle);

            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);

            var grid = new GridBackground();

            Insert(0, grid);
            grid.StretchToParentSize();

            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new RectangleSelector());
            this.AddManipulator(new FreehandSelector());

            nodeCreationRequest += context =>
            {
                var node = new ReddotNode();
                AddNode(node, context.screenMousePosition);
            };
        }
Пример #3
0
        public void AddNode(ReddotNode node, Vector2 screenMousePosition)
        {
            var mousePosition = m_editorWindow.rootVisualElement.ChangeCoordinatesTo(m_editorWindow.rootVisualElement.parent,
                                                                                     screenMousePosition - m_editorWindow.position.position);
            var graphMousePosition = this.contentViewContainer.WorldToLocal(mousePosition);

            this.AddElement(node);
            node.transform.position = graphMousePosition;
        }
Пример #4
0
            public void OnDropOutsidePort(Edge edge, Vector2 position)
            {
                var screenPos = GUIUtility.GUIToScreenPoint(UnityEngine.Event.current.mousePosition);

                // 添加一个新节点并连接
                var node = new ReddotNode();

                graphView.AddNode(node, screenPos);

                if (edge.input is null)
                {
                    edge = (edge.output.node as ReddotNode).AddChild(node);
                }
                else
                {
                    edge = node.AddChild(edge.input.node as ReddotNode);
                }

                graphView.Add(edge);
            }
Пример #5
0
 /// <summary>
 /// 添加一个子节点
 /// </summary>
 /// <param name="childNode">子节点</param>
 /// <returns></returns>
 public Edge AddChild(ReddotNode childNode)
 {
     return(outputPort.ConnectTo(childNode.inputPort));
 }