Inheritance: UnityEngine.ScriptableObject
Esempio n. 1
0
 private void Output_OnTypeChanged(NodeOutput inp)
 {
     //be sure to invoke on main thread
     //as it is possible for this event
     //to trigger from another thread now
     App.Current.Dispatcher.Invoke(() =>
     {
         UpdateColor();
     });
 }
Esempio n. 2
0
    /// <summary>
    /// Creates a new NodeOutput in NodeBody of specified type
    /// </summary>
    public static NodeOutput Create(Node NodeBody, string OutputName, Type OutputType)
    {
        NodeOutput output = NodeOutput.CreateInstance(typeof(NodeOutput)) as NodeOutput;

        output.body = NodeBody;
        output.type = OutputType.AssemblyQualifiedName;
        output.name = OutputName;
        NodeBody.Outputs.Add(output);
        return(output);
    }
Esempio n. 3
0
        public NodeOutput Execute(List <Node> inputs, NodeOutput currentOutput)
        {
            // If any of them are not calculated we can't determine the result yet.
            if (inputs.Any(x => x.Output == NodeOutput.NotCalculated))
            {
                return(NodeOutput.NotCalculated);
            }

            return(inputs.Count(x => x.Output == NodeOutput.On) == 1 ? NodeOutput.On : NodeOutput.Off);
        }
Esempio n. 4
0
        public override void FromJson(string data)
        {
            NodeData d = JsonConvert.DeserializeObject <NodeData>(data);

            SetBaseNodeDate(d);

            Output = new NodeOutput(NodeType.Color | NodeType.Gray, this);
            Outputs.Clear();
            Outputs.Add(Output);
        }
    public override Node Create(Vector2 pos)
    { // This function has to be registered in Node_Editor.ContextCallback
        InputNodeAnimated node = CreateInstance <InputNodeAnimated> ();

        node.name    = "Input Float Animated";
        node.rect    = new Rect(pos.x, pos.y, 100, 50);;
        node.m_Value = new FloatRemap(1, -1, 1);
        NodeOutput.Create(node, "Value", "Float");

        return(node);
    }
Esempio n. 6
0
        public override Node Create(Vector2 pos)
        {
            InputNode node = CreateInstance <InputNode> ();

            node.name = "Input Node";
            node.rect = new Rect(pos.x, pos.y, 200, 50);;

            NodeOutput.Create(node, "Value", "Float");

            return(node);
        }
Esempio n. 7
0
    public override Node Create(Vector2 pos)
    {     // This function has to be registered in Node_Editor.ContextCallback
        InputNode node = CreateInstance <InputNode> ();

        node.name = "Input Node";
        node.rect = new Rect(pos.x, pos.y, 200, 50);;

        NodeOutput.Create(node, "Value", "Float");

        return(node);
    }
