Example #1
0
            internal NodeCanvas AddNode(NodeCanvas nodecanvas)
            {
                if (this.runners.Count == 0)
                {
                    //init node runtime
                    ConnectionPortStyles.FetchConnectionPortStyles();
                    NodeTypes.FetchNodeTypes();
                    NodeCanvasManager.FetchCanvasTypes();
                    ConnectionPortManager.FetchNodeConnectionDeclarations();
                    ImportExportManager.FetchIOFormats();

                    // Setup Callback system
                    NodeEditorCallbacks.SetupReceivers();
                    NodeEditorCallbacks.IssueOnEditorStartUp();
                }

                if (nodecanvas == null)
                {
                    return(null);
                }

                NodeCanvas copycanvas = NodeEditorSaveManager.CreateWorkingCopy(nodecanvas, true);

                //push copy to runners
                runners.Add(copycanvas);

                Restart(copycanvas);
                return(copycanvas);
            }
        public void Start()
        {
            NodeEditor.checkInit(false);
            FPSCounter.Create();

            cache = new NodeEditorUserCache();
            if (canvas != null)
            {
                cache.SetCanvas(NodeEditorSaveManager.CreateWorkingCopy(canvas, true));
            }
        }
Example #3
0
 private void AssureSetup()
 {
     if (canvasCache == null)
     {             // Create cache and load startup-canvas
         canvasCache = new NodeEditorUserCache();
         canvasCache.SetCanvas(NodeEditorSaveManager.CreateWorkingCopy(canvas));
     }
     canvasCache.AssureCanvas();
     if (editorInterface == null)
     {             // Setup editor interface
         editorInterface             = NodeEditorInterface.GetInstance();
         editorInterface.canvasCache = canvasCache;
     }
 }
 private void AssureSetup()
 {
     if (canvasCache == null)
     {             // Create cache and load startup-canvas
         canvasCache = new NodeEditorUserCache();
         if (canvas != null)
         {
             canvasCache.SetCanvas(NodeEditorSaveManager.CreateWorkingCopy(canvas));
         }
         else if (!string.IsNullOrEmpty(loadSceneName))
         {
             canvasCache.LoadSceneNodeCanvas(loadSceneName);
         }
     }
     canvasCache.AssureCanvas();
     if (editorInterface == null)
     {             // Setup editor interface
         editorInterface             = new NodeEditorInterface();
         editorInterface.canvasCache = canvasCache;
     }
 }
