Skip to content

Commit ec1664b

Browse files
committed
set Unity project on import where applicable
1 parent 2554f2b commit ec1664b

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,17 @@ public static string GetPackagePath()
248248

249249
public static string GetTempSavePath()
250250
{
251-
return System.IO.Path.Combine(Application.dataPath, FbxExporters.Review.TurnTable.TempSavePath).Replace("\\", "/");
251+
return FbxExporters.Review.TurnTable.TempSavePath.Replace("\\", "/");
252252
}
253253

254254
/// <summary>
255255
/// Gets the path to the export settings file.
256-
/// Returns an absolute path with forward slashes as path separators.
256+
/// Returns a relative path with forward slashes as path separators.
257257
/// </summary>
258258
/// <returns>The export settings path.</returns>
259259
public static string GetExportSettingsPath()
260260
{
261-
return Application.dataPath + '/' + FBX_EXPORT_SETTINGS_PATH;
261+
return FBX_EXPORT_SETTINGS_PATH;
262262
}
263263

264264
public static string GetPackageVersion()

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static string GetSceneFilePath ()
6161

6262
private static string GetLastSavedFilePath ()
6363
{
64-
string modelPath = FbxExporters.Editor.Integrations.GetTempSavePath ();
64+
string modelPath = Application.dataPath + "/" + TempSavePath;
6565
System.IO.FileInfo fileInfo = GetLastSavedFile (modelPath);
6666

6767
return (fileInfo != null) ? fileInfo.FullName : null;

Assets/Integrations/Autodesk/maya2017/scripts/unityOneClick/commands.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def loadUnityFbxExportSettings(self):
6464
"""
6565
Load the Export Settings from file
6666
"""
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"))
6869
if not os.path.isfile(fileName):
6970
maya.cmds.error("Failed to find Unity Fbx Export Settings at: {0}".format(fileName))
7071
return False
@@ -149,6 +150,18 @@ def beforeImport(self, retCode, file, clientData):
149150
def afterImport(self, *args, **kwargs):
150151
if self._tempPath:
151152
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+
152165
if self._tempName:
153166
self.storeAttribute(self._exportSet, self._unityFbxFileNameAttr, self._tempName)
154167

@@ -218,7 +231,7 @@ def doIt(self, args):
218231

219232
unityAppPath = maya.cmds.optionVar(q='UnityApp')
220233
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'))
222235
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
223236

224237
if not self.loadUnityFbxExportSettings():

0 commit comments

Comments
 (0)