Skip to content

Commit a867da3

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into UNI-23240-bring-Unity-to-front-Windows
2 parents ed23583 + 5cd9fc1 commit a867da3

File tree

10 files changed

+415
-124
lines changed

10 files changed

+415
-124
lines changed

Assets/FbxExporters/Editor/FbxPrefabInspector.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ public class FbxPrefabInspector : UnityEditor.Editor {
88
public override void OnInspectorGUI() {
99
FbxPrefab fbxPrefab = (FbxPrefab)target;
1010

11+
// We can only change these settings when applied to a prefab.
12+
bool isDisabled = AssetDatabase.GetAssetPath(fbxPrefab) == "";
13+
if (isDisabled) {
14+
EditorGUILayout.HelpBox("Please select a prefab. You can't edit an instance in the scene.",
15+
MessageType.Info);
16+
}
17+
EditorGUI.BeginDisabledGroup(isDisabled);
18+
1119
fbxPrefab.SetAutoUpdate(EditorGUILayout.Toggle ("Auto-update:", fbxPrefab.WantsAutoUpdate()));
12-
if (!fbxPrefab.WantsAutoUpdate()) {
20+
if (!isDisabled && !fbxPrefab.WantsAutoUpdate()) {
1321
if (GUILayout.Button("Sync prefab to FBX")) {
1422
fbxPrefab.SyncPrefab();
1523
}
@@ -30,6 +38,8 @@ public override void OnInspectorGUI() {
3038
EditorGUILayout.SelectableLabel(fbxPrefab.GetFbxHistory().ToJson());
3139
GUILayout.EndHorizontal();
3240
#endif
41+
42+
EditorGUI.EndDisabledGroup();
3343
}
3444
}
3545
}

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 228 additions & 98 deletions
Large diffs are not rendered by default.

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class TurnTable
1212
const string ScenesPath = "Assets";
1313
const string SceneName = "FbxExporters_TurnTableReview";
1414

15+
public const string TempSavePath = "_safe_to_delete";
16+
1517
static string LastFilePath = null;
1618
static Object LastModel = null;
1719

@@ -50,7 +52,7 @@ private static string GetSceneFilePath ()
5052

5153
private static string GetLastSavedFilePath ()
5254
{
53-
string modelPath = FbxExporters.EditorTools.ExportSettings.GetAbsoluteSavePath ();
55+
string modelPath = FbxExporters.Editor.Integrations.GetTempSavePath ();
5456
System.IO.FileInfo fileInfo = GetLastSavedFile (modelPath);
5557

5658
return (fileInfo != null) ? fileInfo.FullName : null;
@@ -81,15 +83,32 @@ private static Object LoadModel (string fbxFileName)
8183
modelGO = UnityEditor.PrefabUtility.InstantiatePrefab (unityMainAsset) as GameObject;
8284

8385
GameObject turntableGO = GameObject.Find ("TurnTable");
84-
if (turntableGO!=null)
85-
{
86+
if (turntableGO != null) {
8687
modelGO.transform.parent = turntableGO.transform;
88+
turntableGO.AddComponent<RotateModel> ();
89+
} else {
90+
modelGO.AddComponent<RotateModel> ();
8791
}
8892
}
8993

94+
FrameCameraOnModel (modelGO);
95+
9096
return modelGO as Object;
9197
}
9298

99+
private static void FrameCameraOnModel(GameObject modelGO)
100+
{
101+
// Set so camera frames model
102+
// Note: this code assumes the model is at 0,0,0
103+
Vector3 boundsSize = modelGO.GetComponent<Renderer>().bounds.size;
104+
float distance = Mathf.Max(boundsSize.x, boundsSize.y, boundsSize.z);
105+
distance /= (2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad));
106+
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -distance * 2.0f);
107+
108+
// rotate camera towards model
109+
Camera.main.transform.LookAt(modelGO.transform.position);
110+
}
111+
93112
private static void LoadLastSavedModel ()
94113
{
95114
string fbxFileName = GetLastSavedFilePath ();
@@ -179,13 +198,46 @@ public static void LastSavedModel ()
179198
// make turntable the active scene
180199
UnityEngine.SceneManagement.SceneManager.SetActiveScene (scene);
181200

201+
// create camera and light if none
202+
if (Camera.main == null) {
203+
GameObject camera = new GameObject ("MainCamera");
204+
camera.AddComponent<Camera> ();
205+
camera.tag = "MainCamera";
206+
}
207+
208+
if(!Object.FindObjectOfType<Light>()){
209+
GameObject light = new GameObject ("Light");
210+
light.transform.localEulerAngles = new Vector3 (50, -30, 0);
211+
Light lightComp = light.AddComponent<Light> ();
212+
lightComp.type = LightType.Directional;
213+
lightComp.intensity = 1;
214+
lightComp.shadows = LightShadows.Soft;
215+
}
216+
217+
// maximize game window and start playing
218+
var gameWindow = GetMainGameView();
219+
if (gameWindow) {
220+
gameWindow.maximized = true;
221+
UnityEditor.EditorApplication.isPlaying = true;
222+
} else {
223+
Debug.LogWarning ("Failed to access Game Window, please restart Unity to try again.");
224+
}
225+
182226
if (AutoUpdateEnabled ()) {
183227
LoadLastSavedModel ();
184228

185229
SubscribeToEvents ();
186230
}
187231
}
188232

