Skip to content

Commit 4cba5f6

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into UNI-24203-remove-version-from-integration-folder
2 parents 1b62b8e + be76223 commit 4cba5f6

File tree

6 files changed

+85
-47
lines changed

6 files changed

+85
-47
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ public override void OnInspectorGUI() {
9898
);
9999

100100
GUILayout.EndHorizontal ();
101+
102+
EditorGUILayout.Space ();
103+
if (GUILayout.Button (new GUIContent ("Auto Review",
104+
"Opens turntable review of last saved prefab."))) {
105+
FbxExporters.Review.TurnTable.LastSavedModel ();
106+
}
107+
108+
EditorGUILayout.Space ();
109+
if (GUILayout.Button ("Install Maya Integration")) {
110+
FbxExporters.Editor.IntegrationsUI.InstallMayaIntegration ();
111+
}
112+
101113
GUILayout.FlexibleSpace ();
102114
GUILayout.EndScrollView ();
103115

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ private static string MAYA_COMMANDS { get {
185185
private const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
186186

187187
#if UNITY_EDITOR_OSX
188-
private const string MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/"+VERSION_TAG+"/modules";
188+
private const string MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/modules";
189189
#elif UNITY_EDITOR_LINUX
190-
private const string MAYA_MODULES_PATH = "Maya/"+VERSION_TAG+"/modules";
190+
private const string MAYA_MODULES_PATH = "Maya/modules";
191191
#else
192-
private const string MAYA_MODULES_PATH = "maya/"+VERSION_TAG+"/modules";
192+
private const string MAYA_MODULES_PATH = "maya/modules";
193193
#endif
194194

195195
private static string GetUserFolder()
@@ -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()
@@ -499,32 +499,26 @@ public static bool InstallMaya(MayaVersion version = null, bool verbose = false)
499499
}
500500
}
501501

502-
namespace Editors
502+
class IntegrationsUI
503503
{
504-
class IntegrationsUI
504+
public static void InstallMayaIntegration ()
505505
{
506-
const string MenuItemName1 = "FbxExporters/Install Maya Integration";
507-
508-
[MenuItem (MenuItemName1, false, 0)]
509-
public static void OnMenuItem1 ()
510-
{
511-
var mayaVersion = new Integrations.MayaVersion();
512-
if (!Integrations.InstallMaya(mayaVersion, verbose: true)) {
513-
return;
514-
}
506+
var mayaVersion = new Integrations.MayaVersion();
507+
if (!Integrations.InstallMaya(mayaVersion, verbose: true)) {
508+
return;
509+
}
515510

516-
int exitCode = Integrations.ConfigureMaya (mayaVersion);
511+
int exitCode = Integrations.ConfigureMaya (mayaVersion);
517512

518-
string title, message;
519-
if (exitCode != 0) {
520-
title = string.Format("Failed to install Maya {0} Integration.", mayaVersion.Version);
521-
message = string.Format("Failed to configure Maya, please check logs (exitcode={0}).", exitCode);
522-
} else {
523-
title = string.Format("Completed installation of Maya {0} Integration.", mayaVersion.Version);
524-
message = string.Format("Enjoy the new \"Unity\" menu in Maya {0}.", mayaVersion.Version);
525-
}
526-
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
513+
string title, message;
514+
if (exitCode != 0) {
515+
title = string.Format("Failed to install Maya {0} Integration.", mayaVersion.Version);
516+
message = string.Format("Failed to configure Maya, please check logs (exitcode={0}).", exitCode);
517+
} else {
518+
title = string.Format("Completed installation of Maya {0} Integration.", mayaVersion.Version);
519+
message = string.Format("Enjoy the new \"Unity\" menu in Maya {0}.", mayaVersion.Version);
527520
}
521+
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
528522
}
529523
}
530524
}

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace Review
1414
[UnityEditor.InitializeOnLoad]
1515
public class TurnTable
1616
{
17-
const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab";
18-
1917
const string DefaultScenesPath = "Assets";
2018
const string DefaultSceneName = "FbxExporters_TurnTableReview";
2119

@@ -26,12 +24,6 @@ public class TurnTable
2624
static string LastFilePath = null;
2725
static Object LastModel = null;
2826

29-
[UnityEditor.MenuItem (MenuItemName, false, 10)]
30-
public static void OnMenu ()
31-
{
32-
LastSavedModel ();
33-
}
34-
3527
private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string ext = ".fbx")
3628
{
3729
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo (directoryPath);
@@ -59,9 +51,14 @@ private static string GetSceneFilePath ()
5951
return System.IO.Path.Combine (DefaultScenesPath, DefaultSceneName + ".unity");
6052
}
6153