Example #5
0
    bool FixupForSubCanvas()
    {
        if (!string.IsNullOrEmpty(m_CanvasGuid) && m_SubCanvas == null)
        {
            string NodeCanvasPath = AssetDatabase.GUIDToAssetPath(m_CanvasGuid);

            m_SubCanvas = NodeEditorSaveManager.LoadNodeCanvas(NodeCanvasPath, false);
            m_WasCloned = true;
        }

        if (m_SubCanvas != null)
        {
            if (!m_WasCloned)
            {
                NodeEditorSaveManager.CreateWorkingCopy(m_SubCanvas, false);//miked remove ref
                m_WasCloned = true;
            }

            List <NodeInput>          needsInput  = new List <NodeInput>();
            List <UnityTextureOutput> needsOutput = new List <UnityTextureOutput>();
            foreach (Node n in m_SubCanvas.nodes)
            {
                if (n.Inputs.Count > 0)
                {
                    if (n is UnityTextureOutput && n.Inputs[0].connection != null)
                    {
                        needsOutput.Add(n as UnityTextureOutput);
                    }
                    for (int i = 0; i < n.Inputs.Count; i++)
                    {
                        if (n.Inputs[i].connection == null)
                        {
                            //this node has no input so we will wire it up to ours
                            needsInput.Add(n.Inputs[i]);
                            //                            Debug.Log(" missing input for node "+n+" name "+n.name);
                        }
                    }
                }
            }
            if (needsOutput.Count > Outputs.Count)
            {
                while (needsOutput.Count > Outputs.Count)
                {
                    //                    Debug.Log(" create input "+Inputs.Count);
                    CreateOutput("Texture" + Outputs.Count + " " + needsOutput[needsOutput.Count - 1].m_TexName, needsOutput[needsOutput.Count - 1].Inputs[0].connection.typeID, NodeSide.Right, 50 + Outputs.Count * 20);
                }
            }
            if (needsOutput.Count > 0)
            {
                Outputs[0].name = "Texture0" + " " + needsOutput[0].m_TexName;
            }

            if (needsInput.Count > Inputs.Count)
            {
                //  while (needsInput.Count > Inputs.Count)
                int startInputCount = Inputs.Count;
//                for(int index= needsInput.Count-1;index>= startInputCount; index--)
                for (int index = Inputs.Count; index < needsInput.Count; index++)
                {
                    string name = needsInput[index].name;
                    //                    Debug.Log(" create input "+Inputs.Count);
                    CreateInput(name, needsInput[index].typeID, NodeSide.Left, 30 + Inputs.Count * 20);
                }

                return(false);
            }
        }
        return(true);
    }
        bool FixupForSubCanvas()
        {
            if (!string.IsNullOrEmpty(m_CanvasGuid) && m_SubCanvas == null)
            {
                string nodeCanvasPath = AssetDatabase.GUIDToAssetPath(m_CanvasGuid);

                m_SubCanvas = NodeEditorSaveManager.LoadNodeCanvas(nodeCanvasPath, false);
                m_WasCloned = false;
            }

            if (m_SubCanvas != null)
            {
                if (!m_WasCloned)
                {
                    m_SubCanvas = NodeEditorSaveManager.CreateWorkingCopy(m_SubCanvas, false); //miked remove ref
                    m_WasCloned = true;

/* test its making unique nodes
 *                  foreach (Node n in m_SubCanvas.nodes)
 *                  {
 *                      if (n is TextureNode)
 *                      {
 *                          var tnIn = n as TextureNode;
 *                          var was = tnIn.m_TexHeight;
 *                          tnIn.m_TexHeight = Random.Range(1000, 1500);
 *                          Debug.Log("Change sub routines node" + tnIn + "  tex height to  " + tnIn.m_TexHeight + " was " + was);
 *
 *                      }
 *                  }
 */
                }

                List <NodeInput>   needsInput  = new List <NodeInput>();
                List <TextureNode> needsOutput = new List <TextureNode>();
                foreach (Node n in m_SubCanvas.nodes)
                {
                    if (n.Inputs.Count > 0)
                    {
                        if (n is UnityTextureOutput && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        if (n is UnityTextureOutputMetalicAndRoughness && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        for (int i = 0; i < n.Inputs.Count; i++)
                        {
                            if (n.Inputs[i].connection == null)
                            {
                                //this node has no input so we will wire it up to ours
                                needsInput.Add(n.Inputs[i]);
                                //                            Debug.Log(" missing input for node "+n+" name "+n.name);
                            }
                        }
                    }
                }
                if (needsOutput.Count > Outputs.Count)
                {
                    while (needsOutput.Count > Outputs.Count)
                    {
                        //                    Debug.Log(" create input "+Inputs.Count);

                        string nname = GetNodeOutputName(needsOutput[Outputs.Count]);

                        CreateOutput("Texture" + Outputs.Count + " " + nname, needsOutput[Outputs.Count].Inputs[0].connection.typeID, NodeSide.Right, 50 + Outputs.Count * 20);
                    }
                }
                if (needsOutput.Count > 0)
                {
                    Outputs[0].name = "Texture0" + " " + GetNodeOutputName(needsOutput[0]);
                }

                if (needsInput.Count > Inputs.Count)
                {
                    int added = 0;



                    for (int index = Inputs.Count; index < needsInput.Count; index++)
                    {
                        string needInputname = needsInput[index].name;
                        //                    Debug.Log(" create input "+Inputs.Count);
                        NodeInput newInput = CreateInput(needInputname, needsInput[index].typeID, NodeSide.Left, 30 + Inputs.Count * 20);
                        if (newInput.typeID == "Float")
                        {
                            var n = Node.Create("inputNode", rect.position - new Vector2(100, 50 - added * 60));
                            added++;
                            InputNode inode = n as InputNode;
                            if (inode != null)
                            {
                                newInput.ApplyConnection(inode.Outputs[0], false);
                                InputNode ip = (InputNode)n;
                                Node      nodeThatNeedsInput = needsInput[index].body;
                                //Use reflection to find the float remap member var that matches the input
                                FieldInfo[] myField = nodeThatNeedsInput.GetType().GetFields();
                                foreach (var x in myField)
                                {
                                    // if(x.FieldType is FloatRemap)
                                    if (x.GetValue(nodeThatNeedsInput) is FloatRemap)
                                    {
                                        FloatRemap fr = (FloatRemap)x.GetValue(nodeThatNeedsInput); //its a struct this makes a copy
                                        //                Debug.Log(x + " " + x.FieldType + " " + x.GetType() + " " + x.ReflectedType+" fr val:"+fr.m_Value);
                                        if (fr.m_ReplaceWithInput && fr.m_Replacement == null)
                                        {
                                            Debug.LogError(" wants to be replaced but isnt linked ");
                                        }
                                        else if (fr.m_Replacement != null)
                                        {
                                            NodeKnob  knob    = fr.m_Replacement;
                                            NodeInput replace = knob as NodeInput;
                                            if (replace != null)
                                            {
                                                if (replace == needsInput[index])
                                                {
                                                    ip.m_Value.Set(fr.m_Value);
                                                    ip.m_Value.m_Min = fr.m_Min;
                                                    ip.m_Value.m_Max = fr.m_Max;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    m_InputsCreated = true;
                    //CreateNewFloatInputs();
                    return(false);
                }
            }
            return(true);
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            BehaviourTreeAgent agent = target as BehaviourTreeAgent;

            if (agent.tree == null)
            {
                return;
            }
            if (NodeEditor.curNodeCanvas == null || NodeEditor.curNodeCanvas.savePath != agent.tree.savePath)
            {
                BehaviourTree.selectedAgent = agent;
                NodeEditor.ReInit(false);
                NodeCanvas c = NodeEditorSaveManager.CreateWorkingCopy(agent.tree);
                NodeEditor.curNodeCanvas = c;
                NodeEditorWindow.editor.canvasCache.SetCanvas(c);
            }
            if (agent.gameObjectParameters != null)
            {
                objectFold = EditorGUILayout.Foldout(objectFold, "Game Objects");
                if (objectFold)
                {
                    List <string> keys = new List <string>(agent.gameObjectParameters.Keys);
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.gameObjectParameters[key] = EditorGUILayout.ObjectField(agent.gameObjectParameters[key], typeof(GameObject), true) as GameObject;
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.floatParameters != null)
            {
                floatFold = EditorGUILayout.Foldout(floatFold, "Floats");
                List <string> keys = new List <string>(agent.floatParameters.Keys);
                if (floatFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.floatParameters[key] = EditorGUILayout.FloatField(agent.floatParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.integerParameters != null)
            {
                integerFold = EditorGUILayout.Foldout(integerFold, "Integers");
                List <string> keys = new List <string>(agent.integerParameters.Keys);
                if (integerFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.integerParameters[key] = EditorGUILayout.IntField(agent.integerParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            if (agent.boolParameters != null)
            {
                boolFold = EditorGUILayout.Foldout(boolFold, "Booleans");
                List <string> keys = new List <string>(agent.boolParameters.Keys);
                if (boolFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.boolParameters[key] = EditorGUILayout.Toggle(agent.boolParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.vector3Parameters != null)
            {
                vectorFold = EditorGUILayout.Foldout(vectorFold, "Vectors");
                List <string> keys = new List <string>(agent.vector3Parameters.Keys);
                if (vectorFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        agent.vector3Parameters[key] = EditorGUILayout.Vector3Field(key, agent.vector3Parameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }