Ejemplo n.º 1
0
        public override void OnNodeGUI(DiagramWindowEvent e)
        {
            // Draw the window with property label.
            Rect r = new Rect(1f, 20f, nodeRect.width - DOUBLE_PADDING, 20f);

            GUI.BeginGroup(nodeRect, output.name, IsFocused ? window.activeNodeStyle : window.normalNodeStyle);
            GUI.Label(r, node.GetPropertyName(0));
            GUI.EndGroup();

            // Draw the property connector.
            r.x     = nodeRect.x - 17f;
            r.y     = nodeRect.y + 21f;
            r.width = r.height = CONNECTOR_SIZE;
            if (e.IsTouchBeginInsideRect(r))
            {
                window.StartTransaction(new ConnectionDragTransaction(this, 0, new Vector2(r.x, r.center.y) - window.scrollPosition));
                e.Use();
            }
            GUI.Box(r, typeBoxStrings[(int)node.Function.propertyTypes[0]], window.connectorBoxStyle);
            int argumentIndex = node.argumentIndices[0];

            if (argumentIndex >= 0)
            {
                DrawConnection(argumentIndex, r);
            }
        }
Ejemplo n.º 2
0
        public virtual void OnNodeGUI(DiagramWindowEvent e)
        {
            // Draw the window with property labels.
            Rect r = new Rect(1f, 20f, nodeRect.width - DOUBLE_PADDING, 20f);

            GUI.BeginGroup(nodeRect, node.Name, IsFocused ? window.activeNodeStyle : window.normalNodeStyle);

            if (node.Function == null || node.Function.type != FunctionType.Input)
            {
                for (int i = 0, l = node.PropertyCount; i < l; i++)
                {
                    GUI.Label(r, node.GetPropertyName(i));
                    r.y += 16f;
                }
                GUI.EndGroup();

                // Draw the property connectors.
                float
                    xOffset = nodeRect.x - 17f,
                    yOffset = nodeRect.y + 21f;
                r.width = r.height = CONNECTOR_SIZE;
                for (int i = 0, l = node.PropertyCount; i < l; i++)
                {
                    r.x = xOffset;
                    r.y = yOffset;
                    if (e.IsTouchBeginInsideRect(r))
                    {
                        window.StartTransaction(new ConnectionDragTransaction(this, i, new Vector2(r.x, r.center.y) - window.scrollPosition));
                        e.Use();
                    }
                    GUI.Box(r, node.Function == null ? " ?" : typeBoxStrings[(int)node.Function.propertyTypes[i]], window.connectorBoxStyle);
                    int argumentIndex = node.argumentIndices[i];
                    if (argumentIndex >= 0)
                    {
                        DrawConnection(argumentIndex, r);
                    }
                    else
                    {
                        DrawFixedValue(i, r);
                    }
                    yOffset += CONNECTOR_OFFSET_Y;
                }
            }
            else
            {
                GUI.Label(r, node.GetPropertyName(0));
                GUI.EndGroup();
            }

            // Draw the result connector.
            if (node.Function == null)
            {
                GUI.Box(OutputConnectionRect, " ?", window.connectorBoxStyle);
            }
            else if (node.Function.returnType != ValueType.None)
            {
                GUI.Box(OutputConnectionRect, typeBoxStrings[(int)node.Function.returnType], window.connectorBoxStyle);
            }
        }
Ejemplo n.º 3
0
 public bool OnGUI(DiagramWindowEvent e)
 {
     if (e.type == DiagramWindowEventType.TouchMove)
     {
         nodeToDrag.Position = nodeStartPosition + e.touchPosition - startPosition;
         e.Use();
         return(true);
     }
     if (e.type == DiagramWindowEventType.Layout || e.type == DiagramWindowEventType.Repaint)
     {
         return(true);
     }
     // Any event other than Move, Layout, or Repaint terminates the drag.
     // The TouchEnd event isn't reliable enough to depend on, as it doesn't happen when releasing a node outside of the canvas.
     e.Use();
     return(false);
 }
Ejemplo n.º 4
0
 public bool OnGUI(DiagramWindowEvent e)
 {
     if (e.type == DiagramWindowEventType.TouchMove)
     {
         e.Use();
         return(true);
     }
     if (e.type == DiagramWindowEventType.TouchEnd)
     {
         nodeToConnect.SetArgument(argumentIndex, e.targetWindowNode ?? e.targetOutputNode);
         e.Use();
         return(false);
     }
     if (e.type == DiagramWindowEventType.Repaint)
     {
         Handles.DrawBezier(startPosition, e.touchPosition, startTangent, e.touchPosition, Color.grey, null, 2f);
     }
     return(true);
 }
