Skip to content

Commit 24f110b

Browse files
committed
Unit tests. Missing random folder path to destroy resources after test.
1 parent 0f8587e commit 24f110b

File tree

6 files changed

+2195
-93
lines changed

6 files changed

+2195
-93
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public class ModelExporter : System.IDisposable
8282
// being called only once regardless of what is selected.
8383
const string MenuItemName = "GameObject/Export Model...";
8484

85-
const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips...";
86-
const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip...";
85+
const string ClipMenuItemName = "GameObject/FBX Exporter/Export All Recorded Animation Clips...";
86+
const string TimelineClipMenuItemName = "GameObject/FBX Exporter/Export Selected Timeline Clip...";
8787

8888

8989
const string AnimOnlyMenuItemName = "GameObject/Export Animation Only";
@@ -3081,35 +3081,36 @@ static void OnClipContextClick(MenuCommand command)
30813081

30823082

30833083
var selectedObjects = Selection.objects;
3084-
foreach (GameObject obj in selectedObjects)
3084+
foreach (GameObject editorClipSelected in selectedObjects)
30853085
{
3086-
ExportSingleTimelineClip(obj, folderPath);
3086+
ExportSingleEditorClip(editorClipSelected, folderPath);
30873087
}
30883088
}
30893089

3090-
public static void ExportSingleTimelineClip(GameObject obj, string folderPath)
3090+
public static void ExportSingleEditorClip(GameObject editorClipSelected, string folderPath)
30913091
{
3092-
if (obj.GetType().Name.Contains("EditorClip"))
3092+
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
30933093
{
3094-
var selClip = obj.GetType().GetProperty("clip").GetValue(obj, null);
3094+
var selClip = editorClipSelected.GetType().GetProperty("clip").GetValue(editorClipSelected, null);
30953095
UnityEngine.Timeline.TimelineClip timeLineClip = selClip as UnityEngine.Timeline.TimelineClip;
30963096

3097-
var selClipItem = obj.GetType().GetProperty("item").GetValue(obj, null);
3097+
var selClipItem = editorClipSelected.GetType().GetProperty("item").GetValue(editorClipSelected, null);
30983098
var selClipItemParentTrack = selClipItem.GetType().GetProperty("parentTrack").GetValue(selClipItem, null);
30993099
AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack;
3100-
31013100
GameObject animationTrackGObject = UnityEditor.Timeline.TimelineEditor.playableDirector.GetGenericBinding (editorClipAnimationTrack) as GameObject;
31023101

3103-
Debug.Log("obj name: " + obj.name + " /clip name: " + editorClipAnimationTrack.name + " /timelineAssetName: " + animationTrackGObject.name);
3104-
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 };
3108-
3109-
ExportObjects(filePath, myArray, ExportType.timelineAnimationClip);
3102+
ExportSingleTimelineClip(timeLineClip, folderPath, animationTrackGObject);
31103103
}
31113104
}
31123105

3106+
public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, string folderPath, GameObject animationTrackGObject)
3107+
{
3108+
string filePath = folderPath + "/" + animationTrackGObject.name + "@" + timelineClipSelected.animationClip.name + ".fbx";
3109+
//Debug.Log("filepath: " + filePath);
3110+
UnityEngine.Object[] myArray = new UnityEngine.Object[] { animationTrackGObject, timelineClipSelected.animationClip };
3111+
ExportObjects(filePath, myArray, AnimationExportType.timelineAnimationClip);
3112+
}
3113+
31133114
/// <summary>
31143115
/// GameObject/Export All Recorded Animation Clips...
31153116
/// </summary>
@@ -3147,31 +3148,31 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
31473148
}
31483149
}
31493150

3150-
foreach (GameObject obj in selection)
3151+
foreach (GameObject objectWithPlayableDirector in selection)
31513152
{
3152-
ExportAllTimelineClips(obj,folderPath);
3153+
ExportAllTimelineClips(objectWithPlayableDirector,folderPath);
31533154
}
31543155
}
31553156

