Skip to content

Commit c43a059

Browse files
authored
Merge pull request #136 from Unity-Technologies/UNI-23997-review-with-unity-open
Uni 23997 review with unity open
2 parents 8ae893e + 26b5a3f commit c43a059

File tree

9 files changed

+90
-16
lines changed

9 files changed

+90
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Executable + Temp files ##
22
*.exe
33
*.exe.*
4+
!BringToFront.exe
45
*.o
56
*.pdb
67
*.mdb

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Integrations
1616

1717
private const string FBX_EXPORT_SETTINGS_PATH = "Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel";
1818

19+
private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt";
20+
1921
public class MayaException : System.Exception {
2022
public MayaException() { }
2123
public MayaException(string message) : base(message) { }
@@ -177,8 +179,9 @@ static string AskVersion(string exePath) {
177179
#endif
178180

179181
private static string MAYA_COMMANDS { get {
180-
return string.Format("configureUnityOneClick {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {5}; scriptJob -idleEvent quit;",
181-
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(), GetExportSettingsPath(), (IsHeadlessInstall()?1:0));
182+
return string.Format("configureUnityOneClick {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6}; scriptJob -idleEvent quit;",
183+
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(),
184+
GetExportSettingsPath(), GetMayaInstructionPath(), (IsHeadlessInstall()?1:0));
182185
}}
183186
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
184187

@@ -251,6 +254,25 @@ public static string GetTempSavePath()
251254
return FbxExporters.Review.TurnTable.TempSavePath.Replace("\\", "/");
252255
}
253256

257+
/// <summary>
258+
/// Gets the maya instruction path relative to the Assets folder.
259+
/// Assets folder is not included in the path.
260+
/// </summary>
261+
/// <returns>The relative maya instruction path.</returns>
262+
public static string GetMayaInstructionPath()
263+
{
264+
return MAYA_INSTRUCTION_FILENAME;
265+
}
266+
267+
/// <summary>
268+
/// Gets the full maya instruction path as an absolute Unity path.
269+
/// </summary>
270+
/// <returns>The full maya instruction path.</returns>
271+
public static string GetFullMayaInstructionPath()
272+
{
273+
return Application.dataPath + "/" + FbxExporters.Editor.Integrations.GetMayaInstructionPath ();
274+
}
275+
254276
/// <summary>
255277
/// Gets the path to the export settings file.
256278
/// Returns a relative path with forward slashes as path separators.

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace FbxExporters
1212
namespace Review
1313
{
1414
[UnityEditor.InitializeOnLoad]
15-
public class TurnTable
15+
public class TurnTable : UnityEditor.AssetPostprocessor
1616
{
1717
const string DefaultScenesPath = "Assets";
1818
const string DefaultSceneName = "FbxExporters_TurnTableReview";
@@ -24,6 +24,25 @@ public class TurnTable
2424
static string LastFilePath = null;
2525
static Object LastModel = null;
2626

27+
static void OnPostprocessAllAssets(
28+
string[] importedAssets, string[] deletedAssets,
29+
string[] movedAssets, string[] movedFromAssetPaths)
30+
{
31+
// check if a turntable model was potentially imported
32+
var tempSavePath = "Assets/" + TempSavePath;
33+
foreach (var assetPath in importedAssets) {
34+
if (assetPath.StartsWith(tempSavePath) && assetPath.EndsWith(".fbx")) {
35+
// if the instruction file exists, then run the turntable and delete the file
36+
string instructionFile = FbxExporters.Editor.Integrations.GetFullMayaInstructionPath ();
37+
if(System.IO.File.Exists(instructionFile)){
38+
LastSavedModel ();
39+
System.IO.File.Delete (instructionFile);
40+
break;
41+
}
42+
}
43+
}
44+
}
45+
2746
private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string ext = ".fbx")
2847
{
2948
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo (directoryPath);
@@ -98,14 +117,9 @@ private static Object LoadModel (string fbxFileName)
98117
turntableGO = new GameObject ("TurnTableBase");
99118
turntableGO.AddComponent<FbxTurnTableBase> ();
100119
}
101-
102120
modelGO.transform.parent = turntableGO.transform;
103-
104-
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
105121
}
106122

107-
FrameCameraOnModel (modelGO);
108-
109123
return modelGO as Object;
110124
}
111125

@@ -124,6 +138,10 @@ private static Bounds GetRendererBounds(GameObject modelGO)
124138

125139
private static void FrameCameraOnModel(GameObject modelGO)
126140
{
141+
if (!modelGO) {
142+
return;
143+
}
144+
127145
// Set so camera frames model
128146
// Note: this code assumes the model is at 0,0,0
129147
Vector3 boundsSize = GetRendererBounds(modelGO).size;
@@ -155,6 +173,19 @@ private static void LoadLastSavedModel ()
155173
Debug.LogWarning (string.Format ("failed to load model : {0}", fbxFileName));
156174
}
157175
}
176+
177+
// focus onto model
178+
if (LastModel) {
179+
var model = LastModel as GameObject;
180+
if (model) {
181+
var turntable = model.transform.parent;
182+
if (turntable) {
183+
var turntableGO = turntable.gameObject;
184+
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
185+
FrameCameraOnModel (turntableGO);
186+
}
187+
}
188+
}
158189
}
159190

