예제 #1
0
 public override void Init()
 {
     condition       = CreateIO <Input_System_Boolean>();
     returnCondition = CreateIO <Input_System_Boolean>();
     childTrue       = CreateTreeOutput();
     childFalse      = CreateTreeOutput();
 }
예제 #2
0
 public override void Init()
 {
     animator      = CreateIO <Input_UnityEngine_Animator>();
     animatorLayer = CreateIO <Input_System_Int32>();
     animationClip = CreateIO <Input_UnityEngine_AnimationClip>();
     child         = CreateTreeOutput();
 }
예제 #3
0
        public void DrawNodeCurves(Node node)
        {
            Color c = GUI.color;

            // NodeIO
            foreach (var output in node.GetOutputs())
            {
                foreach (var input in output.GetInputs())
                {
                    Rect  from   = output.GetKnobRect(guiInfo);
                    Rect  to     = input.GetKnobRect(guiInfo);
                    Color shadow = output.GetColor();
                    shadow.a = 0.4f;
                    DrawNodeCurve(from.center, to.center, output.GetColor(), (Time.time - input.lastExecutedTime) / decayInSeconds);
                }
            }

            // Tree
            GUIStyle styleCloseButton = EditorStyles.miniButton;

            styleCloseButton.richText  = true;
            styleCloseButton.padding   = new RectOffset(0, 0, 0, 0);
            styleCloseButton.margin    = new RectOffset(0, 0, 0, 0);
            styleCloseButton.alignment = TextAnchor.MiddleCenter;
            foreach (var treeOutput in node.GetTreeOutputs())
            {
                var input = treeOutput.outputNode;
                if (input == null)
                {
                    continue;
                }

                Rect from = treeOutput.GetKnobRect(guiInfo);
                Rect to   = GetInputTreeNodeKnob(input);

                Color shadow = NodeTreeOutput.GetColor();
                shadow.a = 0.7f;
                DrawNodeCurve(from.center, to.center, NodeTreeOutput.GetColor(), (Time.time - treeOutput.lastExecutedTime) / decayInSeconds, TangetType.Vertical);

                GUI.color = NodeTreeOutput.GetColor();
                if (GUI.Button(new Rect(from.center + (to.center - from.center) / 2 - new Vector2(8, 8), new Vector2(16, 16)), "<color=white>X</color>", styleCloseButton))
                {
                    treeOutput.Set(null);
                }
                GUI.color = c;
            }
            GUI.color = c;
        }
