コード例 #1
0
ファイル: ConnectPoint.cs プロジェクト: xdedzl/StoryKit
        public static void ClearLine()
        {
            if (StartPoint != null)
            {
                StartPoint.RemoveAt(StartPoint.childCount - 1);
            }

            StartPoint = null;
        }
コード例 #2
0
        private void ProcessEvents(UnityEngine.Event e)
        {
            drag = Vector2.zero;

            switch (e.type)
            {
            case EventType.MouseDown:
                if (e.button == 0)
                {
                    activeDrag = true;

                    if (ConnectPoint <T> .StartPoint != null)
                    {
                        ShowCreateNodeMenu(e.mousePosition, "", (node) =>
                        {
                            if (ConnectPoint <T> .StartPoint.point == Point.In)
                            {
                                node.AddNextNode(ConnectPoint <T> .StartPoint.node);
                            }
                            else
                            {
                                ConnectPoint <T> .StartPoint.node.AddNextNode(node);
                            }

                            ConnectPoint <T> .ClearLine();
                        });
                    }
                }

                if (e.button == 1)
                {
                    ConnectPoint <T> .ClearLine();

                    ShowCreateNodeMenu(e.mousePosition, "Add Node");
                }

                if (e.button == 2)
                {
                    ConnectPoint <T> .ClearLine();
                }
                break;

            case EventType.MouseUp:
                if (e.button == 0)
                {
                    activeDrag = false;
                }
                break;

            case EventType.MouseDrag:
                if (e.button == 0 && activeDrag)
                {
                    OnCanvasDrag(e.delta);
                }
                break;
            }
        }
コード例 #3
0
ファイル: ConnectPoint.cs プロジェクト: xdedzl/StoryKit
        public ConnectPoint(Node <T> node, Point point)
        {
            this.node  = node;
            this.point = point;

            RegisterCallback <MouseDownEvent>((e) =>
            {
                if (StartPoint != null)  // 被连接点
                {
                    if (StartPoint.node != this.node && StartPoint.point != this.point)
                    {
                        if (this.point == Point.In)
                        {
                            StartPoint.node.AddNextNode(this.node);
                        }
                        else
                        {
                            this.node.AddNextNode(StartPoint.node);
                        }
                    }
                    ClearLine();
                }
                else  // 连接点
                {
                    StartPoint   = this;
                    var drawLine = new IMGUIContainer(() =>
                    {
                        Vector2 p1 = this.transform.position;
                        Vector2 p2 = UnityEngine.Event.current.mousePosition;
                        Handles.DrawBezier(
                            p1,
                            p2,
                            p1 + Vector2.left * 50f,
                            p2 - Vector2.left * 50f,
                            Color.white,
                            null,
                            2f
                            );

                        GUI.changed = true;
                    })
                    {
                        transform =
                        {
                            position = new Vector2(5, 5),
                        }
                    };
                    Add(drawLine);
                }
            });
        }
コード例 #4
0
ファイル: Node.cs プロジェクト: xdedzl/StoryKit
        private Node()
        {
            m_NextNodes = new List <Node <T> >();
            m_PrevNodes = new List <Node <T> >();
            this.RegisterCallback <PointerDownEvent>((a) =>
            {
                this.BringToFront();
            }, TrickleDown.NoTrickleDown);

            #region 节点顶部

            #region 连接点

            connectPointIn = new ConnectPoint <T>(this, Point.In);
            connectPointIn.AddToClassList("connectPoint");
            connectPointIn.RegisterCallback <PointerDownEvent>((a) => { a.StopPropagation(); });
            connectPointOut = new ConnectPoint <T>(this, Point.Out);
            connectPointOut.AddToClassList("connectPoint");
            connectPointOut.RegisterCallback <PointerDownEvent>((a) => { a.StopPropagation(); });

            #endregion

            Label label = new Label()
            {
                text = $"节点",
            };
            label.AddToClassList("text");

            VisualElement title = new VisualElement();
            title.AddToClassList("title");

            title.RegisterCallback <MouseMoveEvent>((a) =>
            {
                if (isMove)
                {
                    this.transform.position += (Vector3)a.mouseDelta;
                }
            });
            title.RegisterCallback <PointerDownEvent>((a) =>
            {
                isMove = true;
            });
            title.RegisterCallback <PointerUpEvent>((a) =>
            {
                isMove = false;
            });
            title.RegisterCallback <PointerEnterEvent>((a) =>
            {
                isMove = false;
            });

            title.Add(connectPointIn);
            title.Add(label);
            title.Add(connectPointOut);

            title.RegisterCallback <MouseDownEvent>((v) =>
            {
                if (v.button == 0 && v.clickCount == 2)
                {
                    if (Contains(m_ContentUI))
                    {
                        Remove(m_ContentUI);
                    }
                    else
                    {
                        Add(m_ContentUI);
                    }
                }
                else if (v.button == 1 && v.clickCount == 1)
                {
                    GenericMenu genericMenu = new GenericMenu();
                    genericMenu.AddItem(new GUIContent("Delete"), false, Delete);
                    NodeWindow.AddCreateNodeMenu(genericMenu, this.transform.position + new Vector3(150, 60, 0), "Add Next Node", (node) =>
                    {
                        AddNextNode(node);
                    });
                    NodeWindow.AddCreateNodeMenu(genericMenu, this.transform.position - new Vector3(20, 20, 0), "Add Prev Node", (node) =>
                    {
                        node.AddNextNode(this);
                    });
                    genericMenu.ShowAsContext();
                }
            });

            #endregion

            Add(title);
        }