Skip to content

Commit e7ed39d

Browse files
committed
hook up playable director export to UI
1 parent 989cfa8 commit e7ed39d

File tree

4 files changed

+94
-53
lines changed

4 files changed

+94
-53
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ConvertToPrefabEditorWindow : ExportOptionsEditorWindow
2121
public static void Init (IEnumerable<GameObject> toConvert)
2222
{
2323
ConvertToPrefabEditorWindow window = CreateWindow<ConvertToPrefabEditorWindow> ();
24-
window.InitializeWindow (filename: "", singleHierarchyExport: true, isTimelineAnim: false);
24+
window.InitializeWindow ();
2525
window.SetGameObjectsToConvert (toConvert);
2626
window.Show ();
2727
}

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
2626
protected virtual GUIContent WindowTitle { get { return new GUIContent (DefaultWindowTitle); } }
2727

2828
protected string m_exportFileName = "";
29-
protected bool m_isTimelineAnim = false;
30-
protected bool m_singleHierarchyExport = true;
3129

3230
protected UnityEditor.Editor m_innerEditor;
3331
protected FbxExportPresetSelectorReceiver m_receiver;
@@ -62,15 +60,9 @@ protected static T CreateWindow<T>() where T : EditorWindow {
6260
return (T)EditorWindow.GetWindow <T>(DefaultWindowTitle, focus:true);
6361
}
6462

65-
protected virtual void InitializeWindow(string filename = "", bool singleHierarchyExport = true, bool isTimelineAnim = false){
66-
this.SetTitle ();
67-
this.SetFilename (filename);
68-
this.SetAnimationExportType (isTimelineAnim);
69-
this.SetSingleHierarchyExport (singleHierarchyExport);
70-
}
71-
72-
private void SetTitle(){
63+
protected virtual void InitializeWindow(string filename = ""){
7364
this.titleContent = WindowTitle;
65+
this.SetFilename (filename);
7466
}
7567

7668
protected void InitializeReceiver(){
@@ -93,21 +85,6 @@ public void SetFilename(string filename){
9385
m_exportFileName = filename.Remove(extIndex);
9486
}
9587

96-
public void SetAnimationExportType(bool isTimelineAnim){
97-
m_isTimelineAnim = isTimelineAnim;
98-
}
99-
100-
public void SetSingleHierarchyExport(bool singleHierarchy){
101-
m_singleHierarchyExport = singleHierarchy;
102-
103-
if (m_innerEditor) {
104-
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
105-
if (exportModelSettingsEditor) {
106-
exportModelSettingsEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
107-
}
108-
}
109-
}
110-
11188
public void SaveExportSettings()
11289
{
11390
// save once preset selection is finished
@@ -275,14 +252,21 @@ public class ExportModelEditorWindow : ExportOptionsEditorWindow
275252
protected override float MinWindowHeight { get { return 260; } }
276253
private UnityEngine.Object[] m_toExport;
277254

278-
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false)
255+
private bool m_isTimelineAnim = false;
256+
private bool m_singleHierarchyExport = true;
257+
private bool m_isPlayableDirector = false;
258+
259+
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false, bool isPlayableDirector = false)
279260
{
280261
ExportModelEditorWindow window = CreateWindow<ExportModelEditorWindow> ();
281262
int numObjects = window.SetGameObjectsToExport (toExport);
282263
if (string.IsNullOrEmpty (filename)) {
283264
filename = window.GetFilenameFromObjects ();
284265
}
285-
window.InitializeWindow (filename, singleHierarchyExport: numObjects == 1, isTimelineAnim: isTimelineAnim);
266+
window.InitializeWindow (filename);
267+
window.SetAnimationExportType (isTimelineAnim);
268+
window.SetSingleHierarchyExport (numObjects == 1);
269+
window.SetIsPlayableDirector (isPlayableDirector);
286270
window.Show ();
287271
}
288272

@@ -291,6 +275,34 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
291275
return m_toExport.Length;
292276
}
293277

