// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Description: // Export Asset to Unity project // global proc GamePipelineSendToUnity(int $exportSelectionOnly) { global string $gDirRetainingOptionVar; string $unityAssetRoot = `optionVar -query "UnityProject"` + "/Assets"; sysFile -makeDir $unityAssetRoot; string $workspace = `workspace -q -fullName`; loadPlugin -quiet fbxmaya; setWorkingDirectory $workspace "mayaBinary" "scene"; // cache current working directory $currentDir = `optionVar -q $gDirRetainingOptionVar`; // use Unity asset root as the current working directory // or use the previous visited Unity asset folder as the current working directory string $unityPath = $unityAssetRoot; if (`optionVar -exists "UnityAsset"`) { string $unityAssetDir = `optionVar -query "UnityAsset"`; if (`startsWith $unityAssetDir $unityAssetRoot`) { $unityPath = $unityAssetDir; } } retainWorkingDirectory($unityPath); // Default to FBX export unless the user has chosen something else. string $unityExportType = "FBX export"; string $normalExportType = ""; if (`optionVar -exists UnityExportFileType`) { $unityExportType = `optionVar -q UnityExportFileType`; } // The Export dialogs get their default file type from optionVars. We // temporarily override the relevant var to use our preferred type for // Unity. string $normalExportVar = "defaultFileExportAllType"; if ( $exportSelectionOnly ) { $normalExportVar = "defaultFileExportActiveType"; } if (`optionVar -exists $normalExportVar`) { $normalExportType = `optionVar -q $normalExportVar`; } optionVar -sv $normalExportVar $unityExportType; if ( $exportSelectionOnly ) { ExportSelection; } else { Export; } // The normal export optionVar will now contain whatever file type the user // selected. Let's move that into the Unity-specific optionVar. $unityExportType = `optionVar -q $normalExportVar`; optionVar -sv UnityExportFileType $unityExportType; // Restore the original value/state of the normal optionVar. if ($normalExportType != "") { optionVar -sv $normalExportVar $normalExportType; } else { optionVar -rm $normalExportVar; } // store the current asset folder string $currentAssetDir = `optionVar -q $gDirRetainingOptionVar`; optionVar -stringValue "UnityAsset" $currentAssetDir; // restore the workspace directory retainWorkingDirectory($currentDir); }