54+
/// <summary>
55+
/// Gets the last saved file path as a Unity-style (only forward slashes)
56+
/// absolute path.
57+
/// </summary>
58+
/// <returns>The last saved file path.</returns>
6259
private static string GetLastSavedFilePath ()
6360
{
64-
string modelPath = FbxExporters.Editor.Integrations.GetTempSavePath ();
61+
string modelPath = Application.dataPath + "/" + TempSavePath;
6562
System.IO.FileInfo fileInfo = GetLastSavedFile (modelPath);
6663

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

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void TestGetSetFields()
165165
Path.DirectorySeparatorChar);
166166

167167
var defaultAbsolutePath = ExportSettings.GetAbsoluteSavePath();
168-
var dataPath = Path.Combine(appDataPath, ExportSettings.kDefaultSavePath);
168+
var dataPath = Path.GetFullPath(Path.Combine(appDataPath, ExportSettings.kDefaultSavePath));
169169
Assert.AreEqual(dataPath, defaultAbsolutePath);
170170

171171
// set; check that the saved value is platform-independent,

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

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,25 @@ def loadPlugin(self, plugin):
5858
return True
5959

6060
def loadDependencies(self):
61-
return self.loadPlugin('GamePipeline.mll') and self.loadPlugin('fbxmaya.mll')
61+
# GamePipeline plugin 'SendToUnitySelection' command used in Publish
62+
pluginsToLoad = ['GamePipeline', 'fbxmaya']
63+
64+
ext = "mll"
65+
if maya.cmds.about(macOS=True):
66+
ext = "bundle"
67+
68+
# iterate over all the plugins, loading them with extenstion ext, and combining the results
69+
# to return if any of the loads failed
70+
return reduce((lambda result, plugin: result and self.loadPlugin("{0}.{1}".format(plugin, ext))),
71+
pluginsToLoad,
72+
True)
6273

6374
def loadUnityFbxExportSettings(self):
6475
"""
6576
Load the Export Settings from file
6677
"""
67-
fileName = maya.cmds.optionVar(q="UnityFbxExportSettings")
78+
projectPath = maya.cmds.optionVar(q="UnityProject")
79+
fileName = os.path.join(projectPath,"Assets", maya.cmds.optionVar(q="UnityFbxExportSettings"))
6880
if not os.path.isfile(fileName):
6981
maya.cmds.error("Failed to find Unity Fbx Export Settings at: {0}".format(fileName))
7082
return False
@@ -135,9 +147,6 @@ def beforeImport(self, retCode, file, clientData):
135147
if not self.setExists(self._exportSet):
136148
# couldn't find export set so create it
137149
maya.cmds.sets(name=self._exportSet)
138-
else:
139-
# remove all items from set
140-
maya.cmds.sets(clear=self._exportSet)
141150

142151
# reset attribute values, in case import fails
143152
self.storeAttribute(self._exportSet, self._unityFbxFilePathAttr, "")
@@ -149,19 +158,41 @@ def beforeImport(self, retCode, file, clientData):
149158
def afterImport(self, *args, **kwargs):
150159
if self._tempPath:
151160
self.storeAttribute(self._exportSet, self._unityFbxFilePathAttr, self._tempPath)
161+
162+
# Change Unity project if fbx is from a different Unity project.
163+
# Get the project based on the folder structure (i.e. folder above Assets)
164+
head,tail = os.path.split(self._tempPath)
165+
# Check that we are not at the root directory.
166+
# os.path.dirname(head) returns the last directory name in the path,
167+
# or head if head is the root directory.
168+
while head and os.path.dirname(head) != head:
169+
if tail == "Assets":
170+
# this is a valid Unity project, so set it
171+
maya.cmds.optionVar(sv=('UnityProject', head))
172+
break
173+
head,tail = os.path.split(head)
174+
152175
if self._tempName:
153176
self.storeAttribute(self._exportSet, self._unityFbxFileNameAttr, self._tempName)
154177