278+
private void SetAnimationExportType(bool isTimelineAnim){
279+
m_isTimelineAnim = isTimelineAnim;
280+
if (m_isTimelineAnim) {
281+
ExportSettings.instance.exportModelSettings.SetModelAnimIncludeOption (ExportModelSettingsSerialize.Include.Anim);
282+
}
283+
if (m_innerEditor) {
284+
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
285+
if (exportModelSettingsEditor) {
286+
exportModelSettingsEditor.DisableIncludeDropdown(m_isTimelineAnim);
287+
}
288+
}
289+
}
290+
291+
private void SetSingleHierarchyExport(bool singleHierarchy){
292+
m_singleHierarchyExport = singleHierarchy;
293+
294+
if (m_innerEditor) {
295+
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
296+
if (exportModelSettingsEditor) {
297+
exportModelSettingsEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
298+
}
299+
}
300+
}
301+
302+
private void SetIsPlayableDirector(bool isPlayableDirector){
303+
m_isPlayableDirector = isPlayableDirector;
304+
}
305+
294306
protected string GetFilenameFromObjects(){
295307
var filename = "";
296308
if (m_toExport.Length == 1) {
@@ -306,18 +318,38 @@ protected override void OnEnable ()
306318
base.OnEnable ();
307319
if (!m_innerEditor) {
308320
m_innerEditor = UnityEditor.Editor.CreateEditor (ExportSettings.instance.exportModelSettings);
321+
this.SetSingleHierarchyExport (m_singleHierarchyExport);
322+
this.SetAnimationExportType (m_isTimelineAnim);
309323
}
310324
}
311325

312-
protected override void Export(){
313-
var filePath = ExportSettings.GetFbxAbsoluteSavePath ();
326+
protected override bool DisableNameSelection ()
327+
{
328+
return m_isPlayableDirector;
329+
}
314330

315-
filePath = System.IO.Path.Combine (filePath, m_exportFileName + ".fbx");
331+
protected override void Export(){
332+
var folderPath = ExportSettings.GetFbxAbsoluteSavePath ();
333+
var filePath = System.IO.Path.Combine (folderPath, m_exportFileName + ".fbx");
316334

317335
if (!OverwriteExistingFile (filePath)) {
318336
return;
319337
}
320338

339+
if (m_isPlayableDirector) {
340+
foreach (var obj in m_toExport) {
341+
var go = ModelExporter.GetGameObject (obj);
342+
if (!go) {
343+
continue;
344+
}
345+
ModelExporter.ExportAllTimelineClips (go, folderPath, ExportSettings.instance.exportModelSettings);
346+
}
347+
// refresh the asset database so that the file appears in the
348+
// asset folder view.
349+
AssetDatabase.Refresh ();
350+
return;
351+
}
352+
321353
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings, timelineAnim: m_isTimelineAnim) != null) {
322354
// refresh the asset database so that the file appears in the
323355
// asset folder view.

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class ExportModelSettingsEditor : UnityEditor.Editor
1818
private string hierarchyDepOption = "";
1919
private string[] objPositionOptions { get { return new string[]{hierarchyDepOption, "World Absolute"}; }}
2020

21+
private bool disableIncludeDropdown = false;
22+
2123
public void SetIsSingleHierarchy(bool singleHierarchy){
2224
if (singleHierarchy) {
2325
hierarchyDepOption = singleHierarchyOption;
@@ -26,6 +28,10 @@ public void SetIsSingleHierarchy(bool singleHierarchy){
2628
hierarchyDepOption = multiHerarchyOption;
2729
}
2830

31+
public void DisableIncludeDropdown(bool disable){
32+
disableIncludeDropdown = disable;
33+
}
34+
2935
public override void OnInspectorGUI ()
3036
{
3137
var exportSettings = ((ExportModelSettings)target).info;
@@ -40,7 +46,9 @@ public override void OnInspectorGUI ()
4046

4147
GUILayout.BeginHorizontal();
4248
EditorGUILayout.LabelField(new GUIContent("Include", "Select whether to export models, animation or both."), GUILayout.Width(LabelWidth - FieldOffset));
49+
EditorGUI.BeginDisabledGroup(disableIncludeDropdown);
4350
exportSettings.include = (ExportModelSettingsSerialize.Include)EditorGUILayout.Popup((int)exportSettings.include, includeOptions);
51+
EditorGUI.EndDisabledGroup ();
4452
GUILayout.EndHorizontal();
4553

4654
GUILayout.BeginHorizontal();
@@ -147,7 +155,7 @@ public enum ExportFormat { ASCII = 0, Binary = 1}
147155

148156
public enum Include { Model = 0, Anim = 1, ModelAndAnim = 2 }
149157

150-
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1 , Reset = 2 }
158+
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1, Reset = 2 /* For convert to model only, no UI option*/}
151159

152160
public enum LODExportType { All = 0, Highest = 1, Lowest = 2 }
153161

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,20 +3041,24 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
30413041
}
30423042
}
30433043

3044+
var playableDirectors = new List<UnityEngine.Object> ();
30443045
foreach (GameObject objectWithPlayableDirector in selection)
30453046
{
3046-
if (ExportAllTimelineClips (objectWithPlayableDirector)) {
3047-
return;
3047+
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
3048+
if (pd == null) {
3049+
continue;
30483050
}
3051+
playableDirectors.Add (objectWithPlayableDirector);
30493052
}
3053+
ExportModelEditorWindow.Init (playableDirectors, "(automatic)", isTimelineAnim:true, isPlayableDirector:true);
30503054
}
30513055

3052-
public static bool ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath = null)
3056+
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath, IExportOptions exportOptions = null)
30533057
{
30543058
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
30553059
if (pd == null)
30563060
{
3057-
return false;
3061+
return;
30583062
}
30593063
foreach (PlayableBinding output in pd.playableAsset.outputs)
30603064
{
@@ -3065,10 +3069,9 @@ public static bool ExportAllTimelineClips(GameObject objectWithPlayableDirector,
30653069
foreach (TimelineClip timeLineClip in at.GetClips()) {
30663070
string filePath = string.Format(AnimFbxFileFormat, folderPath, atObject.name, timeLineClip.displayName);
30673071
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, timeLineClip.animationClip };
3068-
ExportObjects (filePath, myArray, timelineAnim: true);
3072+
ExportObjects (filePath, myArray, exportOptions, timelineAnim: true);
30693073
}
30703074
}
3071-
return true;
30723075
}
30733076

