Exemplo n.º 1
0
        private void InitializeWindow()
        {
            diagramSO    = new SerializedObject(diagram);
            nodesSP      = diagramSO.FindProperty("nodes");
            diagramEvent = new DiagramWindowEvent();
            if (selectedNodeIndex >= diagram.nodes.Length)
            {
                selectedNodeIndex = -1;
            }

            windowNodes = new DiagramWindowNode[diagram.nodes.Length];
            for (int i = 0; i < diagram.nodes.Length; i++)
            {
                if (diagram.nodes[i].Function == null || diagram.nodes[i].Function.type != FunctionType.Output)
                {
                    windowNodes[i] = new DiagramWindowNode(i, diagram.nodes[i], nodesSP.GetArrayElementAtIndex(i), this);
                }
                else
                {
                    windowNodes[i] = new DiagramWindowOutputNode(i, diagram.nodes[i], nodesSP.GetArrayElementAtIndex(i), this);
                }
                if (selectedNodeIndex == i)
                {
                    windowNodes[i].IsFocused = true;
                }
            }
            ComputeCanvas();
            transactions     = new List <DiagramWindowTransaction>();
            diagram.prepared = false;
        }
Exemplo n.º 2
0
 public bool SetArgument(int argumentIndex, DiagramWindowNode argumentNode)
 {
     if (argumentNode == null && node.argumentIndices[argumentIndex] < 0 || argumentNode != null && argumentNode.index == node.argumentIndices[argumentIndex])
     {
         // No change.
         return(false);
     }
     if (argumentNode == null)
     {
         // Disconnect property.
         nodeSP.FindPropertyRelative("argumentIndices").GetArrayElementAtIndex(argumentIndex).intValue = -1;
         return(true);
     }
     if (node.Function.propertyTypes[argumentIndex] != argumentNode.node.Function.returnType)
     {
         window.ShowNotification(new GUIContent("Cannot connect " + node.Function.propertyTypes[argumentIndex] + " to " + argumentNode.node.Function.returnType));
         return(false);
     }
     if (argumentNode.node.IsDependentOn(node))
     {
         window.ShowNotification(new GUIContent("Cannot create a loop."));
         return(false);
     }
     nodeSP.FindPropertyRelative("argumentIndices").GetArrayElementAtIndex(argumentIndex).intValue = argumentNode.index;
     return(true);
 }
Exemplo n.º 3
0
        private void DoNodeContextMenu(DiagramWindowNode node)
        {
            GenericMenu menu = new GenericMenu();

            menu.AddItem(new GUIContent("Delete"), false, DeleteNodeCallback, node);
            menu.AddItem(new GUIContent("Duplicate"), false, DuplicateNodeCallback, node);
            menu.ShowAsContext();
        }
Exemplo n.º 4
0
 public ConnectionDragTransaction(DiagramWindowNode nodeToConnect, int argumentIndex, Vector2 startPosition)
 {
     this.nodeToConnect = nodeToConnect;
     this.argumentIndex = argumentIndex;
     this.startPosition = startPosition;
     startTangent       = startPosition;
     startTangent.x    -= 60f;
 }
Exemplo n.º 5
0
 public NodeDragTransaction(DiagramWindowNode nodeToDrag, Vector2 dragStartPosition)
 {
     this.nodeToDrag   = nodeToDrag;
     nodeStartPosition = nodeToDrag.Position;
     startPosition     = dragStartPosition;
 }
Exemplo n.º 6
0
        public void Reset(DiagramWindowNode[] windowNodes, Vector2 scrollPosition, int selectedNodeIndex)
        {
            type = DiagramWindowEventType.None;
            if (selectedNodeIndex < 0 || selectedNodeIndex >= windowNodes.Length ||
                !windowNodes[selectedNodeIndex].SelectedWindowRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.button == 0)
                {
                    switch (Event.current.type)
                    {
                    case EventType.MouseDown:
                        type = DiagramWindowEventType.TouchBegin;
                        break;

                    case EventType.MouseUp:
                        type = DiagramWindowEventType.TouchEnd;
                        break;

                    case EventType.MouseDrag:
                        type = DiagramWindowEventType.TouchMove;
                        break;
                    }
                }
                if (Event.current.type == EventType.ContextClick)
                {
                    type = DiagramWindowEventType.ContextClick;
                }
            }
            if (type == DiagramWindowEventType.None)
            {
                switch (Event.current.type)
                {
                case EventType.Layout:
                    type = DiagramWindowEventType.Layout;
                    break;

                case EventType.Repaint:
                    type = DiagramWindowEventType.Repaint;
                    break;
                }
                return;
            }

            touchPosition         = Event.current.mousePosition;
            scrolledTouchPosition = touchPosition + scrollPosition;

            if (type == DiagramWindowEventType.TouchMove)
            {
                // Keep targeting the same node while a drag is in progress.
                return;
            }

            targetWindowNode = null;
            targetOutputNode = null;
            for (int i = windowNodes.Length - 1; i >= 0; i--)
            {
                if (windowNodes[i].Contains(scrolledTouchPosition))
                {
                    targetWindowNode = windowNodes[i];
                    break;
                }
                if (windowNodes[i].OutputConnectionRect.Contains(scrolledTouchPosition))
                {
                    targetOutputNode = windowNodes[i];
                    break;
                }
            }
        }