Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------/
        // Messages
        //--------------------------------------------------------------------------------------------/
        protected override void OnInitializeDisplay()
        {
            base.OnInitializeDisplay();
            var stratusPath = StratusIO.GetFolderPath("Stratus");

            icon = AssetDatabase.LoadAssetAtPath(stratusPath + path + iconName, typeof(Texture2D)) as Texture2D;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes this save's files, if serialized previously
        /// </summary>
        /// <returns></returns>
        public bool DeleteSerialization()
        {
            if (!serialized)
            {
                return(false);
            }

            if (!StratusIO.DeleteFile(filePath))
            {
                this.LogError($"Failed to delete save file at {filePath}");
                return(false);
            }

            if (snapshotLoaded || snapshotExists)
            {
                StratusIO.DeleteFile(snapshotFilePath);
            }

            OnDelete();

            filePath          = null;
            _snapshotFilePath = null;

            return(true);
        }
Exemplo n.º 3
0
 public static string ComposePath(string fileName, string folder = null)
 {
     if (folder != null)
     {
         return(StratusIO.CombinePath(saveDirectoryPath, folder, StratusIO.ChangeExtension(fileName, saveExtension)));
     }
     return(StratusIO.CombinePath(saveDirectoryPath, StratusIO.ChangeExtension(fileName, saveExtension)));
 }
Exemplo n.º 4
0
        private static void Export(ExportPackageArguments arguments)
        {
            string location = StratusIO.GetFolderPath(arguments.path);

            AssetDatabase.ExportPackage(location, $"{arguments.name}.unitypackage", arguments.options);
            EditorUtility.RevealInFinder(location);
            StratusDebug.Log($"Exported {arguments.name} to {location}");
        }
Exemplo n.º 5
0
        //------------------------------------------------------------------------/
        // Procedures
        //------------------------------------------------------------------------/
        private static void Export(string path, string packageName)
        {
            string location = StratusIO.GetFolderPath(path);

            AssetDatabase.ExportPackage(location, $"{packageName}.unitypackage",
                                        ExportPackageOptions.Recurse | ExportPackageOptions.Default |
                                        ExportPackageOptions.Interactive);
            StratusDebug.Log($"Exported {packageName} to {location}");
        }
Exemplo n.º 6
0
        //------------------------------------------------------------------------/
        // Methods
        //------------------------------------------------------------------------/
        /// <summary>
        /// Invoked whenever this save is serialized/deserialized
        /// </summary>
        /// <param name="filePath"></param>
        public void OnAnySerialization(string filePath)
        {
            this.filePath = filePath;
            this.fileName = StratusIO.GetFileName(filePath);

            if (Application.isPlaying)
            {
                this.playtime += StratusTime.minutesSinceStartup;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a string of the folder's path that this script is on
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string GetFolder(ScriptableObject obj)
        {
#if UNITY_EDITOR
            var ms   = UnityEditor.MonoScript.FromScriptableObject(obj);
            var path = UnityEditor.AssetDatabase.GetAssetPath(ms);
            var fi   = new FileInfo(path);

            var folder = fi.Directory.ToString();
            folder = folder.Replace('\\', '/');
            return(StratusIO.MakeRelative(folder));
#else
            return(string.Empty);
#endif
        }
Exemplo n.º 8
0
 /// <summary>
 /// Saves the current snapshot, if there's one
 /// and this save has been already serialized
 /// </summary>
 /// <returns></returns>
 public bool SaveSnapshot()
 {
     if (snapshot == null)
     {
         this.LogError("No valid snapshot texture assigned");
         return(false);
     }
     if (!serialized)
     {
         this.LogError("This save has not yet been serialized. Cannot save snapshot yet");
         return(false);
     }
     return(StratusIO.SaveImage2D(snapshot, snapshotFilePath, snapshotEncoding));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Loads the snapshot associated with this save, if present
        /// </summary>
        /// <returns></returns>
        public bool LoadSnapshot()
        {
            if (snapshotLoaded)
            {
                return(true);
            }

            if (!snapshotExists)
            {
                return(false);
            }

            snapshot = StratusIO.LoadImage2D(snapshotFilePath);
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generates an unique save file name based on naming convention and existing saves
        /// </summary>
        /// <returns></returns>
        public string GenerateSaveFileName()
        {
            string result = namingConvention;

            switch (suffix)
            {
            case StratusSaveDataSuffixFormat.Incremental:
                RefreshSaveFiles();
                result += $"{saveCount}";
                break;

            case StratusSaveDataSuffixFormat.SystemTime:
                result += $"{StratusIO.GetTimestamp(timestampParameters)}";
                break;
            }
            return(result);
        }
Exemplo n.º 11
0
        ///// <summary>
        ///// Loads save data from the given file, generates if not present
        ///// </summary>
        ///// <param name="fileName"></param>
        ///// <param name="folderName"></param>
        ///// <returns></returns>
        //public SaveType LoadOrCreate(string fileName, string folderName = null)
        //{
        //	string filePath = ComposePath(fileName, folderName);
        //	if (StratusIO.FileExists(filePath))
        //	{
        //		return Load(fileName, folderName);
        //	}
        //	if (debug)
        //	{
        //		StratusDebug.Log($"Creating data at path {filePath}");
        //	}
        //	return CreateSave(null, fileName);
        //}

        /// <summary>
        /// Deletes the save file at the default folder
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="folderName"></param>
        public bool Delete(string fileName, string folderName = null)
        {
            if (!Exists(fileName, saveDirectoryPath))
            {
                return(false);
            }

            var fileNameExt = fileName + saveExtension;
            var filePath    = saveDirectoryPath + fileNameExt;

            StratusIO.DeleteFile(ComposePath(fileName, folderName));
            File.Delete(filePath);
            if (debug)
            {
                StratusDebug.Log($"Deleted data at path {filePath}");
            }
            return(true);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Clears all found save files (searches for them first)
 /// </summary>
 public void ClearSaveFiles()
 {
     RefreshSaveFiles();
     if (saveFilePaths.IsValid())
     {
         for (int i = 0; i < saveFilePaths.Length; i++)
         {
             string file = saveFilePaths[i];
             StratusIO.DeleteFile(file);
         }
         if (debug)
         {
             this.Log($"Deleted {saveFilePaths.Length} save files!");
         }
     }
     else if (debug)
     {
         this.LogWarning("No save files were found to be deleted.");
     }
 }
        /// <summary>
        /// Loads the scriptable object from an Unity relative path.
        /// Returns null if the object doesn't exist.
        /// </summary>
        /// <typeparam name="T">The type of ScriptableObject</typeparam>
        /// <param name="path">The relative path to the asset. (e.g: "Assets/Resources/MyFile.asset")</param>
        /// <returns>The saved data as a ScriptableObject.</returns>
        public static T LoadScriptableObject <T>(string path) where T : ScriptableObject
        {
            var resourcesFolder = string.Concat(UnityDirectorySeparator, ResourcesFolderName, UnityDirectorySeparator);

            if (!path.Contains(resourcesFolder))
            {
                var exceptionMessage = string.Format(
                    "Failed to load ScriptableObject of type, {0}, from path: {1}. " +
                    "Path must begin with Assets and include a directory within the Resources folder.",
                    typeof(T).ToString(),
                    path);
                throw new UnityException(exceptionMessage);
            }

            // Mkae sure we are using a relative path
            var resourceRelativePath = StratusIO.MakeRelative(path);
            // Remove the file extension
            var fileExtension = Path.GetExtension(path);

            resourceRelativePath = resourceRelativePath.Replace(fileExtension, string.Empty);
            //Trace.Script("Loading data from " + resourceRelativePath);
            return(Resources.Load <T>(resourceRelativePath));
        }
Exemplo n.º 14
0
 public static bool Exists(string fileName, string folder = null) => StratusIO.FileExists(ComposePath(fileName, folder));
Exemplo n.º 15
0
 /// <summary>
 /// Reveals the default save file directory path
 /// </summary>
 public void RevealSaveFiles()
 {
     StratusIO.Open(saveDirectoryPath);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Generates a save name for this save. By default it will be the time stamp
 /// </summary>
 /// <returns></returns>
 protected virtual string GenerateSaveName()
 {
     return(StratusIO.GetTimestamp());
 }