Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Added ability to save to scene, completely reworked save system
Browse files Browse the repository at this point in the history
Additions:
- Added saving canvases to scene which allows for runtime saving (but data is lost after each session) and referencing scene objects safely

Changes:
- Changed API for saving, now alot cleaner
- Changed internals of saving, nor alot more stable

Fixes:
- Fixed loading in playmode will throw an error because of path type mismatch
- Fixed potential errors in GUIScaleUtility
- Fixed all saving, playmode change and scene change related errors

Notes:
- Generally, the save system is much more cleaner, the API is consistent, and it is more stable.
- You might need to re-save the save files, atleast before you can properly open them at runtime, because I changed how editorStates are stored and only editor can load those old saves...
- GUI for loading scene canvases is temporary right now, planning a proper GUI update with toolbar and everything;)
- I plan to add canvas instancing support of some kind, where one canvas is saved as an asset and is instanced in multiple scenes to allow for varying parameters, including scene objects
  • Loading branch information
Seneral committed Jun 7, 2016
1 parent a05493e commit 23c875b
Show file tree
Hide file tree
Showing 18 changed files with 660 additions and 389 deletions.
226 changes: 135 additions & 91 deletions Editor/Node_Editor/NodeEditorWindow.cs

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Node_Editor/Framework/Node.cs
Expand Up @@ -16,11 +16,9 @@ public abstract class Node : ScriptableObject
public List<NodeKnob> nodeKnobs = new List<NodeKnob> ();

// Calculation graph
// [NonSerialized]
[SerializeField, HideInInspector]
[NonSerialized]
public List<NodeInput> Inputs = new List<NodeInput>();
// [NonSerialized]
[SerializeField, HideInInspector]
[NonSerialized]
public List<NodeOutput> Outputs = new List<NodeOutput>();
[HideInInspector]
[NonSerialized]
Expand Down Expand Up @@ -541,8 +539,8 @@ public void ClearCalculation ()

#region Recursive Search Helpers

private List<Node> recursiveSearchSurpassed;
private Node startRecursiveSearchNode; // Temporary start node for recursive searches
[NonSerialized] private List<Node> recursiveSearchSurpassed;
[NonSerialized] private Node startRecursiveSearchNode; // Temporary start node for recursive searches

/// <summary>
/// Begins the recursive search loop and returns whether this node has already been searched
Expand Down
67 changes: 67 additions & 0 deletions Node_Editor/Framework/NodeCanvas.cs
@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using NodeEditorFramework;

namespace NodeEditorFramework
Expand All @@ -8,6 +9,72 @@ public class NodeCanvas : ScriptableObject
{ // Just contains the nodes and global canvas stuff; an associated NodeEditorState holds the actual state now
public List<Node> nodes = new List<Node> ();

public NodeEditorState[] editorStates = new NodeEditorState[0];

public bool livesInScene = false;

/// <summary>
/// Will validate this canvas for any broken nodes or references and cleans them.
/// </summary>
public void Validate ()
{
if (nodes == null)
{
Debug.LogWarning ("NodeCanvas '" + name + "' nodes were erased and set to null! Automatically fixed!");
nodes = new List<Node> ();
}
for (int nodeCnt = 0; nodeCnt < nodes.Count; nodeCnt++)
{
Node node = nodes[nodeCnt];
if (node == null)
{
Debug.LogWarning ("NodeCanvas '" + name + "' contained broken (null) nodes! Automatically fixed!");
nodes.RemoveAt (nodeCnt);
nodeCnt--;
continue;
}
for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
{
NodeKnob nodeKnob = node.nodeKnobs[knobCnt];
if (nodeKnob == null)
{
Debug.LogWarning ("NodeCanvas '" + name + "' Node '" + node.name + "' contained broken (null) NodeKnobs! Automatically fixed!");
node.nodeKnobs.RemoveAt (knobCnt);
knobCnt--;
continue;
}

if (nodeKnob is NodeInput)
{
NodeInput input = nodeKnob as NodeInput;
if (input.connection != null && input.connection.body == null)
{ // References broken node; Clear connection
input.connection = null;
}
// for (int conCnt = 0; conCnt < (nodeKnob as NodeInput).connection.Count; conCnt++)
}
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)
{ // Broken connection; Clear connection
output.connections.RemoveAt (conCnt);
conCnt--;
}
}
}
}
}

if (editorStates == null)
{
Debug.LogWarning ("NodeCanvas '" + name + "' editorStates were erased! Automatically fixed!");
editorStates = new NodeEditorState[0];
}
editorStates = editorStates.Where ((NodeEditorState state) => state != null).ToArray ();
}
}
}
7 changes: 7 additions & 0 deletions Node_Editor/Framework/NodeCanvasSceneSave.cs
@@ -0,0 +1,7 @@
using UnityEngine;
using NodeEditorFramework;

public class NodeCanvasSceneSave : MonoBehaviour
{
public NodeCanvas savedNodeCanvas;
}
12 changes: 12 additions & 0 deletions Node_Editor/Framework/NodeCanvasSceneSave.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Node_Editor/Framework/NodeEditor.cs
Expand Up @@ -79,7 +79,7 @@ public static void ReInit (bool GUIFunction)
UnityEditor.EditorApplication.update += Update;
RepaintClients ();
#endif
initiated = true;
initiated = GUIFunction;
}

/// <summary>
Expand Down Expand Up @@ -125,11 +125,7 @@ public static void DrawCanvas (NodeCanvas nodeCanvas, NodeEditorState editorStat
return;
checkInit (true);

NodeEditorGUI.StartNodeGUI ();
OverlayGUI.StartOverlayGUI ();
DrawSubCanvas (nodeCanvas, editorState);
OverlayGUI.EndOverlayGUI ();
NodeEditorGUI.EndNodeGUI ();
}

/// <summary>
Expand Down
15 changes: 10 additions & 5 deletions Node_Editor/Framework/NodeEditorGUI.cs
Expand Up @@ -74,15 +74,20 @@ public static bool Init (bool GUIFunction)

public static void StartNodeGUI ()
{
defaultSkin = GUI.skin;
if (nodeSkin == null)
Init (true);
GUI.skin = nodeSkin;
if (GUI.skin != defaultSkin)
{
if (nodeSkin == null)
Init (true);
GUI.skin = nodeSkin;
}
OverlayGUI.StartOverlayGUI ();
}

public static void EndNodeGUI ()
{
GUI.skin = defaultSkin;
OverlayGUI.EndOverlayGUI ();
if (GUI.skin == defaultSkin)
GUI.skin = defaultSkin;
}

#region Connection Drawing
Expand Down

0 comments on commit 23c875b

Please sign in to comment.