/// <summary>
        /// Load the editor from the last session. If a previous editor is not found, returns an empty save which
        /// can be consumed like a non-empty one - in particular, never returns null.
        /// </summary>
        public static NodeEditorSave Load()
        {
            NodeEditorSave save = null;

            save = EditorGUIUtility.Load(IOHelpers.CombinePath(assets, resources, assetNameWithExtension)) as NodeEditorSave;
            if (save == null)
            {
                save = CreateInstance <NodeEditorSave>();
            }
            Assert.IsNotNull(save);
            return(save);
        }
Esempio n. 2
0
        void Load()
        {
            var savedEditor = NodeEditorSave.Load();

            if (savedEditor == null)
            {
                nodes = new List <NodeGroup>();
                return;
            }

            dragOffset = savedEditor.Offset; // Important: restore offset before restoring nodes.
            nodes      = new List <NodeGroup>();
            foreach (SavedNode savedNode in savedEditor.Nodes)
            {
                AddNode(savedNode.NodeRect, savedNode.MapGenModule);
            }
        }
        public static void Save(NodeEditorSave save)
        {
            Assert.IsNotNull(save);
            Assert.IsTrue(save.Nodes.All(node => node != null));
            string folderPath = Path.Combine(assets, resources);

            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                AssetDatabase.CreateFolder(assets, resources);
            }
            string assetPath = Path.Combine(folderPath, assetNameWithExtension);

            if (IOHelpers.AssetExists(assetName, folderPath))
            {
                AssetDatabase.DeleteAsset(assetPath);
            }
            AssetDatabase.CreateAsset(save, assetPath);
            AssetDatabase.SaveAssets();
        }
        /// <summary>
        /// Load the editor from the last session. If a previous editor is not found, returns an empty save which
        /// can be consumed like a non-empty one - in particular, never returns null.
        /// </summary>
        public static NodeEditorSave Load()
        {
            NodeEditorSave save = null;

            if (EditorPrefs.GetBool(loadKey))
            {
                save = EditorGUIUtility.Load(IOHelpers.CombinePath(assets, resources, assetNameWithExtension)) as NodeEditorSave;
            }
            if (save == null)
            {
                save = CreateInstance <NodeEditorSave>();
            }
            else
            {
                // Deep copy all nodes so that we're not maintaining any references to the saved asset.
                // Otherwise, the references will break when we delete the asset.
                //save = save.CopyDeep();
            }
            Assert.IsNotNull(save);
            return(save);
        }
        public static void Save(NodeEditorSave save)
        {
            Assert.IsNotNull(save);
            Assert.IsTrue(save.Nodes.All(node => node != null));
            string folderPath = Path.Combine(assets, resources);

            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                AssetDatabase.CreateFolder(assets, resources);
            }
            string assetPath = Path.Combine(folderPath, assetNameWithExtension);

            if (IOHelpers.AssetExists(assetName, folderPath))
            {
                AssetDatabase.DeleteAsset(assetPath);
            }
            AssetDatabase.CreateAsset(save, assetPath);
            //save = save.CopyDeep();
            //ScriptableObjectHelpers.SaveCompoundScriptableObject(save, assetPath);
            EditorPrefs.SetBool(loadKey, true);
            AssetDatabase.SaveAssets();
        }
Esempio n. 6
0
 void Save()
 {
     savedEditor = NodeEditorSave.CreateSave(nodes, dragOffset);
     NodeEditorSave.Save(savedEditor);
 }