Skip to content

Commit afec48e

Browse files
committed
Work on unit tests
1 parent fdf0013 commit afec48e

File tree

3 files changed

+100
-36
lines changed

3 files changed

+100
-36
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,10 @@ private void ReplaceFile ()
30583058
Debug.LogWarning (string.Format("Failed to move file {0} to {1}", m_tempFilePath, m_lastFilePath));
30593059
}
30603060
}
3061-
3061+
/// <summary>
3062+
/// GameObject/Export Selected Timeline Clip...
3063+
/// </summary>
3064+
/// <param name="command"></param>
30623065
[MenuItem(TimelineClipMenuItemName, false, 31)]
30633066
static void OnClipContextClick(MenuCommand command)
30643067
{
@@ -3078,37 +3081,40 @@ static void OnClipContextClick(MenuCommand command)
30783081

30793082

30803083
var selectedObjects = Selection.objects;
3081-
foreach (var obj in selectedObjects)
3084+
foreach (GameObject obj in selectedObjects)
30823085
{
3083-
if (obj.GetType().Name.Contains("EditorClip"))
3084-
{
3085-
var selClip = obj.GetType().GetProperty("clip").GetValue(obj, null);
3086-
UnityEngine.Timeline.TimelineClip timeLineClip = selClip as UnityEngine.Timeline.TimelineClip;
3087-
3088-
var selClipItem = obj.GetType().GetProperty("item").GetValue(obj, null);
3089-
var selClipItemParentTrack = selClipItem.GetType().GetProperty("parentTrack").GetValue(selClipItem, null);
3090-
AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack;
3086+
ExportSingleTimelineClip(obj, folderPath);
3087+
}
3088+
}
30913089

3092-
GameObject animationTrackGObject = UnityEditor.Timeline.TimelineEditor.playableDirector.GetGenericBinding (editorClipAnimationTrack) as GameObject;
3090+
public static void ExportSingleTimelineClip(GameObject obj, string folderPath)
3091+
{
3092+
if (obj.GetType().Name.Contains("EditorClip"))
3093+
{
3094+
var selClip = obj.GetType().GetProperty("clip").GetValue(obj, null);
3095+
UnityEngine.Timeline.TimelineClip timeLineClip = selClip as UnityEngine.Timeline.TimelineClip;
30933096

3094-
Debug.Log("obj name: " + obj.name + " /clip name: " + editorClipAnimationTrack.name + " /timelineAssetName: " + animationTrackGObject.name);
3097+
var selClipItem = obj.GetType().GetProperty("item").GetValue(obj, null);
3098+
var selClipItemParentTrack = selClipItem.GetType().GetProperty("parentTrack").GetValue(selClipItem, null);
3099+
AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack;
30953100

3096-
string filePath = folderPath + "/" + animationTrackGObject.name + "@" + timeLineClip.animationClip.name + ".fbx";
3097-
Debug.Log("filepath: " + filePath);
3098-
UnityEngine.Object[] myArray = new UnityEngine.Object[] { animationTrackGObject, timeLineClip.animationClip };
3101+
GameObject animationTrackGObject = UnityEditor.Timeline.TimelineEditor.playableDirector.GetGenericBinding (editorClipAnimationTrack) as GameObject;
30993102

3100-
ExportObjects(filePath, myArray, ExportType.timelineAnimationClip);
3101-
}
3102-
}
3103-
}
3103+
Debug.Log("obj name: " + obj.name + " /clip name: " + editorClipAnimationTrack.name + " /timelineAssetName: " + animationTrackGObject.name);
31043104

3105+
string filePath = folderPath + "/" + animationTrackGObject.name + "@" + timeLineClip.animationClip.name + ".fbx";
3106+
Debug.Log("filepath: " + filePath);
3107+
UnityEngine.Object[] myArray = new UnityEngine.Object[] { animationTrackGObject, timeLineClip.animationClip };
31053108

3109+
ExportObjects(filePath, myArray, ExportType.timelineAnimationClip);
3110+
}
3111+
}
31063112

31073113
/// <summary>
3108-
/// Add an option "Update from FBX" in the contextual GameObject menu.
3114+
/// GameObject/Export All Recorded Animation Clips...
31093115
/// </summary>
31103116
[MenuItem(ClipMenuItemName, false, 31)]
3111-
static void OnGameObjectWithTimelineContextClick(MenuCommand command)
3117+
public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
31123118
{
31133119
// Now that we know we have stuff to export, get the user-desired path.
31143120
string directory = string.IsNullOrEmpty(LastFilePath)
@@ -3143,23 +3149,29 @@ static void OnGameObjectWithTimelineContextClick(MenuCommand command)
31433149

31443150
foreach (GameObject obj in selection)
31453151
{
3146-
Debug.Log(obj.GetType().BaseType.ToString() + ":" + obj.name);
3152+
ExportAllTimelineClips(obj,folderPath);
3153+
}
3154+
}
3155+
31473156

