8
8
9
9
namespace FbxExporters
10
10
{
11
- class Integrations
12
- {
11
+ class Integrations
12
+ {
13
+ const string MenuItemName = "FbxExporters/Install Maya2017 Integration" ;
14
+
15
+ private const string MAYA_VERSION = "2017" ;
16
+ private const string MODULE_FILENAME = "unityoneclick.mod" ;
13
17
private const string PACKAGE_NAME = "FbxExporters" ;
14
18
private const string VERSION_FILENAME = "README.txt" ;
15
19
private const string VERSION_FIELD = "**Version**" ;
20
+ private const string VERSION_TAG = "{Version}" ;
21
+ private const string PROJECT_TAG = "{UnityProject}" ;
22
+
16
23
private static Char [ ] FIELD_SEPARATORS = new Char [ ] { ':' } ;
17
24
18
- private const string REL_MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya<version> /unityoneclick.mod" ;
25
+ private const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya" + VERSION_TAG + " /unityoneclick.mod";
19
26
20
- #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
21
- private const string REL_MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/<version> /modules" ;
22
- #elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
23
- private const string REL_MAYA_MODULES_PATH = "Maya/<version> /modules" ;
27
+ #if UNITY_EDITOR_OSX
28
+ private const string REL_MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/" + VERSION_TAG + " /modules";
29
+ #elif UNITY_EDITOR_LINUX
30
+ private const string REL_MAYA_MODULES_PATH = "Maya/" + VERSION_TAG + " /modules";
24
31
#else
25
- private const string REL_MAYA_MODULES_PATH = "My Documents/Maya/<version> /modules" ;
32
+ private const string REL_MAYA_MODULES_PATH = "My Documents/Maya/" + VERSION_TAG + " /modules";
26
33
#endif
27
34
28
35
private static string GetUserFolder ( )
29
36
{
30
- #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
37
+ #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_EDITOR_LINUX
31
38
return System . Environment . GetEnvironmentVariable ( "HOME" ) ;
32
39
#else
33
40
return System . Environment . GetFolderPath ( System . Environment . SpecialFolder . Personal )
@@ -38,14 +45,14 @@ private static string GetModulePath(string version)
38
45
{
39
46
string result = System . IO . Path . Combine ( GetUserFolder ( ) , REL_MAYA_MODULES_PATH ) ;
40
47
41
- return result . Replace ( "<version>" , version ) ;
48
+ return result . Replace ( VERSION_TAG , version ) ;
42
49
}
43
50
44
51
private static string GetModuleTemplatePath ( string version )
45
52
{
46
- string result = System . IO . Path . Combine ( Application . dataPath , REL_MODULE_TEMPLATE_PATH ) ;
53
+ string result = System . IO . Path . Combine ( Application . dataPath , MODULE_TEMPLATE_PATH ) ;
47
54
48
- return result . Replace ( "<version>" , version ) ;
55
+ return result . Replace ( VERSION_TAG , version ) ;
49
56
}
50
57
51
58
private static string GetProjectPath ( )
@@ -152,21 +159,11 @@ private static void WriteFile(string FileName, List<string> Lines )
152
159
}
153
160
}
154
161
155
- #if DEBUG_INSTALLER
156
- const string MenuItemName = "File/Install Maya2017 Integration" ;
157
- [ MenuItem ( MenuItemName , false ) ]
158
- public static void OnMenuItem ( )
159
- {
160
- InstallMaya2017 ( ) ;
161
- }
162
- #endif
163
-
164
- public static void InstallMaya2017 ( )
162
+ private static void _InstallMaya2017 ( bool verbose = true , bool commandsOnly = false )
165
163
{
166
- Debug . Log ( "Installing Maya2017 Integration" ) ;
167
-
168
164
// check if package installed
169
- string moduleTemplatePath = GetModuleTemplatePath ( "2017" ) ;
165
+ string moduleTemplatePath = GetModuleTemplatePath ( MAYA_VERSION ) ;
166
+ if ( verbose ) Debug . Log ( moduleTemplatePath ) ;
170
167
171
168
if ( ! System . IO . File . Exists ( moduleTemplatePath ) )
172
169
{
@@ -179,14 +176,16 @@ public static void InstallMaya2017()
179
176
// TODO: if not maya2017 installed warn user
180
177
181
178
// check for {USER} modules folder
182
- string modulePath = GetModulePath ( "2017" ) ;
183
- string moduleFilePath = System . IO . Path . Combine ( modulePath , "unityoneclick.mod" ) ;
179
+ string modulePath = GetModulePath ( MAYA_VERSION ) ;
180
+ if ( verbose ) Debug . Log ( modulePath ) ;
181
+
182
+ string moduleFilePath = System . IO . Path . Combine ( modulePath , MODULE_FILENAME ) ;
184
183
185
184
bool installed = false ;
186
185
187
186
if ( ! System . IO . Directory . Exists ( modulePath ) )
188
187
{
189
- Debug . Log ( string . Format ( "Creating Maya Modules Folder {0}" , modulePath ) ) ;
188
+ if ( verbose ) Debug . Log ( string . Format ( "Creating Maya Modules Folder {0}" , modulePath ) ) ;
190
189
191
190
try
192
191
{
@@ -217,9 +216,9 @@ public static void InstallMaya2017()
217
216
System . IO . File . Delete ( moduleFilePath ) ;
218
217
installed = false ;
219
218
}
220
- catch
219
+ catch
221
220
{
222
- Debug . LogError ( string . Format ( "Failed to delete plugin module file {0}" , moduleFilePath ) ) ;
221
+ Debug . LogWarning ( string . Format ( "Failed to delete plugin module file {0}" , moduleFilePath ) ) ;
223
222
}
224
223
}
225
224
}
@@ -229,14 +228,14 @@ public static void InstallMaya2017()
229
228
{
230
229
Dictionary < string , string > Tokens = new Dictionary < string , string > ( )
231
230
{
232
- { "{UnityOneClickVersion}" , GetPackageVersion ( ) } ,
233
- { "{UnityProject}" , GetProjectPath ( ) }
231
+ { VERSION_TAG , GetPackageVersion ( ) } ,
232
+ { PROJECT_TAG , GetProjectPath ( ) }
234
233
} ;
235
234
236
235
// parse template, replace "{UnityProject}" with project path
237
236
List < string > lines = ParseTemplateFile ( moduleTemplatePath , Tokens ) ;
238
237
239
- Debug . Log ( string . Format ( "Installing plugin module file: {0}" , moduleFilePath ) ) ;
238
+ if ( verbose ) Debug . Log ( string . Format ( "Installing plugin module file to {0}" , moduleFilePath ) ) ;
240
239
241
240
// write out .mod file
242
241
WriteFile ( moduleFilePath , lines ) ;
@@ -256,9 +255,47 @@ public static void InstallMaya2017()
256
255
// TODO: print message package already installed else where
257
256
}
258
257
258
+ if ( commandsOnly )
259
+ throw new NotImplementedException ( ) ;
260
+
259
261
// TODO: configure maya to auto-load plugin on next startup
260
262
261
- Debug . Log ( "Finished installing Maya 2017 Integration." ) ;
262
263
}
263
- }
264
+
265
+ public static void InstallMaya2017 ( )
266
+ {
267
+ bool verbose = true ;
268
+
269
+ Debug . Log ( string . Format ( "Installing Maya {0} Integration" , MAYA_VERSION ) ) ;
270
+
271
+ _InstallMaya2017 ( verbose ) ;
272
+
273
+ if ( verbose ) Debug . Log ( string . Format ( "Finished installing Maya {0} Integration." , MAYA_VERSION ) ) ;
274
+ }
275
+
276
+ public static void InstallMaya2017CommandsOnly ( )
277
+ {
278
+ bool verbose = true ;
279
+
280
+ Debug . Log ( string . Format ( "Installing Maya {0} Integration Commands Only" , MAYA_VERSION ) ) ;
281
+
282
+ _InstallMaya2017 ( verbose , true ) ;
283
+
284
+ if ( verbose ) Debug . Log ( string . Format ( "Finished installing Maya {0} Integration Commands Only." , MAYA_VERSION ) ) ;
285
+ }
286
+ }
287
+
288
+ namespace Editors
289
+ {
290
+ class IntegrationsUI
291
+ {
292
+ const string MenuItemName = "FbxExporters/Install Maya2017 Integration" ;
293
+
294
+ [ MenuItem ( MenuItemName , false , 0 ) ]
295
+ public static void OnMenuItem ( )
296
+ {
297
+ Integrations . InstallMaya2017 ( ) ;
298
+ }
299
+ }
300
+ }
264
301
}
0 commit comments