File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 66using UnityEngine ;
77using UnityEditor ;
88using Unity . Mathematics ;
9+ using Helpers ;
910
1011[ System . Serializable ]
1112public class CSVWriter
@@ -22,11 +23,12 @@ public class CSVWriter
2223 private bool is_active = false ;
2324
2425 public bool Initialize ( ) {
25- string dname = Application . persistentDataPath ;
26+ string dname = $ " { Application . persistentDataPath } / { Helpers . SaveSystemMethods . GetCurrentDateTime ( ) } " ;
2627 if ( dirName != null && dirName . Length > 0 ) {
27- dname = $ "Assets/{ dirName } ";
28- if ( ! AssetDatabase . IsValidFolder ( dname ) ) dname = AssetDatabase . GUIDToAssetPath ( AssetDatabase . CreateFolder ( "Assets" , dirName ) ) ;
28+ dname = $ "{ Application . persistentDataPath } /{ dirName } ";
2929 }
30+ Helpers . SaveSystemMethods . CheckOrCreateDirectory ( dname ) ;
31+
3032 string fname = ( fileName != null && fileName . Length > 0 ) ? fileName : System . DateTime . Now . ToString ( "HH-mm-ss" ) ;
3133 filePath = ( append_zero_to_filename ) ? Path . Combine ( dname , fname + "_0.csv" ) : Path . Combine ( dname , fname + ".csv" ) ;
3234
Original file line number Diff line number Diff line change @@ -144,6 +144,20 @@ public static bool CheckOrCreateDirectory(string dirPath) {
144144 public static bool CheckFileExists ( string filePath ) {
145145 return File . Exists ( filePath ) ;
146146 }
147+ public static string GetUniqueDirectory ( string dirPath ) {
148+ int counter = 1 ;
149+ string returnDir = dirPath ;
150+ while ( CheckDirectoryExists ( returnDir ) ) {
151+ returnDir = $ "{ dirPath } _{ counter } ";
152+ counter += 1 ;
153+ }
154+ return returnDir ;
155+ }
156+ public static string CreateUniqueDirectory ( string dirPath ) {
157+ string returnDir = GetUniqueDirectory ( dirPath ) ;
158+ Directory . CreateDirectory ( returnDir ) ;
159+ return returnDir ;
160+ }
147161 public static bool DeleteDirectory ( string dirPath ) {
148162 if ( CheckDirectoryExists ( dirPath ) ) {
149163 Directory . Delete ( dirPath , true ) ;
@@ -158,6 +172,10 @@ public static bool DeleteFile(string filePath) {
158172 }
159173 return false ;
160174 }
175+
176+ public static string GetCurrentDateTime ( string format = "HH-mm-ss" ) {
177+ return System . DateTime . Now . ToString ( format ) ;
178+ }
161179
162180 public static string ConvertToJSON < T > ( T data ) {
163181 return JsonUtility . ToJson ( data , true ) ;
You can’t perform that action at this time.
0 commit comments