diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 1a02556..249dc59 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEditor; +using UnityEditor.Experimental.SceneManagement; using UnityEngine; using XNodeEditor.Internal; @@ -227,18 +228,18 @@ namespace XNodeEditor { draggedOutput = null; draggedOutputTarget = null; EditorUtility.SetDirty(graph); - if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); + if (NodeEditorPreferences.GetSettings().autoSave) SaveAssets(); } else if (currentActivity == NodeActivity.DragNode) { IEnumerable nodes = Selection.objects.Where(x => x is XNode.Node).Select(x => x as XNode.Node); foreach (XNode.Node node in nodes) EditorUtility.SetDirty(node); - if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); + if (NodeEditorPreferences.GetSettings().autoSave) SaveAssets(); } else if (!IsHoveringNode) { // If click outside node, release field focus if (!isPanning) { EditorGUI.FocusTextInControl(null); EditorGUIUtility.editingTextField = false; } - if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); + if (NodeEditorPreferences.GetSettings().autoSave) SaveAssets(); } // If click node header, select it. @@ -543,5 +544,12 @@ namespace XNodeEditor { if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); autoConnectOutput = null; } + + /// Save assets normally or to prefab is contained in one + private void SaveAssets(){ + PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); + if (prefabStage == null) AssetDatabase.SaveAssets(); + else AssetDatabase.AddObjectToAsset(graph,prefabStage.prefabAssetPath); + } } }