30743077
/// <summary>
@@ -3629,22 +3632,20 @@ public static string ExportObjects (
36293632
}
36303633

36313634
Dictionary<GameObject, AnimationOnlyExportData> animationExportData = null;
3632-
if (exportOptions.GetModelAnimIncludeOption () == ExportModelSettingsSerialize.Include.Anim) {
3633-
if (timelineAnim) {
3634-
// We expect the first argument in the list to be the GameObject, the second one is the Animation Clip/Track we are exporting from the timeline
3635-
GameObject rootObject = ModelExporter.GetGameObject (objects [0]);
3636-
AnimationClip timelineClip = objects [1] as AnimationClip;
3637-
List<AnimationClip> clipList = new List<AnimationClip> ();
3638-
clipList.Add (timelineClip);
3639-
animationExportData = fbxExporter.GetTimelineAnimationExportData (rootObject, clipList);
3640-
}
3641-
else{
3642-
HashSet<GameObject> gos = new HashSet<GameObject> ();
3643-
foreach (var obj in objects) {
3644-
gos.Add (ModelExporter.GetGameObject (obj));
3645-
}
3646-
animationExportData = fbxExporter.GetAnimationExportData (gos);
3635+
if (timelineAnim) {
3636+
// We expect the first argument in the list to be the GameObject, the second one is the Animation Clip/Track we are exporting from the timeline
3637+
GameObject rootObject = ModelExporter.GetGameObject (objects [0]);
3638+
AnimationClip timelineClip = objects [1] as AnimationClip;
3639+
List<AnimationClip> clipList = new List<AnimationClip> ();
3640+
clipList.Add (timelineClip);
3641+
animationExportData = fbxExporter.GetTimelineAnimationExportData (rootObject, clipList);
3642+
}
3643+
else if (exportOptions.GetModelAnimIncludeOption () == ExportModelSettingsSerialize.Include.Anim) {
3644+
HashSet<GameObject> gos = new HashSet<GameObject> ();
3645+
foreach (var obj in objects) {
3646+
gos.Add (ModelExporter.GetGameObject (obj));
36473647
}
3648+
animationExportData = fbxExporter.GetAnimationExportData (gos);
36483649
}
36493650

36503651
if (fbxExporter.ExportAll (objects, animationExportData) > 0) {

0 commit comments

Comments
 (0)