Ejemplo n.º 5
0
        private void OnGUI()
        {
            if (disabled)
            {
                GUI.Label(position, "Diagram editor is disabled while in play mode.");
                return;
            }
            if (normalNodeStyle == null)
            {
                InitializeStyles();
            }
            if (diagram == null)
            {
                // No diagram to show.
                return;
            }
            if (diagram.nodes.Length > 0 && diagram.nodes[0].Function == null)
            {
                // Intialize if needed.
                diagram.Init();
            }
            if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
            {
                // Start from scratch after detecting undo or redo.
                diagramSO = null;
                Repaint();
                return;
            }
            if (diagramSO == null)
            {
                InitializeWindow();
            }
            diagramSO.Update();

            diagramEvent.Reset(windowNodes, scrollPosition, selectedNodeIndex);

            for (int i = 0; i < transactions.Count; i++)
            {
                if (!transactions[i].OnGUI(diagramEvent))
                {
                    transactions.RemoveAt(i--);
                }
            }

            if (diagramEvent.type == DiagramWindowEventType.ContextClick)
            {
                if (diagramEvent.targetWindowNode != null)
                {
                    DoNodeContextMenu(diagramEvent.targetWindowNode);
                    diagramEvent.Use();
                    return;
                }
                if (PreviewRect.Contains(diagramEvent.touchPosition))
                {
                    ShowPreviewContextMenu();
                }
                else
                {
                    contextMenuPosition = diagramEvent.scrolledTouchPosition;
                    DoContextMenu();
                }
                diagramEvent.Use();
                return;
            }

            if (diagramEvent.type == DiagramWindowEventType.TouchBegin)
            {
                // Clear input focus.
                GUI.FocusControl("");
            }
            if (diagramEvent.type == DiagramWindowEventType.TouchBegin && diagramEvent.targetWindowNode != null)
            {
                if (selectedNodeIndex != diagramEvent.targetWindowNode.index)
                {
                    if (selectedNodeIndex >= 0)
                    {
                        windowNodes[selectedNodeIndex].IsFocused = false;
                    }
                    selectedNodeIndex = diagramEvent.targetWindowNode.index;
                    diagramEvent.targetWindowNode.IsFocused = true;
                    Repaint();
                }
                selectedNodeIndex = diagramEvent.targetWindowNode.index;

                StartTransaction(new NodeDragTransaction(diagramEvent.targetWindowNode, diagramEvent.touchPosition));
            }

            GUI.Label(new Rect(0f, 0f, position.width, 20f), diagram.name, nameLabelStyle);

            scrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, position.width, position.height), scrollPosition, canvas);
            for (int i = 0; i < windowNodes.Length; i++)
            {
                windowNodes[i].OnNodeGUI(diagramEvent);
            }
            GUI.EndScrollView();

            if (selectedNodeIndex >= 0 && selectedNodeIndex < nodesSP.arraySize)
            {
                windowNodes[selectedNodeIndex].OnSelectedWindowGUI(diagramEvent);
            }

            if (diagramSO != null && diagramSO.ApplyModifiedProperties())
            {
                diagram.prepared = false;
            }

            if (diagramEvent.type == DiagramWindowEventType.Used)
            {
                // Something happened, request a repaint.
                ComputeCanvas();
                Repaint();
                return;
            }

            if (diagramEvent.type == DiagramWindowEventType.Repaint && diagram.outputs != null && diagram.outputs.Length > 0)
            {
                System.Action <Rect, Texture2D> drawMethod = drawMethods[(int)diagram.outputs[diagram.previewOutputIndex].type, (int)diagram.outputs[diagram.previewOutputIndex].previewType];
                GUI.BeginGroup(PreviewRect, diagram.outputs[diagram.previewOutputIndex].name, normalNodeStyle);
                Rect r;
                if (diagram.isCubemap)
                {
                    // Flip preview.
                    if (diagram.previewCubemapType == DiagramCubemapPreviewType.Inside)
                    {
                        r = new Rect(1f, 16f + diagram.height, diagram.width, -diagram.height);
                    }
                    else
                    {
                        r = new Rect(1f + diagram.width, 16f + diagram.height, -diagram.width, -diagram.height);
                    }
                }
                else
                {
                    r = new Rect(1f, 16f, diagram.width, diagram.height);
                }
                drawMethod(r, previewTexture);
                if (diagram.tilePreviewHorizontally)
                {
                    r.x += diagram.width;
                    drawMethod(r, previewTexture);
                }
                if (diagram.tilePreviewVertically)
                {
                    r.y += diagram.height;
                    drawMethod(r, previewTexture);
                    if (diagram.tilePreviewHorizontally)
                    {
                        r.x -= diagram.width;
                        drawMethod(r, previewTexture);
                    }
                }
                GUI.EndGroup();
            }
        }