diff --git a/Examples/NewNodeGraph.asset b/Examples/NewNodeGraph.asset deleted file mode 100644 index 62d3ed1..0000000 Binary files a/Examples/NewNodeGraph.asset and /dev/null differ diff --git a/Examples/NewNodeGraph.asset.meta b/Examples/NewNodeGraph.asset.meta deleted file mode 100644 index fc8326b..0000000 --- a/Examples/NewNodeGraph.asset.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 1452552e49747df45b25f74d307c25b6 -timeCreated: 1506021986 -licenseType: Free -NativeFormatImporter: - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index ca6e1ad..f763f3b 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -74,6 +74,7 @@ public class NodeEditor { if (fieldValue != curve) fields[i].SetValue(target, curve); } else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) { + if (fieldName == "graph") continue; //Ignore 'graph' fieldValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, fieldType, true); } diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index d830e7d..7928030 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -11,8 +11,7 @@ public partial class NodeEditorWindow : EditorWindow { public Dictionary portConnectionPoints { get { return _portConnectionPoints; } } private Dictionary _portConnectionPoints = new Dictionary(); private Dictionary portRects = new Dictionary(); - public NodeGraphAsset graphAsset; - public NodeGraph graph { get { return _graph != null ? _graph : _graph = new NodeGraph(); } } + public NodeGraph graph { get { return _graph != null ? _graph : _graph = CreateInstance(); } } public NodeGraph _graph; public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } } private Vector2 _panOffset; @@ -31,10 +30,8 @@ public partial class NodeEditorWindow : EditorWindow { } public void Save() { - if (graphAsset == null) SaveAs(); - else if (AssetDatabase.Contains(graphAsset)) { - graphAsset.json = graph.Serialize(); - EditorUtility.SetDirty(graphAsset); + if (AssetDatabase.Contains(_graph)) { + EditorUtility.SetDirty(_graph); AssetDatabase.SaveAssets(); } else SaveAs(); @@ -44,14 +41,10 @@ public partial class NodeEditorWindow : EditorWindow { string path = EditorUtility.SaveFilePanelInProject("Save NodeGraph", "NewNodeGraph", "asset", ""); if (string.IsNullOrEmpty(path)) return; else { - NodeGraphAsset existingGraphAsset = AssetDatabase.LoadAssetAtPath(path); - if (existingGraphAsset != null) graphAsset = existingGraphAsset; - else { - graphAsset = new NodeGraphAsset(); - AssetDatabase.CreateAsset(graphAsset, path); - } - graphAsset.json = graph.Serialize(); - EditorUtility.SetDirty(graphAsset); + NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath(path); + if (existingGraph != null) AssetDatabase.DeleteAsset(path); + AssetDatabase.CreateAsset(_graph, path); + EditorUtility.SetDirty(_graph); AssetDatabase.SaveAssets(); } } @@ -85,11 +78,10 @@ public partial class NodeEditorWindow : EditorWindow { [OnOpenAsset(0)] public static bool OnOpen(int instanceID, int line) { - NodeGraphAsset nodeGraphAsset = EditorUtility.InstanceIDToObject(instanceID) as NodeGraphAsset; - if (nodeGraphAsset != null) { + NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph; + if (nodeGraph != null) { NodeEditorWindow w = Init(); - w.graphAsset = nodeGraphAsset; - w._graph = nodeGraphAsset.nodeGraph; + w._graph = nodeGraph; return true; } return false; diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs index ca76749..4ceb107 100644 --- a/Scripts/NodeGraph.cs +++ b/Scripts/NodeGraph.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using UnityEngine; using System; /// Base class for all node graphs -[Serializable] -public class NodeGraph { +[Serializable, CreateAssetMenu(fileName = "NewNodeGraph", menuName = "Node Graph")] +public class NodeGraph : ScriptableObject { /// All nodes in the graph. /// See: [NonSerialized] public List nodes = new List(); diff --git a/Scripts/NodeGraphAsset.cs b/Scripts/NodeGraphAsset.cs deleted file mode 100644 index d9b2906..0000000 --- a/Scripts/NodeGraphAsset.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System; - -[CreateAssetMenu(fileName = "NewNodeGraph", menuName = "Node Graph")] -public class NodeGraphAsset : ScriptableObject { - public string json { get { return _json; } set { _json = value; _nodeGraph = null; } } - [SerializeField] private string _json; - - public NodeGraph nodeGraph { get { return _nodeGraph != null ? _nodeGraph : _nodeGraph = NodeGraph.Deserialize(json); } } - [NonSerialized] private NodeGraph _nodeGraph = null; -} diff --git a/Scripts/NodeGraphAsset.cs.meta b/Scripts/NodeGraphAsset.cs.meta deleted file mode 100644 index 718d0eb..0000000 --- a/Scripts/NodeGraphAsset.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 803fd86571b50524f807cf1e86777b1a -timeCreated: 1506020816 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: