@@ -11,9 +11,9 @@ public static class SaveLoadUtility
1111 private const string DefaultFolderName = "SaveLoad" ;
1212 private const string DefaultBaseFolderPath = "GameData" ;
1313
14- public static string GetSavePath ( string folderName = null , string baseFolderPath = null )
14+ public static string GetSavePath ( string folderName = null , string baseFolderPath = null , bool streamingAssets = false )
1515 {
16- return GetRuntimeSavePath ( folderName , baseFolderPath ) ;
16+ return ! streamingAssets ? GetRuntimeSavePath ( folderName , baseFolderPath ) : GetStreamingAssetsSavePath ( folderName , baseFolderPath ) ;
1717 }
1818
1919 public static string GetRuntimeSavePath ( string folderName = null , string baseFolderPath = null )
@@ -29,7 +29,24 @@ public static string GetRuntimeSavePath(string folderName = null, string baseFol
2929 }
3030
3131 var savePath = $ "{ Application . persistentDataPath } /{ baseFolderPath } /";
32- savePath = savePath + folderName + "/" ;
32+ savePath = $ "{ savePath } { folderName } /";
33+ return savePath ;
34+ }
35+
36+ public static string GetStreamingAssetsSavePath ( string folderName = null , string baseFolderPath = null )
37+ {
38+ if ( string . IsNullOrEmpty ( folderName ) )
39+ {
40+ folderName = DefaultFolderName ;
41+ }
42+
43+ if ( string . IsNullOrEmpty ( baseFolderPath ) )
44+ {
45+ baseFolderPath = DefaultBaseFolderPath ;
46+ }
47+
48+ var savePath = $ "{ Application . streamingAssetsPath } /{ baseFolderPath } /";
49+ savePath = $ "{ savePath } { folderName } /";
3350 return savePath ;
3451 }
3552
@@ -77,10 +94,11 @@ public static void Save(object saveObject, ISerializationMethod serializationMet
7794 /// <param name="filename"></param>
7895 /// <param name="folderName"></param>
7996 /// <param name="baseFolderPath"></param>
97+ /// <param name="streamingAssets"></param>
8098 /// <returns></returns>
81- public static object Load ( System . Type objectType , ISerializationMethod serializationMethod , string filename , string folderName = null , string baseFolderPath = null )
99+ public static object Load ( System . Type objectType , ISerializationMethod serializationMethod , string filename , string folderName = null , string baseFolderPath = null , bool streamingAssets = false )
82100 {
83- var savePath = GetSavePath ( folderName , baseFolderPath ) ;
101+ var savePath = GetSavePath ( folderName , baseFolderPath , streamingAssets ) ;
84102 var saveFilename = savePath + GetSaveFileName ( filename ) ;
85103
86104 object returnObject = null ;
@@ -104,11 +122,12 @@ public static object Load(System.Type objectType, ISerializationMethod serializa
104122 /// </summary>
105123 /// <param name="folderName">folder containing the save files</param>
106124 /// <param name="baseFolderPath">base path to the folder</param>
107- /// <param name="extension">include only files with the specified extension</param>
125+ /// <param name="extension">include only files with this extension</param>
126+ /// <param name="streamingAssets">Will use Application.streamingAssetsPath as base path if true otherwise Application.persistentDataPath</param>
108127 /// <returns>list of file names</returns>
109- public static IEnumerable < string > EnumerateSavedFiles ( string folderName = null , string baseFolderPath = null , string extension = null )
128+ public static IEnumerable < string > EnumerateSavedFiles ( string folderName = null , string baseFolderPath = null , string extension = null , bool streamingAssets = false )
110129 {
111- var savePath = GetSavePath ( folderName , baseFolderPath ) ;
130+ var savePath = GetSavePath ( folderName , baseFolderPath , streamingAssets ) ;
112131
113132 //If directory does not exist we're done
114133 if ( ! Directory . Exists ( savePath ) )
@@ -126,13 +145,29 @@ public static IEnumerable<string> EnumerateSavedFiles(string folderName = null,
126145 /// <summary>
127146 /// Creates an array list of save files in the given folder and path
128147 /// </summary>
129- /// <param name="folderName">folder containing the save files</param>
130- /// <param name="baseFolderPath">base path to the folder</param>
148+ /// <param name="folderName"></param>
149+ /// <param name="baseFolderPath"></param>
150+ /// <param name="extension">include only files with this extension</param>
151+ /// <param name="streamingAssets">Will use Application.streamingAssetsPath as base path if true otherwise Application.persistentDataPath</param>
152+ /// <returns>Array of file names</returns>
153+ public static string [ ] GetSavedFiles ( string folderName = null , string baseFolderPath = null , string extension = null , bool streamingAssets = false )
154+ {
155+ return EnumerateSavedFiles ( folderName , baseFolderPath , extension , streamingAssets ) . ToArray ( ) ;
156+ }
157+
158+ /// <summary>
159+ /// Populates a given array with a list of save files in the given folder and path
160+ /// </summary>
161+ /// <param name="list">list to be populated with file names</param>
162+ /// <param name="folderName"></param>
163+ /// <param name="baseFolderPath"></param>
131164 /// <param name="extension">include only files with this extension</param>
165+ /// <param name="streamingAssets">Will use Application.streamingAssetsPath as base path if true otherwise Application.persistentDataPath</param>
132166 /// <returns>Array of file names</returns>
133- public static string [ ] GetSavedFiles ( string folderName = null , string baseFolderPath = null , string extension = null )
167+ public static void GetSavedFiles ( List < string > list , string folderName = null , string baseFolderPath = null , string extension = null , bool streamingAssets = false )
134168 {
135- return EnumerateSavedFiles ( folderName , baseFolderPath , extension ) . ToArray ( ) ;
169+ list . Clear ( ) ;
170+ list . AddRange ( EnumerateSavedFiles ( folderName , baseFolderPath , extension , streamingAssets ) ) ;
136171 }
137172
138173 /// <summary>
0 commit comments