Esempio n. 8
0
        void Setup()
        {
            int count = 0;

            if (GraphInst.InputNodes.Count > 0)
            {
                count = GraphInst.InputNodes.Count;
                for (int i = 0; i < count; i++)
                {
                    string id = GraphInst.InputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        InputNode inp = (InputNode)n;
                        NodeInput np  = new NodeInput(NodeType.Color | NodeType.Gray, this, inp.Name);

                        inp.SetInput(np);
                        Inputs.Add(np);
                    }
                }
            }

            if (GraphInst.OutputNodes.Count > 0)
            {
                count = GraphInst.OutputNodes.Count;
                for (int i = 0; i < count; i++)
                {
                    string id = GraphInst.OutputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        OutputNode op = (OutputNode)n;

                        NodeOutput ot;

                        ot = new NodeOutput(NodeType.Color | NodeType.Gray, n, op.Name);
                        //we add to our graph instance outputs so things can actually connect
                        //to the output
                        Outputs.Add(ot);
                        op.SetOutput(ot);

                        n.OnUpdate += N_OnUpdate;
                    }
                }
            }

            //name map used in parameter mapping for quicker lookup
            count = GraphInst.CustomParameters.Count;
            for (int i = 0; i < count; i++)
            {
                var param = GraphInst.CustomParameters[i];
                nameMap[param.Name] = param;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// A recursive function to clear all inputs that depend on the outputs of node.
 /// Usually does not need to be called manually
 /// </summary>
 private void ClearChildrenInput(Node node)
 {
     for (int outCnt = 0; outCnt < node.Outputs.Count; outCnt++)
     {
         NodeOutput output = node.Outputs [outCnt];
         output.value = null;
         for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
         {
             ClearChildrenInput(output.connections [conCnt].body);
         }
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
 /// </summary>
 public static void ApplyConnection(NodeOutput output, NodeInput input)
 {
     if (input != null && output != null)
     {
         if (input.connection != null)
         {
             input.connection.connections.Remove(input);
         }
         input.connection = output;
         output.connections.Add(input);
     }
 }
Esempio n. 11
0
        private void N_OnOutputRemovedFromNode(Node n, NodeOutput inp)
        {
            var uinp = OutputNodes.Find(m => m.Output == inp);

            if (uinp != null)
            {
                OutputStack.Children.Remove(uinp);
                OutputNodes.Remove(uinp);
            }

            ResizeHeight();
        }
Esempio n. 12
0
    public override Node Create(Vector2 pos)
    {     // This function has to be registered in Node_Editor.ContextCallback
        PrimitiveNode node = CreateInstance <PrimitiveNode> ();

        node.name = "Primitive Node";
        node.rect = new Rect(pos.x, pos.y, 200, 100);

        NodeInput.Create(node, "Parent", "GameObject");
        NodeOutput.Create(node, "GameObject", "GameObject");

        return(node);
    }
Esempio n. 13
0
        public CurvesNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA)
        {
            Name = "Curves";
            Id   = Guid.NewGuid().ToString();

            width  = w;
            height = h;

            minValue = 0;
            maxValue = 1;

            points = new Dictionary <int, List <Point> >();

            previewProcessor = new BasicImageRenderer();

            tileX = tileY = 1;

            lutBrush = new FloatBitmap(256, 2);

            internalPixelType = p;

            curveLUT = new GLTextuer2D(GLInterfaces.PixelInternalFormat.Rgba8);
            curveLUT.Bind();
            curveLUT.SetFilter((int)GLInterfaces.TextureMinFilter.Nearest, (int)GLInterfaces.TextureMagFilter.Nearest);
            curveLUT.SetWrap((int)GLInterfaces.TextureWrapMode.Repeat);
            GLTextuer2D.Unbind();

            processor = new CurvesProcessor(curveLUT);

            //set defaults
            List <Point> pts = new List <Point>();

            pts.Add(new Point(0, 1));
            pts.Add(new Point(1, 0));

            points[0] = pts;
            points[1] = pts;
            points[2] = pts;
            points[3] = pts;

            input  = new NodeInput(NodeType.Color | NodeType.Gray, this, "Image Input");
            Output = new NodeOutput(NodeType.Color | NodeType.Gray, this);

            input.OnInputAdded   += Input_OnInputAdded;
            input.OnInputChanged += Input_OnInputChanged;
            input.OnInputRemoved += Input_OnInputRemoved;

            Inputs = new List <NodeInput>();
            Inputs.Add(input);

            Outputs = new List <NodeOutput>();
            Outputs.Add(Output);
        }
Esempio n. 14
0
        private void N_OnOutputAddedToNode(Node n, NodeOutput inp)
        {
            UINodePoint outpoint = new UINodePoint(this, Graph);

            outpoint.Output            = inp;
            outpoint.VerticalAlignment = VerticalAlignment.Center;
            OutputNodes.Add(outpoint);
            OutputStack.Children.Add(outpoint);
            outpoint.UpdateColor();

            ResizeHeight();
        }
Esempio n. 15
0
    public static InputNode Create(Rect NodeRect)
    {     // This function has to be registered in Node_Editor.ContextCallback
        InputNode node = ScriptableObject.CreateInstance <InputNode> ();

        node.name = "Input Node";
        node.rect = NodeRect;

        NodeOutput.Create(node, "Value", typeof(float));
        node.Outputs [0].value = node.value;

        node.Init();
        return(node);
    }
Esempio n. 16
0
        public override Node Create(Vector2 pos)
        {
            var node = CreateInstance <SetChildrenOfGameObjectNode>();

            node.name = "Set Children Of Game Object Node";
            node.BaseActionSequence.name = node.name;
            node.rect = new Rect(pos.x, pos.y, 200, 80);;

            NodeInput.Create(node, "", "Float");
            NodeOutput.Create(node, "", "Float");

            return(node);
        }
Esempio n. 17
0
    protected void CreateConnectedLine(NodeOutput node)
    {
        var lineObject = new GameObject("Connected Line Object", typeof(UILineRenderer));

        lineObject.transform.SetParent(node.transform);
        lineObject.transform.localPosition = Vector2.zero;
        node.lineRenderer = lineObject.GetComponent <UILineRenderer>();

        node.lineRenderer.rectTransform.sizeDelta = new Vector2(12, 12);
        node.lineRenderer.BezierMode             = UILineRenderer.BezierType.Improved;
        node.lineRenderer.BezierSegmentsPerCurve = 20;
        node.lineRenderer.Points = new Vector2[4];
    }
Esempio n. 18
0
        public override void OnSortTargets()
        {
            if (IsDecision)
            {
                Decision    dec     = (Decision)Task;
                List <Task> m_tasks = new List <Task>();
                NodeOutput  output  = outputs[0];

                m_tasks = output.TargetInputs.Select((NodeInput input) => (Task)input.Parent.Task).ToList();

                dec.SetChilds(m_tasks);
            }
        }
Esempio n. 19
0
        public override Node Create(Vector2 pos)
        { // This function has to be registered in Node_Editor.ContextCallback
            var node = CreateInstance <EnablePlayerControlNode>();

            node.name = "Enable Player Control Node";
            node.BaseActionSequence.name = node.name;
            node.rect = new Rect(pos.x, pos.y, 200, 80);;

            NodeInput.Create(node, "", "Float");
            NodeOutput.Create(node, "", "Float");

            return(node);
        }
Esempio n. 20
0
        public override Node Create(Vector2 pos)
        {
            var node = CreateInstance <ChangeCameraOwnerNode>();

            node.name = "Change Camera Owner Node";
            node.BaseActionSequence.name = node.name;
            node.rect = new Rect(pos.x, pos.y, 200, 80);;

            NodeInput.Create(node, "", "Float");
            NodeOutput.Create(node, "", "Float");

            return(node);
        }
Esempio n. 21
0
    //public static GUIStyle plusButton;

    public static DialNode Create(Rect NodeRect)
    {    //This function has to be registered in Node_Editor.ContextCallback
        DialNode node = ScriptableObject.CreateInstance <DialNode> ();

        node.name = "Dialogue Node";
        node.rect = NodeRect;

        NodeInput.Create(node, "Input 1", typeof(string));
        NodeOutput.Create(node, "Output 1", typeof(string));

        node.Init();
        return(node);
    }
Esempio n. 22
0
        public override Node Create(Vector2 pos)
        {
            var node = CreateInstance <TextNode>();

            node.name = "Text";
            node.rect = new Rect(pos.x, pos.y, 200, 150);

            node.CreateInput("Dialogue", "Dialogue", NodeSide.Left, 10);

            NodeOutput.Create(node, "next", "Dialogue");

            return(node);
        }
Esempio n. 23
0
        public CallNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA) : base()
        {
            //we ignore w,h,p

            CanPreview = false;

            Name     = "Call";
            Id       = Guid.NewGuid().ToString();
            shaderId = "S" + Id.Split('-')[0];

            output = new NodeOutput(NodeType.Float | NodeType.Float2 | NodeType.Float3 | NodeType.Float4, this);
            Outputs.Add(output);
        }
Esempio n. 24
0
    /// <summary>
    /// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
    /// </summary>
    public static void ApplyConnection(NodeOutput output, NodeInput input)
    {
        if (input != null && output != null)
        {
            if (input.connection != null)
            {
                input.connection.connections.Remove (input);
            }
            input.connection = output;
            output.connections.Add (input);

            NodeEditor.RecalculateFrom (input.body);
        }
    }
Esempio n. 25
0
        private void N_OnOutputRemovedFromNode(Node n, NodeOutput inp, NodeOutput previous = null)
        {
            var uinp = OutputNodes.Find(m => m.Output == inp);

            if (uinp != null)
            {
                //whoops forgot to dispose
                //on the uinodepoint to remove previous connects
                //etc
                uinp.Dispose();
                OutputStack.Children.Remove(uinp);
                OutputNodes.Remove(uinp);
            }
        }
Esempio n. 26
0
        public override void FromJson(Dictionary <string, Node> nodes, string data)
        {
            InputNodeData d = JsonConvert.DeserializeObject <InputNodeData>(data);

            SetBaseNodeDate(d);

            Output = new NodeOutput(NodeType.Color | NodeType.Gray, this);
            Outputs.Clear();
            Outputs.Add(Output);

            SetConnections(nodes, d.outputs);

            TryAndProcess();
        }
Esempio n. 27
0
 protected void addAllConnected(List <NarrativeNode> l, NodeOutput output)
 {
     if (output.connections == null)
     {
         return;
     }
     for (int i = 0; i < output.connections.Count; ++i)
     {
         if (output.connections [i].body != null)
         {
             l.Add(output.connections [i].body as NarrativeNode);
         }
     }
 }
Esempio n. 28
0
        public void Reset(bool resetOutput)
        {
            TimesCalculated = 0;

            if (resetOutput)
            {
                Output = NodeOutput.NotCalculated;
            }

            foreach (var output in Outputs)
            {
                output.Reset(true);
            }
        }
Esempio n. 29
0
        private void Output_OnInputRemoved(NodeOutput inp)
        {
            var empties = Outputs.FindAll(m => m.To.Count == 0);

            if (Outputs.Count > 2 && empties != null && empties.Count >= 2)
            {
                var inp2 = empties[empties.Count - 1];
                inp2.OnInputAdded   -= Output_OnInputAdded;
                inp2.OnInputRemoved -= Output_OnInputRemoved;

                Outputs.Remove(inp2);
                RemovedOutput(inp2);
            }
        }
Esempio n. 30
0
    public override Node Create(Vector2 pos)
    { // This function has to be registered in Node_Editor.ContextCallback
        RandomFloatInput node = CreateInstance <RandomFloatInput> ();

        node.name   = "RandomFloatInput";
        node.rect   = new Rect(pos.x, pos.y, 100, 80);;
        node.m_Seed = new FloatRemap(Random.value, 0, 1);
        node.m_Min  = new FloatRemap(0, 0, 1);
        node.m_Max  = new FloatRemap(1, 0, 1);

        NodeOutput.Create(node, "Value", "Float");

        return(node);
    }
Esempio n. 31
0
    /// <summary>
    /// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
    /// </summary>
    public static void ApplyConnection(NodeOutput output, NodeInput input)
    {
        if (input != null && output != null)
        {
            if (input.connection != null)
            {
                input.connection.connections.Remove(input);
            }
            input.connection = output;
            output.connections.Add(input);

            Node_Editor.editor.RecalculateFrom(input.body);
        }
    }
Esempio n. 32
0
        /// <summary>
        /// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
        /// </summary>
        public static void ApplyConnection(NodeOutput output, NodeInput input)
        {
            if (input != null && output != null)
            {
            // 11-27-2016 @radiatoryang -- changed "only one input connection" check)
                if (input.connection != null && input.body.ForceOnePerInput)
                    input.connection.connections.Remove (input);
                input.connection = output;
                output.connections.Add (input);

                NodeEditor.RecalculateFrom (input.body);

                NodeEditorCallbacks.IssueOnAddConnection (input);
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
        /// </summary>
        public static void ApplyConnection(NodeOutput output, NodeInput input)
        {
            if (input != null && output != null)
            {
                if (input.connection != null)
                {
                    input.connection.connections.Remove (input);
                }
                input.connection = output;
                output.connections.Add (input);

                if (input.body.shouldCalculate)
                    NodeEditor.RecalculateFrom (input.body);

                NodeEditorCallbacks.IssueOnAddConnection (input);
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Check if an output and an input can be connected (same type, ...)
        /// </summary>
        public static bool CanApplyConnection(NodeOutput output, NodeInput input)
        {
            if (input == null || output == null)
                return false;

            if (input.body == output.body || input.connection == output)
                return false;

            if (input.type != output.type)
                return false;

            if (output.body.isChildOf (input.body))
            {
                NodeEditorWindow.editor.ShowNotification (new GUIContent ("Recursion detected!"));
                return false;
            }
            return true;
        }
Esempio n. 35
0
        /// <summary>
        /// Check if an output and an input can be connected (same type, ...)
        /// </summary>
        public static bool CanApplyConnection(NodeOutput output, NodeInput input)
        {
            if (input == null || output == null)
                return false;

            if (input.body == output.body || input.connection == output)
                return false;

            if (input.type != output.type)
                return false;

            if ((!output.body.allowRecursion || !input.body.allowRecursion) && output.body.isChildOf (input.body))
            {
                // TODO: Generic Notification
                //ShowNotification (new GUIContent ("Recursion detected!"));
                return false;
            }
            return true;
        }
Esempio n. 36
0
        /// <summary>
        /// Check if an output and an input can be connected (same type, ...)
        /// </summary>
        public static bool CanApplyConnection(NodeOutput output, NodeInput input)
        {
            if (input == null || output == null)
                return false;
            if (input.body == output.body || input.connection == output)
                return false;
            if (input.type != output.type)
                return false;

            bool isRecursive = output.body.isChildOf (input.body);
            if (isRecursive)
            {
                if (!output.body.allowsLoopRecursion (input.body))
                {
                    // TODO: Generic Notification
                    Debug.LogWarning ("Cannot apply connection: Recursion detected!");
                    return false;
                }
            }
            return true;
        }
Esempio n. 37
0
 public virtual void AddOutput(NodeOutput output)
 {
     Outputs.Add(output);
 }
Esempio n. 38
0
    //Leftside Green
    public void DrawNodeGraphInputs(Rect viewRect, GUISkin guiSkin)
    {
        if(graphNode != null)
        {
            graphInputRects.Clear();
            for (int i = 0; i < graphNode.nodeInputs.Count; i++)
            {
                Rect temp;
                if (ViewOptions.showShelf)
                {
                    temp = new Rect(0, viewRect.y + (viewRect.height * (1f / (graphNode.nodeInputs.Count + 1))) * (i + 1), 32f, 64f);
                    graphInputRects.Add(temp);
                }
                else
                {
                    temp = new Rect(viewRect.x, viewRect.y + (viewRect.height * (1f / (graphNode.nodeInputs.Count + 1))) * (i + 1), 32f, 64f);
                    graphInputRects.Add(temp);
                }
                NodeInput input = graphNode.nodeInputs[i];
                if (GUI.Button(temp, "", guiSkin.GetStyle("node_multiOutput")))
                {
                    curveIndex = i;
                    if (graphNode.parentGraph != null && input != null)
                    {
                        if(input.inputNode != null)
                        {

                            wantsConnection = true;
                            connectionNode = input.inputNode;
                            connectionOutput = input.inputNode.nodeOutputs[input.outputPos];
                        }
                    }
                }
            }
        }
    }
Esempio n. 39
0
 public Connection(NodeOutput nodeOutput, NodeInput nodeInput)
 {
     output = nodeOutput;
     input = nodeInput;
 }
Esempio n. 40
0
 /// <summary>
 /// Callback when the NodeOutput was assigned a new connection (the last in the list)
 /// </summary>
 protected internal virtual void OnAddOutputConnection(NodeOutput output)
 {
 }
Esempio n. 41
0
    /// <summary>
    /// Processes input events
    /// </summary>
    private void InputEvents()
    {
        Event e = Event.current;
        mousePos = e.mousePosition;

        Node clickedNode = null;
        if (e.type == EventType.MouseDown || e.type == EventType.MouseUp)
            clickedNode = NodeAtPosition (e.mousePosition);

        if (e.type == EventType.Repaint)
        { // Draw background when repainting
            Vector2 offset = new Vector2 (nodeCanvas.scrollOffset.x%Background.width - Background.width,
                                          nodeCanvas.scrollOffset.y%Background.height - Background.height);
            int tileX = Mathf.CeilToInt ((position.width + (Background.width - offset.x)) / Background.width);
            int tileY = Mathf.CeilToInt ((position.height + (Background.height - offset.y)) / Background.height);

            for (int x = 0; x < tileX; x++)
            {
                for (int y = 0; y < tileY; y++)
                {
                    Rect texRect = new Rect (offset.x + x*Background.width,
                                             offset.y + y*Background.height,
                                             Background.width, Background.height);
                    GUI.DrawTexture (texRect, Background);
                }
            }
        }

        if (e.type == EventType.MouseDown)
        {
            activeNode = clickedNode;
            connectOutput = null;

            if (clickedNode != null)
            { // A click on a node
                if (e.button == 1)
                { // Right click -> Node Context Click
                    GenericMenu menu = new GenericMenu ();

                    menu.AddItem (new GUIContent ("Delete Node"), false, ContextCallback, "deleteNode");

                    menu.ShowAsContext ();
                    e.Use();
                }
                else if (e.button == 0)
                {
                    /* // Handled by Unity. For new Windowing System
                    // Left click -> check for drag on the header and for transition edits, else let it pass for gui elements
                    if (new Rect (clickedNode.rect.x, clickedNode.rect.y, clickedNode.rect.width, 40).Contains (mousePos))
                    { // We clicked the header, so we'll drag the node
                        dragNode = true;
                        e.delta = new Vector2 (0, 0);
                    }*/

                    // If a Connection was left clicked, try edit it's transition
                    NodeOutput nodeOutput = clickedNode.GetOutputAtPos (mousePos);
                    if (nodeOutput != null)
                    { // Output Node -> New Connection drawn from this
                        connectOutput = nodeOutput;
                        e.Use();
                    }
                    else
                    { // no output clicked, check input
                        NodeInput nodeInput = clickedNode.GetInputAtPos (mousePos);
                        if (nodeInput != null && nodeInput.connection != null)
                        { // Input node -> Loose and edit Connection
                            connectOutput = nodeInput.connection;
                            nodeInput.connection.connections.Remove (nodeInput);
                            nodeInput.connection = null;
                            e.Use();
                        } // Nothing interesting for us in the node clicked, so let the event pass to gui elements
                    }
                }
            }
            else if (!sideWindowRect.Contains (mousePos))
            { // A click on the empty canvas
                if (e.button == 2 || e.button == 0)
                { // Left/Middle Click -> Start scrolling
                    scrollWindow = true;
                    e.delta = new Vector2 (0, 0);
                }
                else if (e.button == 1)
                { // Right click -> Editor Context Click
                    GenericMenu menu = new GenericMenu ();
                    menu.AddItem(new GUIContent("오브젝트 추가"), false, ContextCallback, "objectNode");
                    menu.AddItem(new GUIContent("아이템 추가"), false, ContextCallback, "itemNode");
                    menu.AddItem(new GUIContent("조건 추가"), false, ContextCallback, "conditionNode");
                    menu.AddSeparator("");

                    menu.ShowAsContext ();
                    e.Use();
                }
            }
        }
        else if (e.type == EventType.MouseUp)
        {
            if (connectOutput != null)
            { // Apply a connection if theres a clicked input
                if (clickedNode != null )//&& !clickedNode.Outputs.Contains (connectOutput))
                {	// If an input was clicked, it'll will now be connected
                    NodeInput clickedInput = clickedNode.GetInputAtPos (mousePos);
                    if (Node.CanApplyConnection (connectOutput, clickedInput))
                    { // If it can connect (type is equals, it does not cause recursion, ...)
                        Node.ApplyConnection (connectOutput, clickedInput);
                    }
                }
                e.Use();
            }
            else if (e.button == 2 || e.button == 0)
            { // Left/Middle click up -> Stop scrolling
                scrollWindow = false;
            }
            connectOutput = null;
        }
        else if (e.type == EventType.KeyDown)
        {
            if (e.keyCode == KeyCode.N) // Start Navigating (curve to origin)
                navigate = true;
        }
        else if (e.type == EventType.KeyUp)
        {
            if (e.keyCode == KeyCode.N) // Stop Navigating
                navigate = false;
        }
        else if (e.type == EventType.Repaint)
        {
            if (navigate)
            { // Draw a curve to the origin/active node for orientation purposes
                DrawNodeCurve (nodeCanvas.scrollOffset, (activeNode != null? activeNode.rect.center : e.mousePosition));
                Repaint ();
            }
            if (connectOutput != null)
            { // Draw the currently drawn connection
                DrawNodeCurve (connectOutput.GetKnob ().center, e.mousePosition);
                Repaint ();
            }
        }
        if (scrollWindow)
        { // Scroll everything with the current mouse delta
            nodeCanvas.scrollOffset += e.delta / 2;
            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
                nodeCanvas.nodes [nodeCnt].rect.position += e.delta / 2;
            Repaint ();
        }
        /* // Handled by Unity. For new Windowing System
        if (dragNode)
        { // Drag the active node with the current mouse delt
            activeNode.rect.position += e.delta / 2;
            Repaint ();
        }*/
    }
Esempio n. 42
0
    /// <summary>
    /// Processes input events
    /// </summary>
    private void InputEvents()
    {
        Event e = Event.current;
        mousePos = e.mousePosition;

        Node clickedNode = null;
        if (e.type == EventType.MouseDown || e.type == EventType.MouseUp)
        {
            clickedNode = NodeAtPosition (e.mousePosition);
        }

        switch (e.type)
        {
        case EventType.MouseDown:

            if (e.button == 0)
            {
                // Only update the active node when clicking on the canvas
                if (canvasWindowRect.Contains(e.mousePosition))
                    activeNode = clickedNode;
            }

            connectOutput = null;
            dragNode = false;
            panWindow = false;

            if (clickedNode != null)
            { // A click on a node
                if (e.button == 1)
                { // Right click -> Node Context Click
                    GenericMenu menu = new GenericMenu ();

                    menu.AddItem (new GUIContent ("Delete Node"), false, ContextCallback, "deleteNode");
                    menu.AddItem (new GUIContent ("Duplicate Node"), false, ContextCallback, "duplicateNode");

                    menu.ShowAsContext ();
                    e.Use();
                }
                else if (e.button == 0)
                {
                    if (!clickedNode.screenRect.Contains (mousePos))
                    { // Left click at node edges -> Check for clicked connections to edit
                        NodeOutput nodeOutput = clickedNode.GetOutputAtPos (mousePos);
                        if (nodeOutput != null)
                        { // Output Node -> New Connection drawn from this
                            connectOutput = nodeOutput;
                            e.Use();
                        }
                        else
                        { // no output clicked, check input
                            NodeInput nodeInput = clickedNode.GetInputAtPos (mousePos);
                            if (nodeInput != null && nodeInput.connection != null)
                            { // Input node -> Loose and edit Connection
                                connectOutput = nodeInput.connection;
                                nodeInput.connection.connections.Remove (nodeInput);
                                nodeInput.connection = null;
                                //  RecalculateFrom (clickedNode);
                                e.Use();
                            }
                        }
                    }
                }
            }
            else if (canvasWindowRect.Contains (mousePos))
            { // A click on the empty canvas
                if (e.button == 2 || e.button == 0)
                { // Left/Middle Click -> Start scrolling
                    panWindow = true;
                    e.delta = Vector2.zero;
                }
                else if (e.button == 1)
                { // Right click -> Editor Context Click
                    GenericMenu menu = new GenericMenu ();

                    //  menu.AddItem (new GUIContent ("Add Input Node"), false, ContextCallback, InputNode.ID);
                    //  menu.AddItem (new GUIContent ("Add Display Node"), false, ContextCallback, DisplayNode.ID);
                    //  menu.AddItem (new GUIContent ("Add Calculation Node"), false, ContextCallback, CalcNode.ID);
                    //  menu.AddSeparator ("");

                    foreach (var type in ReflectiveEnumerator.GetEnumerableOfType<Node>())
                    {
                        menu.AddItem(new GUIContent(type.ToString()), false, CreateNodeCallback, type.Name);
                    }

                    //menu.AddItem(new GUIContent("Add Example Node"), false, ContextCallback, "exampleNode");

                    menu.ShowAsContext ();
                    e.Use();
                }
            }

            break;

        case EventType.MouseUp:

            if (connectOutput != null)
            { // Apply a connection if theres a clicked input
                if (clickedNode != null && !clickedNode.Outputs.Contains (connectOutput))
                { // If an input was clicked, it'll will now be connected
                    NodeInput clickedInput = clickedNode.GetInputAtPos (mousePos);
                    if (Node.CanApplyConnection (connectOutput, clickedInput))
                    { // If it can connect (type is equals, it does not cause recursion, ...)
                        Node.ApplyConnection (connectOutput, clickedInput);
                    }
                }
                e.Use();
            }

            connectOutput = null;
            dragNode = false;
            panWindow = false;

            break;

        case EventType.ScrollWheel:

            nodeCanvas.zoom = Mathf.Min (2.0f, Mathf.Max (0.6f, nodeCanvas.zoom + e.delta.y / 15));
            Repaint ();

            break;

        case EventType.KeyDown:

            // TODO: Node Editor: Shortcuts
            if (e.keyCode == KeyCode.N) // Start Navigating (curve to origin / active Node)
                navigate = true;

            if (e.keyCode == KeyCode.LeftControl && activeNode != null) // Snap
                activeNode.rect.position = new Vector2 (Mathf.RoundToInt ((activeNode.rect.position.x - nodeCanvas.panOffset.x) / 10) * 10 + nodeCanvas.panOffset.x,
                                                        Mathf.RoundToInt ((activeNode.rect.position.y - nodeCanvas.panOffset.y) / 10) * 10 + nodeCanvas.panOffset.y);

            Repaint ();

            break;

        case EventType.KeyUp:

            if (e.keyCode == KeyCode.N) // Stop Navigating
                navigate = false;

            Repaint ();

            break;

        }

        if (panWindow)
        { // Scroll everything with the current mouse delta
            nodeCanvas.panOffset += e.delta / 2 * nodeCanvas.zoom;
            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
                nodeCanvas.nodes [nodeCnt].rect.position += e.delta / 2 * nodeCanvas.zoom;
            Repaint ();
        }

        if (dragNode && activeNode != null && GUIUtility.hotControl == 0)
        { // Drag the active node with the current mouse delta
            activeNode.rect.position += e.delta / 2 * nodeCanvas.zoom;
            Repaint ();
        }
    }
Esempio n. 43
0
    private void DrawSelectFunction(NodeOutput outPut, NodeInput inPut)
    {
        var functions = selects[outPut].functions;
        var target = functions[inPut];
        if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
            return;
        inPut.DisplayLayout();
        if (isExpanded)
        {
            if (target is SpriteChanger)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[0]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                SpriteChanger changer = (SpriteChanger)target;
                GUILayout.BeginHorizontal();
                GUILayout.Label("기본 스프라이트");
                changer.baseSprite = EditorGUILayout.ObjectField (changer.baseSprite, typeof(Sprite), true) as Sprite;
                GUILayout.Label("선택 스프라이트");
                changer.selectedSprite = EditorGUILayout.ObjectField (changer.selectedSprite, typeof(Sprite), true) as Sprite;
                GUILayout.EndHorizontal();
            }
            else if (target is Enabler)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[1]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                Enabler enabler = (Enabler)target;
                enabler.option = (EnableOption)EditorGUILayout.EnumPopup("옵션", enabler.option);
            }
            else if (target is SoundPlayer)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[2]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                SoundPlayer player = (SoundPlayer)target;
                player.sound = EditorGUILayout.ObjectField("효과음", player.sound, typeof(AudioClip), true) as AudioClip;
            }
            else if (target is MessageDisplayer)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[3]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                GUILayout.BeginHorizontal();
                MessageDisplayer displayer = (MessageDisplayer)target;
                displayer.inputMessage = EditorGUILayout.TextArea(displayer.inputMessage);
                GUILayout.EndHorizontal();
            }
            else if (target is ItemGainer)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[4]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

            }
            else if (target is DangerChanger)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[5]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                DangerChanger dChanger = (DangerChanger)target;
                dChanger.newDanger = EditorGUILayout.IntField("새 위험도", dChanger.newDanger);
            }
            else if (target is SpriteShower)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[6]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target,true);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                SpriteShower shower = (SpriteShower)target;
                for (int i=0; i<shower.sprites.Count; i++)
                {
                    shower.sprites[i] = EditorGUILayout.ObjectField(shower.sprites[i], typeof(Sprite), true) as Sprite;
                }
                Sprite newSprite = null;
                newSprite = EditorGUILayout.ObjectField(newSprite, typeof(Sprite), true) as Sprite;
                if(newSprite != null)
                {
                    shower.sprites.Add(newSprite);
                }
            }
            else if (target is EventMaker)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectOptions[7]);
                if(GUILayout.Button("기능 삭제"))
                {
                    if (!selects.ContainsKey(outPut) || !functions.ContainsKey(inPut))
                        return;
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    functions.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                    Vector2 topLeft = rect.position;
                    rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                    DrawConnectors();
                    return;
                }
                GUILayout.EndHorizontal();
                target.delay = EditorGUILayout.FloatField("발동 딜레이(초)", target.delay);

                GUILayout.BeginHorizontal();
                EventMaker eventMaker = (EventMaker)target;
                eventMaker.eventFlag = EditorGUILayout.TextField("이벤트명", eventMaker.eventFlag);
                GUILayout.EndHorizontal();
            }
            GUILayout.Space(10);
        }
    }
