예제 #1
0
    private void DragWindowLoop(CNode w, int ind)
    {
        Event e = Event.current;

        if (e.button == 0 && e.type == EventType.MouseDown && e.control == false)
        {
            if (w.pos.Contains(e.mousePosition))
            {
                if (dragNode == null && connectionDragging == null)
                {
                    selectedNode = w;
                }
            }
        }

        if (e.button == 0 && e.type == EventType.MouseDown && e.shift == true)
        {
            if (dragNode == null && connectionDragging == null)
            {
                if (!w.pos.Contains(e.mousePosition))
                {
                    enumming    = true;
                    enummingPos = e.mousePosition;
                }
            }
        }

        if (e.button == 0 && e.type == EventType.MouseUp && e.alt == true)
        {
            if (w.recieverBox.Contains(e.mousePosition))
            {
                for (int i = 0; i < c.nodes.nodes.Count; i++)
                {
                    if (c.nodes.nodes [i].connected.Contains(ind))
                    {
                        c.nodes.nodes [i].connected.Remove(ind);
                    }
                }
                w.recieved.Clear();
            }
            if (w.connecterBox.Contains(e.mousePosition))
            {
                w.connected.Clear();
            }
        }


        if (e.button == 0 && e.type == EventType.MouseDrag)
        {
            if (dragNode == w)
            {
                dragNode.pos = new Rect(new Vector2(e.mousePosition.x - w.pos.width / 2, e.mousePosition.y - w.pos.height / 2), w.pos.size);
                return;
            }
            if (w.pos.Contains(e.mousePosition))
            {
                if (dragNode == null)
                {
                    dragNode     = w;
                    dragNode.pos = new Rect(new Vector2(e.mousePosition.x - w.pos.width / 2, e.mousePosition.y - w.pos.height / 2), w.pos.size);
                }
            }
            if (w.connecterBox.Contains(e.mousePosition) && connectionDragging == null)
            {
                connectionDragging = w;
            }
        }
        if (e.button == 1 && e.type == EventType.MouseDown)
        {
            if (w.hideBox.Contains(e.mousePosition))
            {
                w.HideChildren(c);
                return;
            }
            else
            {
                selectedNode       = null;
                connectionDragging = null;
            }
        }
        if (e.button == 0 && e.type == EventType.MouseUp)
        {
            dragNode = null;
            if (w.hideBox.Contains(e.mousePosition))
            {
                w.hidden = !w.hidden;
                return;
            }
            if (w.showBox.Contains(e.mousePosition))
            {
                w.ShowChildren(c);
            }
            if (w.recieverBox.Contains(e.mousePosition) && connectionDragging != null && !connectionDragging.connected.Contains(ind))
            {
                connectionDragging.connected.Add(ind);
                w.recieved.Add(nodeToIndex(connectionDragging));
                w.tag = connectionDragging.tag;
                w.ChangeColor();
                connectionDragging = null;
                selectedNode       = w;
            }
        }
        if (e.button == 2 && e.type == EventType.MouseDown && e.alt == true)
        {
            if (w.pos.Contains(e.mousePosition))
            {
                for (int i = 0; i < c.nodes.nodes.Count; i++)
                {
                    if (c.nodes.nodes [i].connected.Contains(ind))
                    {
                        c.nodes.nodes [i].connected.Remove(ind);
                    }
                }
                w.recieved.Clear();
                w.connected.Clear();
                w.permaDel = true;
                w.hidden   = true;
            }
        }
        if (e.button == 2 && e.type == EventType.MouseDrag)
        {
            Vector2 dir = (e.mousePosition - lastPos).normalized;
            loc.position -= dir * 0.3f;
            lastPos       = e.mousePosition;
        }
        if (e.button == 2 && e.type == EventType.MouseUp)
        {
            loc.position = Vector2.zero;
        }
    }