Пример #1
0
        private void AssureCache()
        {
            // Get temp path to save cache to
            string tempPath;

            if (TEMP_PATH_USE_EDITOR_PATH_IF_IN_ASSETS && NodeEditor.editorPath.StartsWith("Assets") &&
                AssetDatabase.IsValidFolder(ResourceManager.StripTrailingSeparator(NodeEditor.editorPath)))
            {
                tempPath = NodeEditor.editorPath;
            }
            else if (!string.IsNullOrEmpty(TEMP_PATH_FIXED))
            {
                tempPath = TEMP_PATH_FIXED;
                Directory.CreateDirectory(tempPath);
            }
            else
            {             // Use variable temp path, only required if we have no folder in Assets/ that we can call ours to store the sessions in
                          // It will start with a default folder, but will allow users to easily move it by moving the files and a marker to any folder in Assets/
                // 1. Try to find temp path marker
                tempPath = AssetDatabase.GUIDToAssetPath(TEMP_PATH_MARKER_GUID);
                // Sometimes this will return a path but the asset behind it has been deleted
                if (!string.IsNullOrEmpty(tempPath) && !AssetDatabase.IsValidFolder(ResourceManager.UnifyPathSeparators(Path.GetDirectoryName(tempPath), '/')))
                {
                    tempPath = "";
                }
                if (string.IsNullOrEmpty(tempPath) || !File.Exists(tempPath))
                {                 // 2. Create temp path marker with specified GUID
                    if (string.IsNullOrEmpty(tempPath))
                    {             // No previous folder trace to use
                        Directory.CreateDirectory(TEMP_PATH_DEFAULT);
                        tempPath = TEMP_PATH_DEFAULT;
                    }
                    using (File.Create(tempPath + "NEFTempFilesMarker")) {}
                    using (StreamWriter sw = File.CreateText(tempPath + "NEFTempFilesMarker.meta"))
                        sw.Write(META_FILE.Replace("MARKER_GUID", TEMP_PATH_MARKER_GUID));
                    AssetDatabase.Refresh();
                    tempPath = AssetDatabase.GUIDToAssetPath(TEMP_PATH_MARKER_GUID);
                    Debug.LogWarning("Created temp marker '" + tempPath + "'! You can move this marker along with the cache files curSession and lastSession to a different cache location.");
                }
                tempPath = ResourceManager.UnifyPathSeparators(Path.GetDirectoryName(tempPath), '/') + "/";
            }
            if (!string.IsNullOrEmpty(TEMP_PATH_SUBFOLDER))
            {             // 3. Apply subfolder
                tempPath = tempPath + TEMP_PATH_SUBFOLDER;
                Directory.CreateDirectory(tempPath);
            }

            // Make sure we have a cache at that temp path with a canvas
            if (canvasCache == null)
            {
                canvasCache = new NodeEditorUserCache(tempPath);
            }
            else
            {
                canvasCache.SetCachePath(tempPath);
            }
            canvasCache.AssureCanvas();
        }