mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +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);
|
if (fieldValue != curve) fields[i].SetValue(target, curve);
|
||||||
}
|
}
|
||||||
else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) {
|
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);
|
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; } }
|
public Dictionary<NodePort, Vector2> portConnectionPoints { get { return _portConnectionPoints; } }
|
||||||
private Dictionary<NodePort, Vector2> _portConnectionPoints = new Dictionary<NodePort, Vector2>();
|
private Dictionary<NodePort, Vector2> _portConnectionPoints = new Dictionary<NodePort, Vector2>();
|
||||||
private Dictionary<NodePort, Rect> portRects = new Dictionary<NodePort, Rect>();
|
private Dictionary<NodePort, Rect> portRects = new Dictionary<NodePort, Rect>();
|
||||||
public NodeGraphAsset graphAsset;
|
public NodeGraph graph { get { return _graph != null ? _graph : _graph = CreateInstance<NodeGraph>(); } }
|
||||||
public NodeGraph graph { get { return _graph != null ? _graph : _graph = new NodeGraph(); } }
|
|
||||||
public NodeGraph _graph;
|
public NodeGraph _graph;
|
||||||
public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } }
|
public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } }
|
||||||
private Vector2 _panOffset;
|
private Vector2 _panOffset;
|
||||||
@ -31,10 +30,8 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Save() {
|
public void Save() {
|
||||||
if (graphAsset == null) SaveAs();
|
if (AssetDatabase.Contains(_graph)) {
|
||||||
else if (AssetDatabase.Contains(graphAsset)) {
|
EditorUtility.SetDirty(_graph);
|
||||||
graphAsset.json = graph.Serialize();
|
|
||||||
EditorUtility.SetDirty(graphAsset);
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
else SaveAs();
|
else SaveAs();
|
||||||
@ -44,14 +41,10 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
string path = EditorUtility.SaveFilePanelInProject("Save NodeGraph", "NewNodeGraph", "asset", "");
|
string path = EditorUtility.SaveFilePanelInProject("Save NodeGraph", "NewNodeGraph", "asset", "");
|
||||||
if (string.IsNullOrEmpty(path)) return;
|
if (string.IsNullOrEmpty(path)) return;
|
||||||
else {
|
else {
|
||||||
NodeGraphAsset existingGraphAsset = AssetDatabase.LoadAssetAtPath<NodeGraphAsset>(path);
|
NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath<NodeGraph>(path);
|
||||||
if (existingGraphAsset != null) graphAsset = existingGraphAsset;
|
if (existingGraph != null) AssetDatabase.DeleteAsset(path);
|
||||||
else {
|
AssetDatabase.CreateAsset(_graph, path);
|
||||||
graphAsset = new NodeGraphAsset();
|
EditorUtility.SetDirty(_graph);
|
||||||
AssetDatabase.CreateAsset(graphAsset, path);
|
|
||||||
}
|
|
||||||
graphAsset.json = graph.Serialize();
|
|
||||||
EditorUtility.SetDirty(graphAsset);
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,11 +78,10 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
|
|
||||||
[OnOpenAsset(0)]
|
[OnOpenAsset(0)]
|
||||||
public static bool OnOpen(int instanceID, int line) {
|
public static bool OnOpen(int instanceID, int line) {
|
||||||
NodeGraphAsset nodeGraphAsset = EditorUtility.InstanceIDToObject(instanceID) as NodeGraphAsset;
|
NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph;
|
||||||
if (nodeGraphAsset != null) {
|
if (nodeGraph != null) {
|
||||||
NodeEditorWindow w = Init();
|
NodeEditorWindow w = Init();
|
||||||
w.graphAsset = nodeGraphAsset;
|
w._graph = nodeGraph;
|
||||||
w._graph = nodeGraphAsset.nodeGraph;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
/// <summary> Base class for all node graphs </summary>
|
/// <summary> Base class for all node graphs </summary>
|
||||||
[Serializable]
|
[Serializable, CreateAssetMenu(fileName = "NewNodeGraph", menuName = "Node Graph")]
|
||||||
public class NodeGraph {
|
public class NodeGraph : ScriptableObject {
|
||||||
/// <summary> All nodes in the graph. <para/>
|
/// <summary> All nodes in the graph. <para/>
|
||||||
/// See: <see cref="AddNode{T}"/> </summary>
|
/// See: <see cref="AddNode{T}"/> </summary>
|
||||||
[NonSerialized] public List<Node> nodes = new List<Node>();
|
[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