155178
if self.setExists(self._exportSet):
156179
# figure out what has been added after import
157180
itemsInScene = maya.cmds.ls(tr=True, o=True, r=True)
181+
158182
newItems = list(set(itemsInScene) - set(self._origItemsInScene))
159183

160184
# add newly imported items to set
161-
maya.cmds.sets(newItems, add=self._exportSet)
185+
if len(newItems) > 0:
186+
maya.cmds.sets(newItems, include=self._exportSet)
162187

163188
def doIt(self, args):
164189
self.loadDependencies()
190+
191+
# set Unity project as the current workspace
192+
currWorkspace = maya.cmds.workspace(o=True, q=True)
193+
unityProject = maya.cmds.optionVar(q='UnityProject')
194+
if unityProject:
195+
maya.cmds.workspace(unityProject, o=True)
165196

166197
self._tempPath = None
167198
self._tempName = None
@@ -176,6 +207,9 @@ def doIt(self, args):
176207

177208
OpenMaya.MMessage.removeCallback(callbackId)
178209
OpenMaya.MMessage.removeCallback(callbackId2)
210+
211+
if currWorkspace:
212+
maya.cmds.workspace(currWorkspace, o=True)
179213

180214
@classmethod
181215
def invoke(cls):
@@ -218,7 +252,7 @@ def doIt(self, args):
218252

219253
unityAppPath = maya.cmds.optionVar(q='UnityApp')
220254
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
221-
unityTempSavePath = maya.cmds.optionVar(q='UnityTempSavePath')
255+
unityTempSavePath = os.path.join(unityProjectPath, "Assets", maya.cmds.optionVar(q='UnityTempSavePath'))
222256
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
223257

224258
if not self.loadUnityFbxExportSettings():
@@ -236,8 +270,10 @@ def doIt(self, args):
236270
# save fbx to Assets/_safe_to_delete/
237271
savePath = unityTempSavePath
238272
maya.cmds.sysFile(savePath, makeDir=True)
239-
savePath = savePath + "/TurnTableModel.fbx"
240-
maya.mel.eval(r'file -force -options "" -typ "FBX export" -pr -es "{0}"'.format(savePath));
273+
savePath = os.path.join(savePath, "TurnTableModel.fbx")
274+
savePath = os.path.abspath(savePath)
275+
276+
maya.cmds.file(savePath, force=True, options="", typ="FBX export", pr=True, es=True)
241277

242278
if maya.cmds.about(macOS=True):
243279
# Use 'open -a' to bring app to front if it has already been started.

Assets/Integrations/Autodesk/maya/scripts/unityOneClick/ui.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def installMenu():
5959
maya.cmds.menuItem(parent=kMainWndMenuName, label=commands.importCmd.kShortLabel, command=commands.importCmd.kScriptCommand) # @UndefinedVariable
6060
maya.cmds.menuItem(parent=kMainWndMenuName, label=commands.reviewCmd.kShortLabel, command=commands.reviewCmd.kScriptCommand) # @UndefinedVariable
6161
maya.cmds.menuItem(parent=kMainWndMenuName, label=commands.publishCmd.kShortLabel, command=commands.publishCmd.kScriptCommand) # @UndefinedVariable
62-
maya.cmds.menuItem(parent=kMainWndMenuName, label=commands.configureCmd.kShortLabel, command=commands.configureCmd.kScriptCommand) # @UndefinedVariable
6362

6463
def uninstallMenu():
6564
"""

0 commit comments

Comments
 (0)