mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Removed NodeGraphAsset. Made NodeGraph into a ScriptableObject
Runtime serialization will have to wait.
This commit is contained in:
parent
d88cf5b53d
commit
f00b957e04
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1452552e49747df45b25f74d307c25b6
|
||||
timeCreated: 1506021986
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -11,8 +11,7 @@ public partial class NodeEditorWindow : EditorWindow {
|
||||
public Dictionary<NodePort, Vector2> portConnectionPoints { get { return _portConnectionPoints; } }
|
||||
private Dictionary<NodePort, Vector2> _portConnectionPoints = new Dictionary<NodePort, Vector2>();
|
||||
private Dictionary<NodePort, Rect> portRects = new Dictionary<NodePort, Rect>();
|
||||
public NodeGraphAsset graphAsset;
|
||||
public NodeGraph graph { get { return _graph != null ? _graph : _graph = new NodeGraph(); } }
|
||||
public NodeGraph graph { get { return _graph != null ? _graph : _graph = CreateInstance<NodeGraph>(); } }
|
||||
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<NodeGraphAsset>(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<NodeGraph>(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;
|
||||
|
||||
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
/// <summary> Base class for all node graphs </summary>
|
||||
[Serializable]
|
||||
public class NodeGraph {
|
||||
[Serializable, CreateAssetMenu(fileName = "NewNodeGraph", menuName = "Node Graph")]
|
||||
public class NodeGraph : ScriptableObject {
|
||||
/// <summary> All nodes in the graph. <para/>
|
||||
/// See: <see cref="AddNode{T}"/> </summary>
|
||||
[NonSerialized] public List<Node> nodes = new List<Node>();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 803fd86571b50524f807cf1e86777b1a
|
||||
timeCreated: 1506020816
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user