233+
public static UnityEditor.EditorWindow GetMainGameView()
234+
{
235+
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
236+
System.Type type = assembly.GetType("UnityEditor.GameView");
237+
UnityEditor.EditorWindow gameview = UnityEditor.EditorWindow.GetWindow(type, false, null, true);
238+
return gameview;
239+
}
240+
189241
private static void SubscribeToEvents ()
190242
{
191243
// ensure we only subscribe once
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System.IO;
4+
using System.Collections.Generic;
5+
using NUnit.Framework;
6+
7+
namespace FbxExporters.UnitTests
8+
{
9+
public class IntegrationsTest {
10+
string m_oldMayaLocation;
11+
12+
[SetUp]
13+
public void ClearEnv() {
14+
m_oldMayaLocation = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
15+
System.Environment.SetEnvironmentVariable("MAYA_LOCATION", null);
16+
}
17+
18+
[TearDown]
19+
public void ResetEnv() {
20+
System.Environment.SetEnvironmentVariable("MAYA_LOCATION", m_oldMayaLocation);
21+
}
22+
23+
void LogNonEmptyString(string name, string str) {
24+
Debug.Log(name + ": " + str);
25+
Assert.IsFalse(string.IsNullOrEmpty(str));
26+
}
27+
28+
[Test]
29+
public void BasicTest() {
30+
// Note: This test assumes that Maya is actually installed in a default location.
31+
Assert.IsTrue(Directory.Exists(Editor.Integrations.MayaVersion.AdskRoot));
32+
33+
var maya = new Editor.Integrations.MayaVersion();
34+
35+
LogNonEmptyString("location", maya.Location);
36+
LogNonEmptyString("binary ", maya.MayaExe);
37+
LogNonEmptyString("version ", maya.Version);
38+
39+
Assert.IsFalse(Editor.Integrations.IsHeadlessInstall());
40+
41+
LogNonEmptyString("module path (2017)", Editor.Integrations.GetModulePath("2017"));
42+
LogNonEmptyString("module template path (2017)", Editor.Integrations.GetModuleTemplatePath("2017"));
43+
Assert.That( () => Editor.Integrations.GetModuleTemplatePath("bad version"),
44+
Throws.Exception.TypeOf<Editor.Integrations.MayaException>());
45+
46+
LogNonEmptyString("app path", Editor.Integrations.GetAppPath());
47+
LogNonEmptyString("project path", Editor.Integrations.GetProjectPath());
48+
LogNonEmptyString("package path", Editor.Integrations.GetPackagePath());
49+
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
50+
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
51+
}
52+
}
53+
}

Assets/FbxExporters/README.txt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@ Requirements
1111

1212
* [FBX SDK C# Bindings](https://github.com/Unity-Technologies/FbxSharp)
1313

14-
Command-line Installing Maya2017 Integration
14+
Installing Maya Integration
1515
--------------------------------------------
1616

17-
You can install the package and integrations from the command-line using the following script:
17+
The easy way to install the Maya integration is with the
18+
FbxExporters -> Install Maya Integration
19+
menu option in Unity.
20+
21+
It uses the most recent version of Maya it can find. Set your MAYA_LOCATION
22+
environment before running Unity if you want to specify a particular version of Maya.
23+
24+
25+
Alternately, you can install the package and integrations from the command-line
26+
using the following script:
27+
1828

1929
MacOS:
2030

2131
# Configure where Unity is installed
22-
if [ ! -f "${UNITY3D_PATH}" ]; then
23-
UNITY3D_PATH="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
32+
if [ ! -d "${UNITY3D_PATH}" ]; then
33+
UNITY3D_PATH="/Applications/Unity/Unity.app"
2434
fi
2535

2636
# Configure which Unity project to install package
@@ -33,23 +43,24 @@ if [ ! -f "${PACKAGE_PATH}" ]; then
3343
PACKAGE_PATH=`ls -t ${PROJECT_PATH}/FbxExporters_*.unitypackage | head -1`
3444
fi
3545

36-
if [ ! -f "${UNITY3D_PATH}" ]; then
46+
# Configuring Maya2017 to auto-load integration
47+
if [ ! -d "${MAYA_LOCATION}" ] ; then
48+
MAYA_LOCATION=/Applications/Autodesk/maya2017/Maya.app
49+
fi
50+
export MAYA_LOCATION
51+
52+
if [ ! -d "${UNITY3D_PATH}" ]; then
3753
echo "Unity is not installed"
54+
elif [ ! -d "${MAYA_LOCATION}" ] ; then
55+
echo "Maya is not installed"
3856
else
3957
# Install FbxExporters package
40-
"${UNITY3D_PATH}" -projectPath "${PROJECT_PATH}" -importPackage ${PACKAGE_PATH} -quit
41-
42-
# Install Maya2017 Integration
43-
"${UNITY3D_PATH}" -batchMode -projectPath "${PROJECT_PATH}" -executeMethod FbxExporters.Integrations.InstallMaya2017 -quit
58+
"${UNITY3D_PATH}/Contents/MacOS/Unity" -projectPath "${PROJECT_PATH}" -importPackage ${PACKAGE_PATH} -quit
4459

45-
# Configuring Maya2017 to auto-load integration
46-
MAYA_PATH=/Applications/Autodesk/maya2017/Maya.app/Contents/bin/maya
60+
# Install Maya Integration. Requires MAYA_LOCATION.
61+
"${UNITY3D_PATH}/Contents/MacOS/Unity" -batchMode -projectPath "${PROJECT_PATH}" -executeMethod FbxExporters.Integrations.InstallMaya -quit
4762

48-
if [ ! -f "${MAYA_PATH}" ]; then
49-
echo "Maya2017 not installed"
50-
else
51-
# To configure without user interface change the last argument to 1 instead of 0
52-
"${MAYA_PATH}" -command "configureUnityOneClick \"${PROJECT_PATH}\" \"${UNITY3D_PATH}\" 0; scriptJob -idleEvent quit;"
53-
fi
63+
# To configure without user interface change the last argument to 1 instead of 0
64+
"${MAYA_LOCATION}/Contents/MacOS/Maya" -command "configureUnityOneClick \"${PROJECT_PATH}\" \"${UNITY3D_PATH}\" 0; scriptJob -idleEvent quit;"
5465
fi
5566

Assets/FbxExporters/RotateModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class RotateModel : MonoBehaviour {
6+
7+
[Tooltip("Rotation speed in degrees/second")]
8+
[SerializeField]
9+
private float speed = 10f;
10+
11+
void Update () {
12+
transform.Rotate (Vector3.up, speed * Time.deltaTime, Space.World);
13+
}
14+
}

Assets/Integrations/Autodesk/maya2017/README.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@
1313
#
1414
########################################################################
1515

16+
Automatic Installation
17+
===================
18+
19+
The easiest installation method is to launch Unity and use the
20+
FbxExporters -> Install Maya Integration
21+
option.
22+
23+
It will choose the most recent version of Maya installed in the default
24+
installation location. To choose a particular version of Maya or to handle
25+
non-default installation locations, set the MAYA_LOCATION environment variable.
26+
1627
Manual Installation
1728
===================
1829

1930
Instructions for installing if you don't use the unity package installer
20-
and your installing in a none-default location.
31+
and your installing in a non-default location.
2132

2233
1. copy unityoneclick.mod to user folder
2334

2435
MacOS & Ubuntu: ~/MayaProjects/modules
2536
Windows: C:\Program Files\Autodesk\Maya2017\modules
26-
37+
2738
2. configure path within unityoneclick.mod to point to integration installation folder
2839

2940
{UnityProject}/Assets/Integrations/Autodesk/maya2017
@@ -42,4 +53,4 @@ export PYTHONPATH=${MAYA_INTEGRATION_PATH}/scripts
4253
${MAYAPY_PATH} ${MAYA_INTEGRATION_PATH}/scripts/run_all_tests.py
4354

4455
# run one test
45-
${MAYAPY_PATH} ${MAYA_INTEGRATION_PATH}/scripts/unityOneClick/commands.py
56+
${MAYAPY_PATH} ${MAYA_INTEGRATION_PATH}/scripts/unityOneClick/commands.py

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
global proc configureUnityOneClick(string $unityProject, string $unityApp, int $headless)
1+
global proc configureUnityOneClick(string $unityProject, string $unityApp, string $unityTempSavePath, int $headless)
22
{
33
// configure plugin settings
44
optionVar -stringValue "UnityApp" $unityApp;
55
optionVar -stringValue "UnityProject" $unityProject;
6+
optionVar -stringValue "UnityTempSavePath" $unityTempSavePath;
67
optionVar -intValue "UnityOneClick_Headless" $headless;
78

89
// configure auto load of plugin

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,17 @@ def doIt(self, args):
129129

130130
unityAppPath = maya.cmds.optionVar(q='UnityApp')
131131
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
132+
unityTempSavePath = maya.cmds.optionVar(q='UnityTempSavePath')
132133
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
133134

135+
# make sure the GamePipeline and fbxmaya plugins are loaded
136+
if self.loadDependencies() and self.loadPlugin('fbxmaya.mll'):
137+
# save fbx to Assets/_safe_to_delete/
138+
savePath = unityTempSavePath
139+
maya.cmds.sysFile(savePath, makeDir=True)
140+
savePath = savePath + "/TurnTableModel.fbx"
141+
maya.mel.eval(r'file -force -options "" -typ "FBX export" -pr -es "{0}"'.format(savePath));
142+
134143
if maya.cmds.about(macOS=True):
135144
# Use 'open -a' to bring app to front if it has already been started.
136145
# Note that the unity command will not get called.

Assets/Integrations/Autodesk/maya2017/unityoneclick.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
#
1414
########################################################################
1515

16-
+ MAYAVERSION:2017 unityoneclick {Version} {UnityProject}/Assets/Integrations/Autodesk/maya2017
16+
+ unityoneclick {Version} {UnityProject}/Assets/Integrations/Autodesk/maya2017

0 commit comments

Comments
 (0)