public void LoadNodeCanvas(string path) { nodeGroupCanvas = NodeEditorSaveManager.LoadNodeCanvas(path); if (nodeGroupCanvas != null) { List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path); editorState = editorStates.Count == 0? CreateInstance <NodeEditorState> () : editorStates[0]; editorState.canvas = nodeGroupCanvas; editorState.parentEditor = NodeEditor.curEditorState; editorState.drawing = edit; editorState.name = "GroupNode_EditorState"; string[] folders = path.Split(new char[] { '/' }, StringSplitOptions.None); string canvasName = folders [folders.Length - 1]; if (canvasName.EndsWith(".asset")) { canvasName = canvasName.Remove(canvasName.Length - 6); } name = canvasName; } else { name = "Node Group"; } }
/// <summary> /// Loads the canvas from the cache save file /// Called whenever a reload was made /// </summary> private void LoadCache() { // Try to load the NodeCanvas if (!File.Exists(lastSessionPath) || (mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(lastSessionPath, false)) == null) { NewNodeCanvas(); return; } // Fetch the associated MainEditorState if (mainNodeCanvas.editorStates.Length > 0) { mainEditorState = mainNodeCanvas.editorStates.Length == 1? mainNodeCanvas.editorStates[0] : mainNodeCanvas.editorStates.First((NodeEditorState state) => state.name == "MainEditorState"); } if (mainEditorState == null) { NewEditorState(); NodeEditorSaveManager.AddSubAsset(mainEditorState, lastSessionPath); } CheckCurrentCache(); NodeEditor.RecalculateAll(mainNodeCanvas); Repaint(); }
public void LoadNodeCanvas(string path) { // Else it will be stuck forever NodeEditor.StopTransitioning(canvas); // Load the NodeCanvas canvas = NodeEditorSaveManager.LoadNodeCanvas(path); if (canvas == null) { NewNodeCanvas(); return; } // Load the associated MainEditorState List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path); if (editorStates.Count == 0) { state = ScriptableObject.CreateInstance <NodeEditorState> (); } else { state = editorStates.Find(x => x.name == "MainEditorState"); if (state == null) { state = editorStates[0]; } } state.canvas = canvas; NodeEditor.RecalculateAll(canvas); }
private void LoadCache() { string lastSessionName = EditorPrefs.GetString("NodeEditorLastSession"); string path = tempSessionPath + "/LastSession.asset"; mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, false); if (mainNodeCanvas == null) { NewNodeCanvas(); } else { mainNodeCanvas.name = lastSessionName; List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path, false); if (editorStates == null || editorStates.Count == 0 || (mainEditorState = editorStates.Find(x => x.name == "MainEditorState")) == null) { // New NodeEditorState mainEditorState = CreateInstance <NodeEditorState> (); mainEditorState.canvas = mainNodeCanvas; mainEditorState.name = "MainEditorState"; NodeEditorSaveManager.AddSubAsset(mainEditorState, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } }
public void LoadNodeCanvas(string path) { if (!File.Exists(path) || (canvas = NodeEditorSaveManager.LoadNodeCanvas(path, true)) == null) { NewNodeCanvas(); return; } state = NodeEditorSaveManager.ExtractEditorState(canvas, "MainEditorState"); NodeEditor.RecalculateAll(canvas); }
public void LoadCanvas(string path) { canvasPath = path; if (!string.IsNullOrEmpty(canvasPath)) { canvas = NodeEditorSaveManager.LoadNodeCanvas(canvasPath, true); CalculateCanvas(); } else { canvas = null; } }
/// <summary> /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path /// </summary> public void LoadNodeCanvas(string path) { // Try to load the NodeCanvas if (!File.Exists(path) || (mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true)) == null) { NewNodeCanvas(); return; } mainEditorState = NodeEditorSaveManager.ExtractEditorState(mainNodeCanvas, "MainEditorState"); openedCanvasPath = path; SaveCache(); NodeEditor.RecalculateAll(mainNodeCanvas); Repaint(); }
void Start() { Animator animator = GetComponent <Animator>(); // Load NodeCanvas asset var path = "Assets/Plugins/Node_Editor/Resources/Saves/PlayableCanvas.asset"; var canvas = NodeEditorSaveManager.LoadNodeCanvas(path, false); // Set input/output values on runtime, otherwise all input/output have null foreach (Node n in canvas.nodes) { n.Calculate(); } // Find AnimationPlayableMixerNode AnimationPlayableBaseNode node = FindNode(canvas); playableInst = new AnimationPlayableInstance(animator, node); // Mixing animations. playableInst.Execute(); }
/// <summary> /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path /// </summary> public void LoadNodeCanvas(string path) { // Else it will be stuck forever NodeEditor.StopTransitioning(mainNodeCanvas); // Load the NodeCanvas mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true); if (mainNodeCanvas == null) { Debug.Log("Error loading NodeCanvas from '" + path + "'!"); NewNodeCanvas(); return; } // Load the associated MainEditorState List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path, true); if (editorStates.Count == 0) { mainEditorState = ScriptableObject.CreateInstance <NodeEditorState> (); Debug.LogError("The save file '" + path + "' did not contain an associated NodeEditorState!"); } else { mainEditorState = editorStates.Find(x => x.name == "MainEditorState"); if (mainEditorState == null) { mainEditorState = editorStates[0]; } } mainEditorState.canvas = mainNodeCanvas; openedCanvasPath = path; NodeEditor.RecalculateAll(mainNodeCanvas); SaveCache(); Repaint(); }
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); }