private void SaveNewNodeKnob(NodeKnob knob)
        {
            if (!useCache)
            {
                return;
            }
            if (nodeCanvas.livesInScene)
            {
                DeleteCache();
                return;
            }
            if (!nodeCanvas.nodes.Contains(knob.body))
            {
                return;
            }

            CheckCurrentCache();

            NodeEditorSaveManager.AddSubAsset(knob, knob.body);
            foreach (ScriptableObject so in knob.GetScriptableObjects())
            {
                NodeEditorSaveManager.AddSubAsset(so, knob);
            }

            UpdateCacheFile();
        }
 public static void IssueOnAddNodeKnob(NodeKnob nodeKnob)
 {
     if (OnAddNodeKnob != null)
     {
         OnAddNodeKnob.Invoke(nodeKnob);
     }
     for (int cnt = 0; cnt < receiverCount; cnt++)
     {
         if (callbackReceiver[cnt] == null)
         {
             callbackReceiver.RemoveAt(cnt--);
         }
         else
         {
             callbackReceiver[cnt].OnAddNodeKnob(nodeKnob);
         }
     }
 }
 public static void Uncompress(ref NodeCanvas nodeCanvas)
 {
     for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
     {
         Node node = nodeCanvas.nodes[nodeCnt];
         node.Inputs  = new List <NodeInput>();
         node.Outputs = new List <NodeOutput>();
         for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
         {
             NodeKnob knob = node.nodeKnobs[knobCnt];
             if (knob is NodeInput)
             {
                 node.Inputs.Add(knob as NodeInput);
             }
             else if (knob is NodeOutput)
             {
                 node.Outputs.Add(knob as NodeOutput);
             }
         }
     }
 }
Esempio n. 4
0
        public void Validate()
        {
            if (nodes == null)
            {
                nodes = new List <Node>();
            }
            for (int nodeCnt = 0; nodeCnt < nodes.Count; nodeCnt++)
            {
                Node node = nodes[nodeCnt];
                if (node == null)
                {
                    nodes.RemoveAt(nodeCnt);
                    nodeCnt--;
                    continue;
                }
                for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
                {
                    NodeKnob nodeKnob = node.nodeKnobs[knobCnt];
                    if (nodeKnob == null)
                    {
                        node.nodeKnobs.RemoveAt(knobCnt);
                        knobCnt--;
                        continue;
                    }

                    if (nodeKnob is NodeInput)
                    {
                        NodeInput input = nodeKnob as NodeInput;
                        if (input.connection != null && input.connection.body == null)
                        {
                            input.connection = null;
                        }
                    }
                    else if (nodeKnob is NodeOutput)
                    {
                        NodeOutput output = nodeKnob as NodeOutput;
                        for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
                        {
                            NodeInput con = output.connections[conCnt];
                            if (con == null || con.body == null)
                            {
                                output.connections.RemoveAt(conCnt);
                                conCnt--;
                            }
                        }
                    }
                }
            }

            if (editorStates == null)
            {
                editorStates = new NodeEditorState[0];
            }
            editorStates = editorStates.Where((NodeEditorState state) => state != null).ToArray();
            foreach (NodeEditorState state in editorStates)
            {
                if (!nodes.Contains(state.selectedNode))
                {
                    state.selectedNode = null;
                }
            }
        }
        public static NodeCanvas CreateWorkingCopy(NodeCanvas nodeCanvas, bool editorStates)
        {
            nodeCanvas.Validate();
            nodeCanvas = Clone(nodeCanvas);


            List <ScriptableObject> allSOs    = new List <ScriptableObject>();
            List <ScriptableObject> clonedSOs = new List <ScriptableObject>();

            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = nodeCanvas.nodes[nodeCnt];
                node.CheckNodeKnobMigration();


                Node clonedNode = AddClonedSO(allSOs, clonedSOs, node);
                AddClonedSOs(allSOs, clonedSOs, clonedNode.GetScriptableObjects());

                foreach (NodeKnob knob in clonedNode.nodeKnobs)
                {
                    AddClonedSO(allSOs, clonedSOs, knob);
                    AddClonedSOs(allSOs, clonedSOs, knob.GetScriptableObjects());
                }
            }


            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = nodeCanvas.nodes[nodeCnt];

                Node clonedNode = nodeCanvas.nodes[nodeCnt] = ReplaceSO(allSOs, clonedSOs, node);
                clonedNode.CopyScriptableObjects((ScriptableObject so) => ReplaceSO(allSOs, clonedSOs, so));


                clonedNode.Inputs  = new List <NodeInput>();
                clonedNode.Outputs = new List <NodeOutput>();
                for (int knobCnt = 0; knobCnt < clonedNode.nodeKnobs.Count; knobCnt++)
                {
                    NodeKnob knob = clonedNode.nodeKnobs[knobCnt] = ReplaceSO(allSOs, clonedSOs, clonedNode.nodeKnobs[knobCnt]);
                    knob.body = clonedNode;

                    knob.CopyScriptableObjects((ScriptableObject so) => ReplaceSO(allSOs, clonedSOs, so));

                    if (knob is NodeInput)
                    {
                        clonedNode.Inputs.Add(knob as NodeInput);
                    }
                    else if (knob is NodeOutput)
                    {
                        clonedNode.Outputs.Add(knob as NodeOutput);
                    }
                }
            }

            if (editorStates)
            {
                nodeCanvas.editorStates = CreateWorkingCopy(nodeCanvas.editorStates, nodeCanvas);
                foreach (NodeEditorState state in nodeCanvas.editorStates)
                {
                    state.selectedNode = ReplaceSO(allSOs, clonedSOs, state.selectedNode);
                }
            }
            else
            {
                foreach (NodeEditorState state in nodeCanvas.editorStates)
                {
                    state.selectedNode = null;
                }
            }

            return(nodeCanvas);
        }
 public virtual void OnAddNodeKnob(NodeKnob knob)
 {
 }
Esempio n. 7
0
        public static Node NodeAtPosition(NodeEditorState editorState, Vector2 canvasPos, out NodeKnob focusedKnob)
        {
            focusedKnob = null;
            if (NodeEditorInputSystem.shouldIgnoreInput(editorState))
            {
                return(null);
            }
            NodeCanvas canvas = editorState.canvas;

            for (int nodeCnt = canvas.nodes.Count - 1; nodeCnt >= 0; nodeCnt--)
            {
                Node node = canvas.nodes[nodeCnt];
                if (node.rect.Contains(canvasPos))
                {
                    return(node);
                }
                for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
                {
                    if (node.nodeKnobs[knobCnt].GetCanvasSpaceKnob().Contains(canvasPos))
                    {
                        focusedKnob = node.nodeKnobs[knobCnt];
                        return(node);
                    }
                }
            }
            return(null);
        }
Esempio n. 8
0
 public static Node NodeAtPosition(Vector2 canvasPos, out NodeKnob focusedKnob)
 {
     return(NodeAtPosition(curEditorState, canvasPos, out focusedKnob));
 }