@@ -77,10 +77,11 @@ private static List<GameObject> OnConvertInPlace (GameObject [] unityActiveGOs)
77
77
78
78
for ( int n = 0 ; n < gosToExport . Length ; n ++ ) {
79
79
var filename = gosToExport [ n ] . name + ".fbx" ;
80
- if ( File . Exists ( Path . Combine ( dirPath , filename ) ) ) {
81
- filename = IncrementFileName ( dirPath , filename ) ;
80
+ var filePath = Path . Combine ( dirPath , filename ) ;
81
+ if ( File . Exists ( filePath ) ) {
82
+ filePath = IncrementFileName ( dirPath , filename ) ;
82
83
}
83
- filePaths [ n ] = Path . Combine ( dirPath , filename ) ;
84
+ filePaths [ n ] = filePath ;
84
85
}
85
86
86
87
string [ ] fbxFileNames = new string [ filePaths . Length ] ;
@@ -142,33 +143,24 @@ private static List<GameObject> OnConvertInPlace (GameObject [] unityActiveGOs)
142
143
143
144
/// <summary>
144
145
/// Check if the file exists, and if it does, then increment the name.
145
- /// e.g. if filename is Sphere.fbx and it already exists, change it to Sphere1 .fbx.
146
+ /// e.g. if filename is Sphere.fbx and it already exists, change it to Sphere 1 .fbx.
146
147
/// </summary>
147
148
/// <returns>new file name.</returns>
148
149
/// <param name="filename">Filename.</param>
149
150
private static string IncrementFileName ( string path , string filename )
150
151
{
151
152
string fileWithoutExt = Path . GetFileNameWithoutExtension ( filename ) ;
152
153
string ext = Path . GetExtension ( filename ) ;
153
- string pattern = string . Format ( @"{0}{1}{2}" , fileWithoutExt , "*" , ext ) ;
154
- string [ ] files = Directory . GetFiles ( path , pattern , SearchOption . TopDirectoryOnly ) ;
155
-
156
- int index = 0 ;
157
- string groupName = "index" ;
158
- pattern = string . Format ( @"{0}{1}\{2}" , fileWithoutExt , "[ ]*(?<" + groupName + ">[0-9]*?)" , ext ) ;
159
- foreach ( var file in files ) {
160
- var match = System . Text . RegularExpressions . Regex . Match ( file , pattern ) ;
161
- if ( match . Success ) {
162
- string indexMatch = match . Groups [ groupName ] . Value ;
163
- if ( ! string . IsNullOrEmpty ( indexMatch ) ) {
164
- int i = - 1 ;
165
- if ( int . TryParse ( indexMatch , out i ) && i > index ) {
166
- index = i ;
167
- }
168
- }
169
- }
170
- }
171
- return string . Format ( "{0} {1}{2}" , fileWithoutExt , ( index + 1 ) , ext ) ;
154
+
155
+ int index = 1 ;
156
+ string file = null ;
157
+ do {
158
+ file = string . Format ( "{0} {1}{2}" , fileWithoutExt , index , ext ) ;
159
+ file = Path . Combine ( path , file ) ;
160
+ index ++ ;
161
+ } while ( File . Exists ( file ) ) ;
162
+
163
+ return file ;
172
164
}
173
165
174
166
private static void SetupImportedGameObject ( GameObject orig , GameObject imported )
0 commit comments