예제 #4
0
        /// <summary>
        /// Processes input events
        /// </summary>
        private void InputEvents()
        {
            Event e = Event.current;

            mousePos = e.mousePosition;

            Node           clickedNode       = null;
            Group          clickedGroup      = null;
            NodeOutput     clickedOutput     = null;
            NodeInput      clickedInput      = null;
            NodeTreeOutput clickedTreeOutput = null;

            if (e.type == EventType.MouseDown || e.type == EventType.MouseUp)
            {
                clickedNode  = NodeAtPosition(mousePos);
                clickedGroup = EDIT_GROUPS ? GroupAtPosition(mousePos) : null;
                if (clickedNode != null)
                {
                    clickedOutput     = clickedNode.GetOutputAtPos(mousePos, guiInfo);
                    clickedInput      = clickedNode.GetInputAtPos(mousePos, guiInfo);
                    clickedTreeOutput = clickedNode.GetTreeOutputAtPos(mousePos, guiInfo);
                }
            }

            if (e.type == EventType.MouseDown)
            {
                if (e.button == 2)                   // Init scroll
                {
                    scrollWindow = true;
                    e.delta      = new Vector2(0, 0);
                    e.Use();
                }
                else if (e.button == 1)                     // Right click -> Editor Context Click
                {
                    if (clickedOutput != null)
                    {
                        connectInput = new List <NodeInput>(clickedOutput.GetInputs()).ToArray();
                        foreach (var i in connectInput)
                        {
                            clickedOutput.RemoveNodeInput(i);
                        }
                    }
                    else
                    {
                        GenericMenu menu = new GenericMenu();

                        if (clickedNode != null)
                        {
                            menu.AddItem(new GUIContent("Set as Start Node"), false, () => { nodeCanvas.SetFirstNode(clickedNode); });
                            menu.AddSeparator("");
                            nodeCanvas.ForeachGroup(group => {
                                if (!group.ContainsNode(clickedNode))
                                {
                                    menu.AddItem(new GUIContent("Add to Group/" + group.GetName()), false, () => { group.AddNode(clickedNode); group.needsUpdate = true; });
                                }
                            });
                            menu.AddItem(new GUIContent("Add to Group/New Group"), false, () => { AddGroup().AddNode(clickedNode); });
                            nodeCanvas.ForeachGroup(group => {
                                if (group.ContainsNode(clickedNode))
                                {
                                    menu.AddItem(new GUIContent("Remove from Group/" + group.GetName()), false, () => { group.RemoveNode(clickedNode); group.needsUpdate = true; });
                                }
                            });
                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Rename Node"), false, () => { WindowChangeName.AskName(clickedNode, mousePos + position.position); });
                            menu.AddItem(new GUIContent("Delete Node"), false, () => {
                                if (EditorUtility.DisplayDialog("¿Delete, are you sure?", "¿Do you really want to delete this node?", "Delete it", "Nope, Don't touch it"))
                                {
                                    DeleteNodeDeferred(clickedNode);
                                }
                            });
                        }
                        else if (clickedGroup != null)
                        {
                            menu.AddItem(new GUIContent("Rename Group"), false, () => { WindowChangeName.AskName(clickedGroup, mousePos + position.position); });
                            menu.AddItem(new GUIContent("Remove Group"), false, () => {
                                // ok, alt, nope
                                int response = EditorUtility.DisplayDialogComplex("¿Delete, are you sure?", "¿Do you really want to delete this group?", "Delete it", "Nope, Don't touch it", "Delete it + nodes");
                                if (response == 2)
                                {
                                    foreach (var node in clickedGroup.GetNodes())
                                    {
                                        DeleteNodeDeferred(node);
                                    }
                                    DeleteGroupDeferred(clickedGroup);
                                }
                                if (response == 0)
                                {
                                    DeleteGroupDeferred(clickedGroup);
                                }
                            });
                        }
                        else
                        {
                            foreach (var elem in CreateNodeAttribute.Cached)
                            {
                                menu.AddItem(new GUIContent(elem.Value.name, elem.Value.description), false, MenuNodeContextCallback, elem.Key);
                            }
                        }
                        menu.ShowAsContext();
                    }

                    e.Use();
                }
                else if (e.button == 0)
                {
                    scrollWindow = false;
                    e.delta      = new Vector2(0, 0);
                    // If a Connection was left clicked, try edit it's transition
                    if (clickedNode != null)
                    {
                        if (clickedOutput != null)
                        {
                            if (connectInput.Length > 0)
                            {
                                bool connectedOk = true;
                                foreach (var i in connectInput)
                                {
                                    if (!clickedNode.TryApplyConnection(clickedOutput, i))
                                    {
                                        connectedOk = false;
                                        break;
                                    }
                                }
                                if (connectedOk)
                                {
                                    connectInput = new NodeInput[0];
                                }
                            }
                            else
                            {
                                connectOutput = clickedOutput;
                            }
                            e.Use();
                        }
                        else if (clickedTreeOutput != null)
                        {
                            connectTreeOutput = clickedTreeOutput;
                            connectOutput     = null;
                            e.Use();
                        }
                        else if (connectOutput != null)
                        {
                            if (!ArrayUtility.Contains((NodeOutput[])clickedNode.GetOutputs(), connectOutput))                                // If an input was clicked, it'll will now be connected
                            {
                                clickedNode.TryApplyConnection(connectOutput, clickedInput);
                                if (!e.control && !e.shift)
                                {
                                    connectOutput = null;
                                }
                            }
                            else
                            {
                                connectOutput = null;
                            }
                            e.Use();
                        }
                        else if (connectTreeOutput != null)
                        {
                            if (clickedNode != connectTreeOutput.GetBody())
                            {
                                if (clickedNode != null)
                                {
                                    connectTreeOutput.Set(clickedNode);
                                }
                            }
                            connectTreeOutput = null;
                            e.Use();
                        }
                        else if (clickedInput != null && clickedInput.nodeOutput != null)                             // Input node -> Loose and edit Connection
                        {
                            connectOutput = clickedInput.nodeOutput;
                            connectOutput.RemoveNodeInput(clickedInput);
                            e.Use();
                        }
                        else
                        {
                            if (selectedNode != null)
                            {
                                selectedNode.isNodeSelected = false;
                            }
                            selectedNode = clickedNode;
                        }
                    }
                    else if (clickedGroup != null)
                    {
                        movingGroup = clickedGroup;
                    }
                    else
                    {
                        selectedNode = null;
                        if (connectOutput != null)
                        {
                            connectOutput = null;
                            e.Use();
                        }
                        else if (connectTreeOutput != null)
                        {
                            connectTreeOutput = null;
                            e.Use();
                        }
                        else if (clickedGroup == null)                             // Init scroll
                        {
                            scrollWindow = true;
                            e.delta      = new Vector2(0, 0);
                            e.Use();
                        }
                    }
                }
            }
            else if (e.type == EventType.MouseUp)
            {
                if (movingGroup != null)
                {
                    movingGroup = null;
                }
                else if (e.button == 0 && connectOutput != null)                     // Apply a connection if theres a clicked input
                {
                    if (clickedNode == null)
                    {
                        connectOutput = null;
                        e.Use();
                    }
                    else if (!ArrayUtility.Contains((NodeOutput[])clickedNode.GetOutputs(), connectOutput))                          // If an input was clicked, it'll will now be connected
                    {
                        clickedNode.TryApplyConnection(connectOutput, clickedInput);
                        if (!e.control && !e.shift)
                        {
                            connectOutput = null;
                        }
                        e.Use();
                    }
                }
                else if (e.button == 0 && connectTreeOutput != null)
                {
                    if (clickedNode != connectTreeOutput.GetBody())
                    {
                        if (clickedNode != null)
                        {
                            connectTreeOutput.Set(clickedNode);
                        }
                        connectTreeOutput = null;
                        e.Use();
                    }
                }
                else if (e.button == 2 || e.button == 0)                     // Left/Middle click up -> Stop scrolling
                {
                    scrollWindow = false;
                }
            }
            else if (e.type == EventType.Repaint)
            {
                // Draw the currently drawn connection
                if (connectOutput != null)
                {
                    DrawNodeCurve(connectOutput.GetKnobRect(guiInfo).center, mousePos, connectOutput.GetColor());
                    Repaint();
                }
                else if (connectTreeOutput != null)
                {
                    DrawNodeCurve(connectTreeOutput.GetKnobRect(guiInfo).center, mousePos, NodeTreeOutput.GetColor(), TangetType.Vertical);
                    Repaint();
                }
                else if (connectInput.Length > 0)
                {
                    foreach (var i in connectInput)
                    {
                        DrawNodeCurve(mousePos, i.GetKnobRect(guiInfo).center, i.GetColor());
                    }
                    Repaint();
                }
            }

            if (e.type == EventType.ScrollWheel)
            {
                float multiplier = e.delta.y < 0 ? 2 : e.delta.y > 0 ? 0.5f : 0;

                if (multiplier != 0)
                {
                    nodeCanvas.zoom.DoZoom(multiplier);

                    /*
                     * float diff = nodeCanvas.zoom.zoom - initialZoom;
                     *
                     * if (diff > 0) {
                     *      nodeCanvas.scrollOffset -= (e.mousePosition * initialZoom) / nodeCanvas.zoom.zoom;
                     * } else if (diff < 0) {
                     *      nodeCanvas.scrollOffset += (e.mousePosition * targetZoom) / nodeCanvas.zoom.zoom;
                     * }
                     */
                }

                e.Use();
            }

            if (scrollWindow)
            {
                nodeCanvas.scrollOffset += e.delta / 2;
            }
            else if (movingGroup)
            {
                movingGroup.AddDelta(e.delta, guiInfo);
            }
            else
            {
                nodeCanvas.scrollOffset = new Vector2((int)nodeCanvas.scrollOffset.x, (int)nodeCanvas.scrollOffset.y);
            }
        }
예제 #5
0
 public override void Init()
 {
     child = CreateTreeOutput();
 }
예제 #6
0
 public override void Init()
 {
     child       = CreateTreeOutput();
     repetitions = CreateIO <Input_System_Int32>();
 }
예제 #7
0
 public void RemoveTreeOutput(NodeTreeOutput elem)
 {
     this.Remove("treeOutputs", elem);
 }
예제 #8
0
 public void AddTreeOutput(NodeTreeOutput elem)
 {
     this.Add("treeOutputs", elem);
 }
예제 #9
0
 public override void Init()
 {
     seconds           = CreateInput <Input_System_Single, float>(1f);
     skipMinimumAFrame = CreateInput <Input_System_Boolean, bool>(true);
     child             = CreateTreeOutput();
 }
예제 #10
0
 public DeciderInput(Decider decider)
 {
     score  = decider.CreateIO <Input_System_Single>();
     output = decider.CreateTreeOutput();
 }