Esempio n. 44
0
    private void DrawSelect(NodeOutput outPut)
    {
        if (outPut == null || !selects.ContainsKey(outPut))
            return;
        outPut.DisplayLayout();
        SelectManager selectManager = selects[outPut].selectManager;
        var functions = selects[outPut].functions;
        if (isExpanded)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("이름");
            if (selects.ContainsKey(outPut))
                selects[outPut].selectManager.gameObject.name = EditorGUILayout.TextField(selects[outPut].selectManager.gameObject.name);
            string buttonName = (nodeType == NodeType.Route) ? "조건 실행 삭제" : "선택지 삭제";
            if(GUILayout.Button(buttonName))
            {
                if (!selects.ContainsKey(outPut))
                    return;
                List<NodeInput> keyInputList = new List<NodeInput>(selects[outPut].functions.Keys);
                foreach (var inPut in keyInputList)
                {
                    var functions1 = selects[outPut].functions;
                    var target = functions1[inPut];
                    DestroyImmediate((MonoBehaviour)functions[inPut]);
                    DestroyImmediate(target, true);
                    functions1.Remove(inPut);
                    try
                    {
                        inPut.connection.connections.Remove(inPut);
                    }
                    catch (NullReferenceException e)
                    {

                    }
                    Inputs.Remove(inPut);
                }
                DestroyImmediate(selects[outPut], true);
                DestroyImmediate(selects[outPut].selectManager.gameObject);
                selects.Remove(outPut);
                //  Outputs.Remove(outPut);
                Vector2 topLeft = rect.position;
                rect = new Rect (topLeft.x, topLeft.y, 200, 100);
                foreach (NodeInput inPut in outPut.connections)
                {
                    inPut.connection = null;
                }
                Outputs.Remove(outPut);
                DrawConnectors();
                return;
            }
            GUILayout.EndHorizontal();
            selectManager.isActive = EditorGUILayout.Toggle("활성화", selectManager.isActive);
            selectManager.isOnce = EditorGUILayout.Toggle("일회용", selects[outPut].selectManager.isOnce);
            selectManager.requireTime = EditorGUILayout.FloatField("소요시간", selectManager.requireTime);
            //  selects[outPut].selectManager.dangers.isActive = EditorGUILayout.Toggle("위험 활성화", selects[outPut].selectManager.dangers.isActive);
            selectManager.dangers.dangerCount = EditorGUILayout.IntField("위험도", selectManager.dangers.dangerCount);
            GUILayout.BeginHorizontal();
            selectOptionIndex = EditorGUILayout.Popup("종류", selectOptionIndex, selectOptions);
            if(GUILayout.Button("기능 추가"))
            {
                NodeInput key;
                Function executor = null;
                if (!selects.ContainsKey(outPut))
                    return;
                switch (selectOptionIndex)
                {
                    case 0:
                        executor = selectManager.gameObject.AddComponent<SpriteChanger>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.ObjectOnly);
                        break;
                    case 1:
                        executor = selectManager.gameObject.AddComponent<Enabler>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.General);
                        break;
                    case 2:
                        executor = selectManager.gameObject.AddComponent<SoundPlayer>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.Closed);
                        break;
                    case 3:
                        executor = selectManager.gameObject.AddComponent<MessageDisplayer>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.Closed);
                        break;
                    case 4:
                        executor = selectManager.gameObject.AddComponent<ItemGainer>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.ItemOnly);
                        break;
                    case 5:
                        executor = selectManager.gameObject.AddComponent<DangerChanger>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.SelectionOnly);
                        break;
                    case 6:
                        executor = selectManager.gameObject.AddComponent<SpriteShower>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.Closed);
                        break;
                    case 7:
                        executor = selectManager.gameObject.AddComponent<EventMaker>();
                        key = NodeInput.Create(this, "기능 출력", IOtype.Closed);
                        break;
                    default:
                        executor = null;
                        key = null;
                        break;
                }
                functions.Add(key, executor);
                DrawNode();
            }
            GUILayout.EndHorizontal();
        }

        List<NodeInput> keyList = new List<NodeInput>(functions.Keys);
        foreach (var item in keyList)
        {
            DrawSelectFunction(outPut, item);
        }

        DrawConnectors();
        if (isExpanded)
            GUILayout.Space(20);
    }
