@@ -389,4 +389,99 @@ public static void InstallMayaIntegration ()
389
389
UnityEditor . EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
390
390
}
391
391
}
392
+
393
+ class MaxIntegration
394
+ {
395
+ // get version of Max
396
+ // find 3dsmax.ini file (in the AppData)
397
+ // get startup path from .ini file
398
+ // copy .ms file to startup path
399
+
400
+ //private const string MaxIni = "3dsmax.ini";
401
+ private const string PluginName = "unityOneClickPlugin.ms" ;
402
+ private const string PluginPath = "Integrations/Autodesk/max/scripts/" + PluginName ;
403
+ //private const string InstallMaxScript = "Integrations/Autodesk/max/scripts/unityPluginInstall.ms";
404
+
405
+ private const string InstallMaxScriptTemplate =
406
+ @"startupScriptPath = pathConfig.GetDir(#userStartupScripts);" +
407
+ @"copyFile \""{UnityPluginScript_Source}\"" (startupScriptPath + \""/{UnityPluginScript_Name}\"")" ;
408
+
409
+ private const string PluginSourceTag = "{UnityPluginScript_Source}" ;
410
+ private const string PluginNameTag = "{UnityPluginScript_Name}" ;
411
+
412
+ // TODO: get this from the export settings
413
+ private static string GetMaxExe ( ) {
414
+ return "C:/Program Files/Autodesk/3ds Max 2017/3dsmax.exe" ;
415
+ }
416
+
417
+ private static string GetInstallScript ( ) {
418
+ Dictionary < string , string > Tokens = new Dictionary < string , string > ( )
419
+ {
420
+ { PluginSourceTag , Application . dataPath + "/" + PluginPath } ,
421
+ { PluginNameTag , PluginName }
422
+ } ;
423
+
424
+ var installScript = InstallMaxScriptTemplate ;
425
+ foreach ( var t in Tokens ) {
426
+ installScript = installScript . Replace ( t . Key , t . Value ) ;
427
+ }
428
+ return installScript ;
429
+ }
430
+
431
+ public static int InstallMaxPlugin ( ) {
432
+ var maxExe = GetMaxExe ( ) ;
433
+ var installScript = GetInstallScript ( ) ;
434
+
435
+ int ExitCode = 0 ;
436
+
437
+ try {
438
+ if ( ! System . IO . File . Exists ( maxExe ) )
439
+ {
440
+ Debug . LogError ( string . Format ( "No 3DsMax installation found at {0}" , maxExe ) ) ;
441
+ return - 1 ;
442
+ }
443
+
444
+ System . Diagnostics . Process myProcess = new System . Diagnostics . Process ( ) ;
445
+ myProcess . StartInfo . FileName = maxExe ;
446
+ myProcess . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
447
+ myProcess . StartInfo . CreateNoWindow = true ;
448
+ myProcess . StartInfo . UseShellExecute = false ;
449
+
450
+ #if UNITY_EDITOR_OSX
451
+ throw new NotImplementedException ( ) ;
452
+ #elif UNITY_EDITOR_LINUX
453
+ throw new NotImplementedException ( ) ;
454
+ #else // UNITY_EDITOR_WINDOWS
455
+ myProcess . StartInfo . Arguments = string . Format ( "-q -silent -mxs \" {0}\" " , installScript ) ;
456
+ #endif
457
+ myProcess . EnableRaisingEvents = true ;
458
+
459
+ Debug . Log ( "args: " + myProcess . StartInfo . Arguments ) ;
460
+
461
+ myProcess . Start ( ) ;
462
+ myProcess . WaitForExit ( ) ;
463
+ ExitCode = myProcess . ExitCode ;
464
+ Debug . Log ( string . Format ( "Ran max: [{0}]\n With args [{1}]\n Result {2}" ,
465
+ maxExe , myProcess . StartInfo . Arguments , ExitCode ) ) ;
466
+ }
467
+ catch ( Exception e )
468
+ {
469
+ UnityEngine . Debug . LogError ( string . Format ( "Exception failed to start Max ({0})" , e . Message ) ) ;
470
+ ExitCode = - 1 ;
471
+ }
472
+ return ExitCode ;
473
+ }
474
+
475
+ /*private string AppDataPath{
476
+ get{
477
+ return Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
478
+ }
479
+ }
480
+
481
+ //C:/Users/Viktoria/AppData/Local/Autodesk/3dsMax/2017 - 64bit/ENU
482
+ private string GetMaxIniPath(){
483
+ var appData = AppDataPath;
484
+ return null;
485
+ }*/
486
+ }
392
487
}
0 commit comments