3148-
PlayableDirector pd = obj.GetComponent<PlayableDirector>();
3149-
if (pd != null)
3157+
public static void ExportAllTimelineClips(GameObject obj, string folderPath)
3158+
{
3159+
Debug.Log(obj.GetType().BaseType.ToString() + ":" + obj.name);
3160+
3161+
PlayableDirector pd = obj.GetComponent<PlayableDirector>();
3162+
if (pd != null)
3163+
{
3164+
foreach (PlayableBinding output in pd.playableAsset.outputs)
31503165
{
3151-
foreach (PlayableBinding output in pd.playableAsset.outputs)
3152-
{
3153-
AnimationTrack at = output.sourceObject as AnimationTrack;
3166+
AnimationTrack at = output.sourceObject as AnimationTrack;
31543167

3155-
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
3168+
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
31563169

3157-
string filePath = folderPath + "/" + atObject.name + "@" + at.name + ".fbx";
3158-
Debug.Log("filepath: " + filePath);
3159-
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, at};
3170+
string filePath = folderPath + "/" + atObject.name + "@" + at.name + ".fbx";
3171+
Debug.Log("filepath: " + filePath);
3172+
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, at};
31603173

3161-
ExportObjects(filePath, myArray, ExportType.timelineAnimationTrack);
3162-
}
3174+
ExportObjects(filePath, myArray, ExportType.timelineAnimationTrack);
31633175
}
31643176
}
31653177
}

Assets/FbxExporters/Editor/UnitTests/ExportTimelineClip.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using NUnit.Framework;
44
using FbxExporters.Editor;
55
using UnityEngine.Timeline;
6+
using UnityEngine.Playables;
7+
using System;
68

79
namespace FbxExporters.UnitTests
810
{
@@ -15,8 +17,38 @@ public void Init()
1517
}
1618

1719
[Test]
18-
public void RemappingTest()
20+
public void ExportClip()
1921
{
22+
GameObject timelineGO = new GameObject();
23+
PlayableDirector playableDirector = timelineGO.AddComponent<PlayableDirector>();
24+
Animator animator = timelineGO.AddComponent<Animator>();
25+
TimelineAsset timelineAsset = (TimelineAsset)playableDirector.playableAsset;
26+
AnimationTrack newTrack = timelineAsset.CreateTrack<AnimationTrack>(null, "Animation Track " + timelineGO.name);
27+
28+
//bind object to which the animation shell be assigned to the created animationTrack
29+
playableDirector.SetGenericBinding(newTrack, timelineGO);
30+
31+
AnimationClip animationClip = new AnimationClip();
32+
//create a timelineClip for the animationClip on the AnimationTrack
33+
TimelineClip timelineClip = newTrack.CreateClip(animationClip);
34+
35+
36+
/*Type timelineWindowType = Type.GetType("UnityEditor.Timeline.TimelineWindow,UnityEditor.Timeline");
37+
var timelineWindow = EditorWindow.GetWindow(timelineWindowType);
38+
timelineWindow.Repaint();​*/
39+
40+
41+
//New GameObject
42+
//New Playable Director
43+
//New Timeline
44+
//New Animation Track
45+
//New Animation Clip
46+
//Create clip (timeline) with Animation Clip
47+
//UnityEngine.Timeline.TimelineClip timeLineClip = new UnityEngine.Timeline.TimelineClip();
48+
49+
50+
51+
2052
/*var selectedObjects = Selection.objects;
2153
foreach (var obj in selectedObjects)
2254
{
@@ -46,9 +78,29 @@ public void RemappingTest()
4678
Assert.IsTrue(FbxPrefabAutoUpdater.OnValidateMenuItem());
4779
}
4880

81+
[Test]
82+
public void ExportAllTimelineClip()
83+
{
84+
GameObject myCube = GameObject.Find("Cube");
85+
Selection.objects = new UnityEngine.GameObject[] { myCube };
86+
string folderPath = Application.dataPath + "/Assets/UnitTest";
87+
Debug.Log(folderPath);
88+
foreach(GameObject obj in Selection.objects)
89+
{
90+
ModelExporter.ExportAllTimelineClips(obj, Application.dataPath + "/Assets/UnitTest/");
91+
FileAssert.Exists(folderPath + obj.name + "@Recorded.fbx");
92+
93+
}
94+
95+
96+
97+
}
98+
99+
100+
49101

50102
[TearDown]
51-
public void stopTest()
103+
public void StopTest()
52104
{
53105

54106
}

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public void RemappingTest()
327327

328328

329329
[TearDown]
330-
public void stopTest()
330+
public void StopTest()
331331
{
332332
// Put back the initial setting for the auto-updater toggle
333333
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;

0 commit comments

Comments
 (0)