3156-
3157-
public static void ExportAllTimelineClips(GameObject obj, string folderPath)
3157+
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath)
31583158
{
3159-
Debug.Log(obj.GetType().BaseType.ToString() + ":" + obj.name);
3159+
Debug.Log(objectWithPlayableDirector.GetType().BaseType.ToString() + ":" + objectWithPlayableDirector.name);
31603160

3161-
PlayableDirector pd = obj.GetComponent<PlayableDirector>();
3161+
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
31623162
if (pd != null)
31633163
{
31643164
foreach (PlayableBinding output in pd.playableAsset.outputs)
31653165
{
31663166
AnimationTrack at = output.sourceObject as AnimationTrack;
31673167

31683168
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
3169-
3170-
string filePath = folderPath + "/" + atObject.name + "@" + at.name + ".fbx";
3171-
Debug.Log("filepath: " + filePath);
3172-
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, at};
3173-
3174-
ExportObjects(filePath, myArray, ExportType.timelineAnimationTrack);
3169+
// One file by animation clip
3170+
foreach(TimelineClip timeLineClip in at.GetClips())
3171+
{
3172+
string filePath = folderPath + "/" + atObject.name + "@" + timeLineClip.animationClip.name + ".fbx";
3173+
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, timeLineClip.animationClip };
3174+
ExportObjects(filePath, myArray, AnimationExportType.timelineAnimationClip);
3175+
}
31753176
}
31763177
}
31773178
}
@@ -3238,7 +3239,7 @@ static void OnAnimOnlyContextItem (MenuCommand command)
32383239
return;
32393240
}
32403241

3241-
OnExport (ExportType.componentAnimation);
3242+
OnExport (AnimationExportType.componentAnimation);
32423243
}
32433244

32443245
/// <summary>
@@ -3689,7 +3690,7 @@ public void Dispose ()
36893690

36903691
const string Extension = "fbx";
36913692

