@@ -64,7 +64,8 @@ def loadUnityFbxExportSettings(self):
64
64
"""
65
65
Load the Export Settings from file
66
66
"""
67
- fileName = maya .cmds .optionVar (q = "UnityFbxExportSettings" )
67
+ projectPath = maya .cmds .optionVar (q = "UnityProject" )
68
+ fileName = "{0}/Assets/{1}" .format (projectPath , maya .cmds .optionVar (q = "UnityFbxExportSettings" ))
68
69
if not os .path .isfile (fileName ):
69
70
maya .cmds .error ("Failed to find Unity Fbx Export Settings at: {0}" .format (fileName ))
70
71
return False
@@ -149,6 +150,18 @@ def beforeImport(self, retCode, file, clientData):
149
150
def afterImport (self , * args , ** kwargs ):
150
151
if self ._tempPath :
151
152
self .storeAttribute (self ._exportSet , self ._unityFbxFilePathAttr , self ._tempPath )
153
+
154
+ # Change Unity project if fbx is from a different Unity project.
155
+ # Get the project based on the folder structure (i.e. folder above Assets)
156
+ splitPath = os .path .split (self ._tempPath )
157
+ # Check that we are not at the root directory.
158
+ while len (splitPath ) == 2 and splitPath [0 ] and os .path .dirname (splitPath [0 ]) != splitPath [0 ]:
159
+ if splitPath [1 ] == "Assets" and os .path .exists (splitPath [0 ]):
160
+ # this is a valid Unity project, so set it
161
+ maya .cmds .optionVar (sv = ('UnityProject' , splitPath [0 ]))
162
+ break
163
+ splitPath = os .path .split (splitPath [0 ])
164
+
152
165
if self ._tempName :
153
166
self .storeAttribute (self ._exportSet , self ._unityFbxFileNameAttr , self ._tempName )
154
167
@@ -218,7 +231,7 @@ def doIt(self, args):
218
231
219
232
unityAppPath = maya .cmds .optionVar (q = 'UnityApp' )
220
233
unityProjectPath = maya .cmds .optionVar (q = 'UnityProject' )
221
- unityTempSavePath = maya .cmds .optionVar (q = 'UnityTempSavePath' )
234
+ unityTempSavePath = "{0}/Assets/{1}" . format ( unityProjectPath , maya .cmds .optionVar (q = 'UnityTempSavePath' ) )
222
235
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
223
236
224
237
if not self .loadUnityFbxExportSettings ():
0 commit comments