diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs
index b237d6b..651824a 100644
--- a/Scripts/Editor/NodeEditorAction.cs
+++ b/Scripts/Editor/NodeEditorAction.cs
@@ -201,9 +201,9 @@ namespace XNodeEditor {
draggedOutput = null;
draggedOutputTarget = null;
EditorUtility.SetDirty(graph);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (currentActivity == NodeActivity.DragNode) {
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (!IsHoveringNode) {
// If click outside node, release field focus
if (!isPanning) {
@@ -214,7 +214,7 @@ namespace XNodeEditor {
EditorGUIUtility.keyboardControl = 0;
EditorGUIUtility.hotControl = 0;
}
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
// If click node header, select it.
@@ -298,7 +298,7 @@ namespace XNodeEditor {
node.position = position;
node.name = UnityEditor.ObjectNames.NicifyVariableName(type.ToString());
AssetDatabase.AddObjectToAsset(node, graph);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
Repaint();
}
diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs
index 2c71a29..34cd210 100644
--- a/Scripts/Editor/NodeEditorGUI.cs
+++ b/Scripts/Editor/NodeEditorGUI.cs
@@ -94,7 +94,7 @@ namespace XNodeEditor {
GenericMenu contextMenu = new GenericMenu();
contextMenu.AddItem(new GUIContent("Remove"), false, () => reroute.RemovePoint());
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
/// Show right-click context menu for hovered port
@@ -102,7 +102,7 @@ namespace XNodeEditor {
GenericMenu contextMenu = new GenericMenu();
contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
/// Show right-click context menu for selected nodes
diff --git a/Scripts/Editor/NodeEditorPreferences.cs b/Scripts/Editor/NodeEditorPreferences.cs
index aa87785..210a619 100644
--- a/Scripts/Editor/NodeEditorPreferences.cs
+++ b/Scripts/Editor/NodeEditorPreferences.cs
@@ -25,6 +25,7 @@ namespace XNodeEditor {
public Color32 highlightColor = new Color32(255, 255, 255, 255);
public bool gridSnap = true;
+ public bool autoSave = true;
[SerializeField] private string typeColorsData = "";
[NonSerialized] public Dictionary typeColors = new Dictionary();
public NoodleType noodleType = NoodleType.Curve;
@@ -73,9 +74,9 @@ namespace XNodeEditor {
XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute attrib = attribs[0] as XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute;
lastEditor = XNodeEditor.NodeEditorWindow.current.graphEditor;
lastKey = attrib.editorPrefsKey;
- VerifyLoaded();
} else return null;
}
+ if (!settings.ContainsKey(lastKey)) VerifyLoaded();
return settings[lastKey];
}
@@ -86,6 +87,7 @@ namespace XNodeEditor {
NodeSettingsGUI(lastKey, settings);
GridSettingsGUI(lastKey, settings);
+ SystemSettingsGUI(lastKey, settings);
TypeColorsGUI(lastKey, settings);
if (GUILayout.Button(new GUIContent("Set Default", "Reset all values to default"), GUILayout.Width(120))) {
ResetPrefs();
@@ -95,7 +97,7 @@ namespace XNodeEditor {
private static void GridSettingsGUI(string key, Settings settings) {
//Label
EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel);
- settings.gridSnap = EditorGUILayout.Toggle("Snap", settings.gridSnap);
+ settings.gridSnap = EditorGUILayout.Toggle(new GUIContent("Snap", "Hold CTRL in editor to invert"), settings.gridSnap);
settings.gridLineColor = EditorGUILayout.ColorField("Color", settings.gridLineColor);
settings.gridBgColor = EditorGUILayout.ColorField(" ", settings.gridBgColor);
@@ -107,6 +109,14 @@ namespace XNodeEditor {
EditorGUILayout.Space();
}
+ private static void SystemSettingsGUI(string key, Settings settings) {
+ //Label
+ EditorGUILayout.LabelField("System", EditorStyles.boldLabel);
+ settings.autoSave = EditorGUILayout.Toggle(new GUIContent("Autosave", "Disable for better editor performance"), settings.autoSave);
+ if (GUI.changed) SavePrefs(key, settings);
+ EditorGUILayout.Space();
+ }
+
private static void NodeSettingsGUI(string key, Settings settings) {
//Label
EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs
index 67d7e73..d626130 100644
--- a/Scripts/Editor/NodeEditorWindow.cs
+++ b/Scripts/Editor/NodeEditorWindow.cs
@@ -20,8 +20,8 @@ namespace XNodeEditor {
private float _zoom = 1;
void OnFocus() {
- AssetDatabase.SaveAssets();
current = this;
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
partial void OnEnable();
@@ -37,7 +37,7 @@ namespace XNodeEditor {
public void Save() {
if (AssetDatabase.Contains(graph)) {
EditorUtility.SetDirty(graph);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else SaveAs();
}
@@ -49,7 +49,7 @@ namespace XNodeEditor {
if (existingGraph != null) AssetDatabase.DeleteAsset(path);
AssetDatabase.CreateAsset(graph, path);
EditorUtility.SetDirty(graph);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
}
diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs
index 37b7eaf..8d81a07 100644
--- a/Scripts/Editor/NodeGraphEditor.cs
+++ b/Scripts/Editor/NodeGraphEditor.cs
@@ -47,7 +47,7 @@ namespace XNodeEditor {
XNode.Node node = target.CopyNode(original);
node.name = original.name;
AssetDatabase.AddObjectToAsset(node, target);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
return node;
}
@@ -55,7 +55,7 @@ namespace XNodeEditor {
public void RemoveNode(XNode.Node node) {
UnityEngine.Object.DestroyImmediate(node, true);
target.RemoveNode(node);
- AssetDatabase.SaveAssets();
+ if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
[AttributeUsage(AttributeTargets.Class)]