3692-
public enum ExportType{
3693+
public enum AnimationExportType{
36933694
timelineAnimationClip,
36943695
timelineAnimationTrack,
36953696
componentAnimation,
@@ -3702,7 +3703,7 @@ private static string MakeFileName (string basename = "test", string extension =
37023703
return basename + "." + extension;
37033704
}
37043705

3705-
private static void OnExport (ExportType exportType = ExportType.all)
3706+
private static void OnExport (AnimationExportType exportType = AnimationExportType.all)
37063707
{
37073708

37083709
// Now that we know we have stuff to export, get the user-desired path.
@@ -3739,7 +3740,7 @@ private static void OnExport (ExportType exportType = ExportType.all)
37393740
/// Export a list of (Game) objects to FBX file.
37403741
/// Use the SaveFile panel to allow user to enter a file name.
37413742
/// <summary>
3742-
public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, ExportType exportType = ExportType.all /*, bool animOnly = false*/)
3743+
public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
37433744
{
37443745
LastFilePath = filePath;
37453746

@@ -3755,19 +3756,19 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
37553756
Dictionary<GameObject, AnimationOnlyExportData> animationExportData = null;
37563757
switch (exportType)
37573758
{
3758-
case ExportType.timelineAnimationClip:
3759+
case AnimationExportType.timelineAnimationClip:
37593760
GameObject rootObject = ModelExporter.GetGameObject(objects[0]);
37603761
AnimationClip timelineClip = objects[1] as AnimationClip;
37613762
List<AnimationClip> clipList = new List<AnimationClip>();
37623763
clipList.Add(timelineClip);
37633764
animationExportData = fbxExporter.GetTimelineAnimationExportData(rootObject, clipList);
37643765
break;
3765-
case ExportType.timelineAnimationTrack:
3766+
case AnimationExportType.timelineAnimationTrack:
37663767
GameObject rootObject2 = ModelExporter.GetGameObject(objects[0]);
37673768
AnimationTrack timelineTrack = objects[1] as AnimationTrack;
37683769
animationExportData = fbxExporter.GetAnimationExportDataFromAnimationTrack(rootObject2, timelineTrack);
37693770
break;
3770-
case ExportType.componentAnimation:
3771+
case AnimationExportType.componentAnimation:
37713772
HashSet<GameObject> gos = new HashSet<GameObject>();
37723773
foreach(var obj in objects)
37733774
{
@@ -3789,7 +3790,7 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
37893790
return null;
37903791
}
37913792

3792-
public static string ExportObject (string filePath, UnityEngine.Object root, ExportType exportType = ExportType.all /*, bool animOnly = false*/)
3793+
public static string ExportObject (string filePath, UnityEngine.Object root, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
37933794
{
37943795
return ExportObjects(filePath, new Object[] { root }, exportType);
37953796
}

Assets/FbxExporters/Editor/UnitTests/ExportTimelineClipTest.cs

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
using FbxExporters.Editor;
55
using UnityEngine.Timeline;
66
using UnityEngine.Playables;
7-
using System;
7+
using UnityEditor.SceneManagement;
8+
using UnityEngine.SceneManagement;
89

910
namespace FbxExporters.UnitTests
1011
{
@@ -13,68 +14,35 @@ public class ExportTimelineClipTest : ExporterTestBase
1314
[SetUp]
1415
public void Init()
1516
{
16-
17+
EditorSceneManager.OpenScene("Assets/FBXExporters/Editor/UnitTests/Scene/TestScene.unity");
1718
}
1819

1920
[Test]
20-
public void ExportClip()
21+
public void ExportSingleTimelineClipTest()
2122
{
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();
23+
GameObject myCube = GameObject.Find("CubeSpecial");
24+
string folderPath = Application.dataPath + "/UnitTest/";
4825

49-
/*var selectedObjects = Selection.objects;
50-
foreach (var obj in selectedObjects)
26+
PlayableDirector pd = myCube.GetComponent<PlayableDirector>();
27+
if (pd != null)
5128
{
52-
if (obj.GetType().Name.Contains("EditorClip"))
29+
foreach (PlayableBinding output in pd.playableAsset.outputs)
5330
{
54-
var selClip = obj.GetType().GetProperty("clip").GetValue(obj, null);
55-
UnityEngine.Timeline.TimelineClip timeLineClip = selClip as UnityEngine.Timeline.TimelineClip;
56-
57-
var selClipItem = obj.GetType().GetProperty("item").GetValue(obj, null);
58-
var selClipItemParentTrack = selClipItem.GetType().GetProperty("parentTrack").GetValue(selClipItem, null);
59-
AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack;
60-
61-
GameObject animationTrackGObject = UnityEditor.Timeline.TimelineEditor.playableDirector.GetGenericBinding (editorClipAnimationTrack) as GameObject;
62-
63-
Debug.Log("obj name: " + obj.name + " /clip name: " + editorClipAnimationTrack.name + " /timelineAssetName: " + animationTrackGObject.name);
64-
65-
string filePath = folderPath + "/" + animationTrackGObject.name + "@" + timeLineClip.animationClip.name + ".fbx";
66-
Debug.Log("filepath: " + filePath);
67-
UnityEngine.Object[] myArray = new UnityEngine.Object[] { animationTrackGObject, timeLineClip.animationClip };
68-
69-
FbxExporter.ExportObjects(filePath, myArray, ExportType.timelineAnimationClip);
70-
}
71-
}*/
72-
73-
// Assert.IsTrue(FbxPrefabAutoUpdater.OnValidateMenuItem());
31+
AnimationTrack at = output.sourceObject as AnimationTrack;
32+
33+
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
34+
// One file by animation clip
35+
foreach(TimelineClip timeLineClip in at.GetClips())
36+
{
37+
ModelExporter.ExportSingleTimelineClip(timeLineClip, folderPath, atObject);
38+
FileAssert.Exists(folderPath + atObject.name + "@Recorded.fbx");
39+
}
40+
}
41+
}
7442
}
7543

7644
[Test]
77-
public void ExportAllTimelineClip()
45+
public void ExportAllTimelineClipTest()
7846
{
7947
GameObject myCube = GameObject.Find("CubeSpecial");
8048
Selection.objects = new UnityEngine.GameObject[] { myCube };
@@ -83,7 +51,7 @@ public void ExportAllTimelineClip()
8351
foreach(GameObject obj in Selection.objects)
8452
{
8553
ModelExporter.ExportAllTimelineClips(obj, folderPath);
86-
FileAssert.Exists(folderPath + obj.name + "@Animation Track.fbx");
54+
FileAssert.Exists(folderPath + obj.name + "@Recorded.fbx");
8755
}
8856
}
8957

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ public void AnimOnlyExportTest(string prefabPath)
828828
// export fbx
829829
// get GameObject
830830
string filename = GetRandomFbxFilePath ();
831-
var exportedFilePath = ModelExporter.ExportObject (filename, originalGO, ModelExporter.ExportType.componentAnimation);
831+
var exportedFilePath = ModelExporter.ExportObject (filename, originalGO, ModelExporter.AnimationExportType.componentAnimation);
832832
Assert.That (exportedFilePath, Is.EqualTo (filename));
833833

834834
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,11 @@ public void TestNameMapping()
158158
// In FbxPrefab Component of Cube, add SphereFBX/Sphere name mapping
159159
FbxPrefab fbxPrefabScript = cubePrefabInstance.transform.GetComponent<FbxPrefab>();
160160

161-
162161
FbxPrefab.StringPair stringpair = new FbxPrefab.StringPair();
163162
stringpair.FBXObjectName = "SphereFBX";
164163
stringpair.UnityObjectName = "Sphere";
165164
fbxPrefabScript.NameMapping.Add(stringpair);
166165

167-
168166
FbxPrefabAutoUpdater.FbxPrefabUtility fbxPrefabUtility = new FbxPrefabAutoUpdater.FbxPrefabUtility(fbxPrefabScript);
169167

170168
Assert.IsTrue(fbxPrefabUtility.GetUnityObjectName("SphereFBX") == stringpair.UnityObjectName);

0 commit comments

Comments
 (0)