Esempio n. 45
0
 public FloatNode()
 {
     output = new NodeOutput();
     nodeOutputs.Add(output);
 }
Esempio n. 46
0
 public callbackObject(string Message, NodeCanvas nodecanvas, NodeEditorState editorState, Node Node, NodeOutput NodeOutput)
 {
     message = Message;
     canvas = nodecanvas;
     editor = editorState;
     node = Node;
     nodeOutput = NodeOutput;
 }
Esempio n. 47
0
 public void DeselectAllNodes()
 {
     nodes.ForEach(node => node.isSelected = false);
     nodes.ForEach(node => node.timePointer.isSelected = false);
     nodes.ForEach(node => node.timePointer.isMoveable = false);
     selectedNodes.Clear();
     showProperties = false;
     wantsConnection = false;
     connectionNode = null;
     connectionOutputList = null;
     connectionOutput = null;
     curveIndex = -1;
 }
Esempio n. 48
0
 public callbackObject(string Message, NodeCanvas nodecanvas, NodeEditorState editorState)
 {
     message = Message;
     canvas = nodecanvas;
     editor = editorState;
     node = null;
     nodeOutput = null;
 }
Esempio n. 49
0
 public void Send(object obj, NodeOutput output)
 {
     output.value = obj;
     output.Notify();
 }
Esempio n. 50
0
 public override sealed void AddOutput(NodeOutput output)
 {
 }
Esempio n. 51
0
		/// <summary>
		/// Applies a connection between output and input. 'CanApplyConnection' has to be checked before
		/// </summary>
		public static void ApplyConnection (NodeOutput output, NodeInput input)
		{
			if (input != null && output != null) 
			{
				if (input.Connection != null)
					input.Connection.Connections.Remove (input);
				input.Connection = output;
				output.Connections.Add (input);

				NodeEditor.RecalculateFrom (input.Body);
				output.Body.OnAddOutputConnection (output);
				input.Body.OnAddInputConnection (input);
				NodeEditorCallbacks.IssueOnAddConnection (input);
			}
		}