1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00

Added option to disable autosave in preferences

This commit is contained in:
Thor Brigsted 2018-04-13 10:46:51 +02:00
parent 9f09452b43
commit 2582d5aaf3
5 changed files with 23 additions and 13 deletions

View File

@ -201,9 +201,9 @@ namespace XNodeEditor {
draggedOutput = null; draggedOutput = null;
draggedOutputTarget = null; draggedOutputTarget = null;
EditorUtility.SetDirty(graph); EditorUtility.SetDirty(graph);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (currentActivity == NodeActivity.DragNode) { } else if (currentActivity == NodeActivity.DragNode) {
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (!IsHoveringNode) { } else if (!IsHoveringNode) {
// If click outside node, release field focus // If click outside node, release field focus
if (!isPanning) { if (!isPanning) {
@ -214,7 +214,7 @@ namespace XNodeEditor {
EditorGUIUtility.keyboardControl = 0; EditorGUIUtility.keyboardControl = 0;
EditorGUIUtility.hotControl = 0; EditorGUIUtility.hotControl = 0;
} }
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
// If click node header, select it. // If click node header, select it.
@ -298,7 +298,7 @@ namespace XNodeEditor {
node.position = position; node.position = position;
node.name = UnityEditor.ObjectNames.NicifyVariableName(type.ToString()); node.name = UnityEditor.ObjectNames.NicifyVariableName(type.ToString());
AssetDatabase.AddObjectToAsset(node, graph); AssetDatabase.AddObjectToAsset(node, graph);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
Repaint(); Repaint();
} }

View File

@ -94,7 +94,7 @@ namespace XNodeEditor {
GenericMenu contextMenu = new GenericMenu(); GenericMenu contextMenu = new GenericMenu();
contextMenu.AddItem(new GUIContent("Remove"), false, () => reroute.RemovePoint()); contextMenu.AddItem(new GUIContent("Remove"), false, () => reroute.RemovePoint());
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
/// <summary> Show right-click context menu for hovered port </summary> /// <summary> Show right-click context menu for hovered port </summary>
@ -102,7 +102,7 @@ namespace XNodeEditor {
GenericMenu contextMenu = new GenericMenu(); GenericMenu contextMenu = new GenericMenu();
contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections()); contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
/// <summary> Show right-click context menu for selected nodes </summary> /// <summary> Show right-click context menu for selected nodes </summary>

View File

@ -25,6 +25,7 @@ namespace XNodeEditor {
public Color32 highlightColor = new Color32(255, 255, 255, 255); public Color32 highlightColor = new Color32(255, 255, 255, 255);
public bool gridSnap = true; public bool gridSnap = true;
public bool autoSave = true;
[SerializeField] private string typeColorsData = ""; [SerializeField] private string typeColorsData = "";
[NonSerialized] public Dictionary<string, Color> typeColors = new Dictionary<string, Color>(); [NonSerialized] public Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
public NoodleType noodleType = NoodleType.Curve; public NoodleType noodleType = NoodleType.Curve;
@ -73,9 +74,9 @@ namespace XNodeEditor {
XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute attrib = attribs[0] as XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute; XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute attrib = attribs[0] as XNodeEditor.NodeGraphEditor.CustomNodeGraphEditorAttribute;
lastEditor = XNodeEditor.NodeEditorWindow.current.graphEditor; lastEditor = XNodeEditor.NodeEditorWindow.current.graphEditor;
lastKey = attrib.editorPrefsKey; lastKey = attrib.editorPrefsKey;
VerifyLoaded();
} else return null; } else return null;
} }
if (!settings.ContainsKey(lastKey)) VerifyLoaded();
return settings[lastKey]; return settings[lastKey];
} }
@ -86,6 +87,7 @@ namespace XNodeEditor {
NodeSettingsGUI(lastKey, settings); NodeSettingsGUI(lastKey, settings);
GridSettingsGUI(lastKey, settings); GridSettingsGUI(lastKey, settings);
SystemSettingsGUI(lastKey, settings);
TypeColorsGUI(lastKey, settings); TypeColorsGUI(lastKey, settings);
if (GUILayout.Button(new GUIContent("Set Default", "Reset all values to default"), GUILayout.Width(120))) { if (GUILayout.Button(new GUIContent("Set Default", "Reset all values to default"), GUILayout.Width(120))) {
ResetPrefs(); ResetPrefs();
@ -95,7 +97,7 @@ namespace XNodeEditor {
private static void GridSettingsGUI(string key, Settings settings) { private static void GridSettingsGUI(string key, Settings settings) {
//Label //Label
EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel); 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.gridLineColor = EditorGUILayout.ColorField("Color", settings.gridLineColor);
settings.gridBgColor = EditorGUILayout.ColorField(" ", settings.gridBgColor); settings.gridBgColor = EditorGUILayout.ColorField(" ", settings.gridBgColor);
@ -107,6 +109,14 @@ namespace XNodeEditor {
EditorGUILayout.Space(); 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) { private static void NodeSettingsGUI(string key, Settings settings) {
//Label //Label
EditorGUILayout.LabelField("Node", EditorStyles.boldLabel); EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);

View File

@ -20,8 +20,8 @@ namespace XNodeEditor {
private float _zoom = 1; private float _zoom = 1;
void OnFocus() { void OnFocus() {
AssetDatabase.SaveAssets();
current = this; current = this;
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
partial void OnEnable(); partial void OnEnable();
@ -37,7 +37,7 @@ namespace XNodeEditor {
public void Save() { public void Save() {
if (AssetDatabase.Contains(graph)) { if (AssetDatabase.Contains(graph)) {
EditorUtility.SetDirty(graph); EditorUtility.SetDirty(graph);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else SaveAs(); } else SaveAs();
} }
@ -49,7 +49,7 @@ namespace XNodeEditor {
if (existingGraph != null) AssetDatabase.DeleteAsset(path); if (existingGraph != null) AssetDatabase.DeleteAsset(path);
AssetDatabase.CreateAsset(graph, path); AssetDatabase.CreateAsset(graph, path);
EditorUtility.SetDirty(graph); EditorUtility.SetDirty(graph);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
} }

View File

@ -47,7 +47,7 @@ namespace XNodeEditor {
XNode.Node node = target.CopyNode(original); XNode.Node node = target.CopyNode(original);
node.name = original.name; node.name = original.name;
AssetDatabase.AddObjectToAsset(node, target); AssetDatabase.AddObjectToAsset(node, target);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
return node; return node;
} }
@ -55,7 +55,7 @@ namespace XNodeEditor {
public void RemoveNode(XNode.Node node) { public void RemoveNode(XNode.Node node) {
UnityEngine.Object.DestroyImmediate(node, true); UnityEngine.Object.DestroyImmediate(node, true);
target.RemoveNode(node); target.RemoveNode(node);
AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} }
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]