Ejemplo n.º 1
0
    private void OnClick(bool isCtrl, bool isLeft)
    {
        var hitNode = HitTest(Canvas.MouseInWorld);

        if (hitNode == null)
        {
            Selecteds.Clear();
        }
        else
        {
            if (!isLeft && !ReadOnly)
            {
                if (Graph.CheckOutput(hitNode) && MouseInPin(GetOutputPin(hitNode)))
                {
                    BreakOutputLink(hitNode);
                    ignoreRightUp = true;
                    return;
                }
                if (Graph.ChechInput(hitNode) && MouseInPin(GetInputPin(hitNode)))
                {
                    BreakInputLink(hitNode);
                    ignoreRightUp = true;
                    return;
                }
                if (Graph.IsStack(hitNode) && GetAddChildPinRect(hitNode).Contains(Canvas.MouseInWorld))
                {
                    BreakChildLink(hitNode);
                    ignoreRightUp = true;
                    return;
                }
            }
            bool hasSelected = Selecteds.Contains(hitNode);

            if (!isCtrl)
            {
                if (hasSelected && Selecteds.Count > 0)
                {
                    do
                    {
                        if (isLeft && !ReadOnly)
                        {
                            Rect rect = GetAddChildPinRect(hitNode);
                            if (Graph.IsStack(hitNode) && rect.Contains(Canvas.MouseInWorld))
                            {
                                DragMode = new ViewLinkMode(hitNode, true, true, rect.center);
                                break;
                            }
                            Vector2 center = GetOutputPin(hitNode);
                            if (Graph.CheckOutput(hitNode) && MouseInPin(center))
                            {
                                DragMode = new ViewLinkMode(hitNode, true, false, center);
                                break;
                            }
                            center = GetInputPin(hitNode);
                            if (Graph.ChechInput(hitNode) && MouseInPin(center))
                            {
                                DragMode = new ViewLinkMode(hitNode, false, false, center);
                                break;
                            }
                        }
                        return;
                    } while (false);
                    Selecteds.Clear();
                    Selecteds.Add(hitNode);
                    MoveNodeToBack(hitNode);
                }
                else
                {
                    if (!hasSelected)
                    {
                        SelectNode(hitNode);
                    }
                }
            }
            else
            {
                if (hasSelected)
                {
                    Selecteds.Remove(hitNode);
                }
                else
                {
                    Selecteds.Add(hitNode);
                    MoveNodeToBack(hitNode);
                }
            }
        }
    }
Ejemplo n.º 2
0
 private void OnEvent(Event e, Vector2 size)
 {
     if (e.type == EventType.MouseDown && e.button <= 1)
     {
         OnClick(e.control, e.button == 0);
         e.Use();
         return;
     }
     if (e.type == EventType.MouseUp)
     {
         if (DragMode != null && e.button == 0)
         {
             DragMode.OnDragEnd(this, Canvas.MouseInWorld);
             DragMode = null;
             e.Use();
             return;
         }
         if (e.button == 1)
         {
             e.Use();
             if (!ignoreRightUp)
             {
                 OnMenu();
             }
             ignoreRightUp = false;
             return;
         }
     }
     if (e.type == EventType.MouseDrag)
     {
         if (DragMode != null && e.button == 0)
         {
             DragMode.OnDrag(this, Canvas.MouseInWorld);
             e.Use();
             return;
         }
         if (e.button == 2 || (e.button == 1 && Selecteds.Count == 0))
         {
             //移动View
             Canvas.Pan(-e.delta);
             e.Use();
             ignoreRightUp = true;
             return;
         }
         if (e.button == 0)
         {
             Rect rect = new Rect(Vector2.zero, size);
             if (rect.Contains(e.mousePosition))
             {
                 if (Selecteds.Count > 0 && !ReadOnly)
                 {
                     DragMode = new ViewNormalMoveMode(this, Canvas.PointInWorld);
                 }
                 else
                 {
                     DragMode = new ViewAreaSelectMode(this, Canvas.PointInWorld);
                 }
             }
         }
     }
     if (e.type == EventType.KeyDown)
     {
         if (e.keyCode == KeyCode.Delete && !ReadOnly)
         {
             if (Selecteds.Count > 0)
             {
                 if (DeleteSelectedNode())
                 {
                     e.Use();
                 }
             }
             return;
         }
         bool control = (e.control || (Application.platform == RuntimePlatform.OSXEditor && e.command)) && !e.alt;
         if (control && e.keyCode == KeyCode.D && !ReadOnly)
         {
             if (Duplicate())
             {
                 e.Use();
                 return;
             }
         }
         if (control && e.keyCode == KeyCode.C)
         {
             CopyNodes();
             e.Use();
             return;
         }
         if (control && e.keyCode == KeyCode.V && !ReadOnly)
         {
             PasteFromClipboard();
             e.Use();
             return;
         }
         if (control && e.keyCode == KeyCode.A)
         {
             Selecteds.Clear();
             foreach (var node in Graph.Nodes)
             {
                 Selecteds.Add(node);
             }
             e.Use();
             return;
         }
     }
 }