160191
public static void LastSavedModel ()

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public void BasicTest() {
4949
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
5050
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
5151
LogNonEmptyString("export settings path", Editor.Integrations.GetExportSettingsPath ());
52+
LogNonEmptyString ("instruction path", Editor.Integrations.GetMayaInstructionPath ());
53+
LogNonEmptyString ("full instruction path", Editor.Integrations.GetFullMayaInstructionPath ());
5254

5355
// test that the paths don't contain backslashes
5456
Assert.IsFalse(Editor.Integrations.GetAppPath().Contains("\\"));

Assets/Integrations/Autodesk/maya/scripts/configureUnityOneClick.mel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
global proc configureUnityOneClick(
22
string $unityProject, string $unityApp,
3-
string $unityTempSavePath, string $unityFbxExportSettings, int $headless)
3+
string $unityTempSavePath, string $unityFbxExportSettings,
4+
string $mayaInstructionPath, int $headless)
45
{
56
// configure plugin settings
67
optionVar -stringValue "UnityApp" $unityApp;
78
optionVar -stringValue "UnityProject" $unityProject;
89
optionVar -stringValue "UnityTempSavePath" $unityTempSavePath;
910
optionVar -stringValue "UnityFbxExportSettings" $unityFbxExportSettings;
11+
optionVar -stringValue "UnityInstructionPath" $mayaInstructionPath;
1012
optionVar -intValue "UnityOneClick_Headless" $headless;
1113

1214
// configure auto load of plugin

Assets/Integrations/Autodesk/maya/scripts/install_maya_plugin.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ else
5858
# Configure Maya Integration
5959
TEMP_SAVE_PATH="_safe_to_delete"
6060
EXPORT_SETTINGS_PATH="Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel"
61+
MAYA_INSTRUCTION_PATH="_safe_to_delete/_temp.txt"
6162
HEADLESS=1
6263

6364
# NOTE: we need start Maya in UI mode so that we can correctly configure the auto-load of the plugin.
64-
"${MAYA_PATH}" -command "configureUnityOneClick \"${PROJECT_PATH}\" \"${UNITY_EDITOR_PATH}\" \"${TEMP_SAVE_PATH}\" \"${EXPORT_SETTINGS_PATH}\" ${HEADLESS}; scriptJob -idleEvent quit;"
65+
"${MAYA_PATH}" -command "configureUnityOneClick \"${PROJECT_PATH}\" \"${UNITY_EDITOR_PATH}\" \"${TEMP_SAVE_PATH}\" \"${EXPORT_SETTINGS_PATH}\" \"${MAYA_INSTRUCTION_PATH}\" ${HEADLESS}; scriptJob -idleEvent quit;"
6566
fi
6667

6768
exit 0

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ def doIt(self, args):
270270
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
271271
unityTempSavePath = os.path.join(unityProjectPath, "Assets", maya.cmds.optionVar(q='UnityTempSavePath'))
272272
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
273+
if maya.cmds.optionVar(exists='UnityInstructionPath'):
274+
instructionFile = os.path.join(unityProjectPath, "Assets", maya.cmds.optionVar(q='UnityInstructionPath'))
275+
else:
276+
self.displayError("Missing Unity instruction file path, please re-install integration.")
277+
return
273278

274279
if not self.loadUnityFbxExportSettings():
275280
return
@@ -292,6 +297,10 @@ def doIt(self, args):
292297

293298
maya.cmds.file(savePath, force=True, options="", typ="FBX export", pr=True, es=True)
294299

300+
# create temp file in _safe_to_delete/
301+
with open(instructionFile,"w+") as f:
302+
pass
303+
295304
if maya.cmds.about(macOS=True):
296305
# Use 'open -a' to bring app to front if it has already been started.
297306
# Note that the unity command will not get called.
@@ -303,8 +312,10 @@ def doIt(self, args):
303312
.format(unityAppPath, unityProjectPath, unityCommand)
304313

305314
elif maya.cmds.about(windows=True):
306-
melCommand = r'system("start \"{0}\" \"{1}\" \"-projectPath {2} -executeMethod {3}\"");'\
307-
.format(unityProjectPath + "/Assets/Integrations/BringToFront.exe", unityAppPath, unityProjectPath, unityCommand)
315+
melCommand = r'system("start \"{0}\" \"{1}\" \"{2}\" \"-projectPath {3} -executeMethod {4}\"");'\
316+
.format(unityProjectPath + "/Assets/Integrations/BringToFront.exe",
317+
os.path.basename(unityProjectPath), unityAppPath,
318+
unityProjectPath, unityCommand)
308319

309320
else:
310321
raise NotImplementedError("missing platform implementation for {0}".format(maya.cmds.about(os=True)))

Assets/Integrations/BringToFront.exe

4.5 KB
Binary file not shown.

BringToFront.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ static void Main(string[] args)
4747
{
4848
if (!String.IsNullOrEmpty(process.MainWindowTitle))
4949
{
50+
if(args.Length > 0 && !process.MainWindowTitle.Contains(args[0]))
51+
{
52+
continue;
53+
}
5054
bringToFront(process.MainWindowTitle);
5155
found = true;
5256
}
5357
}
5458

55-
if(!found){
59+
if(!found && args.Length > 1){
5660
Process myProcess = new Process();
57-
myProcess.StartInfo.FileName = args[0];
58-
if(args.Length > 1){
59-
myProcess.StartInfo.Arguments = args[1];
61+
myProcess.StartInfo.FileName = args[1];
62+
if(args.Length > 2){
63+
myProcess.StartInfo.Arguments = args[2];
6064
}
6165
myProcess.Start();
6266
}

0 commit comments

Comments
 (0)