Exemple #1
0
        /// <summary>
        /// 处理事件
        /// </summary>
        private void DealHandles(Rect canvas)
        {
            var window   = BtEditorWindow.Window;
            var curEvent = window.Event;

            if (curEvent.type == EventType.MouseDrag && curEvent.button == 0)
            {
                //拖拽
                if (BtNodeGraph.NodeRect.Contains(curEvent.mousePosition) && mCanDragMove)
                {
                    curEvent.Use();
                    mIsDragging          = true;
                    window.CurSelectNode = this;
                    var delta = BtEditorWindow.IsLockAxisY ? new Vector2(curEvent.delta.x, 0) : curEvent.delta;
                    UpdateNodePosition(this, delta);
                }
            }
            else if (curEvent.type == EventType.MouseDown && curEvent.button == 0)
            {
                //点击
                if (curEvent.mousePosition.x >= canvas.width - BtConst.RightInspectWidth)
                {
                    //window.CurSelectNode = null;
                }
                else if (BtNodeGraph.UpPointRect.Contains(curEvent.mousePosition))
                {
                    curEvent.Use();
                    if (!IsRoot)
                    {
                        if (IsHaveParent)
                        {
                            Parent.ChildNodeList.Remove(this);
                            Parent.Data.children.Remove(Data);
                            Owner.AddBrokenNode(this);
                            Parent = null;
                        }
                        else
                        {
                            window.CurSelectNode = this;
                            mIsLinkParent        = true;
                        }
                    }
                }
                else if (BtNodeGraph.NodeRect.Contains(curEvent.mousePosition))
                {
                    curEvent.Use();
                    window.CurSelectNode = this;
                    mCanDragMove         = true;
                }
                else
                {
                    window.CurSelectNode = null;
                }
            }
            else if (curEvent.type == EventType.MouseUp && curEvent.button == 0)
            {
                //松开鼠标
                if (mIsDragging)
                {
                    curEvent.Use();
                    mIsDragging = false;
                    if (BtEditorWindow.IsAutoAlign)
                    {
                        SetNodePosition(this);
                    }
                }

                if (mIsLinkParent)
                {
                    mIsLinkParent = false;
                    var parent = window.GetMouseTriggerDownPoint(curEvent.mousePosition);
                    if (parent != null && parent != this && parent.ChildNodeList.Count < parent.Type.CanAddNodeCount)
                    {
                        parent.ChildNodeList.Add(this);
                        parent.Data.AddChild(Data);
                        Owner.RemoveBrokenNode(this);
                        Parent = parent;
                    }
                }

                mCanDragMove = false;
            }
            else if (curEvent.type == EventType.ContextClick)
            {
                if (BtNodeGraph.NodeRect.Contains(curEvent.mousePosition))
                {
                    //显示右键菜单
                    ShowMenu();
                }
            }
        }