7
7
8
8
namespace UnityEditor . Formats . Fbx . Exporter
9
9
{
10
- class FbxRecorder : GenericRecorder < FbxRecorderSettings > //GenericRecorder<FbxRecorderSettings>
10
+ class FbxRecorder : GenericRecorder < FbxRecorderSettings >
11
11
{
12
12
public override void RecordFrame ( RecordingSession ctx )
13
13
{
14
- //Debug.LogWarning("Frame " + ctx.frameIndex + ": " + ctx.);
14
+
15
15
}
16
16
17
17
public override void EndRecording ( RecordingSession session )
@@ -32,27 +32,51 @@ public override void EndRecording(RecordingSession session)
32
32
33
33
var absolutePath = FileNameGenerator . SanitizePath ( ars . fileNameGenerator . BuildAbsolutePath ( session ) ) ;
34
34
var clipName = absolutePath . Replace ( FileNameGenerator . SanitizePath ( Application . dataPath ) , "Assets" ) ;
35
-
36
- //var tempClipName = System.IO.Path.ChangeExtension(clipName, ".asset");
37
- //AssetDatabase.CreateAsset(clip, tempClipName);
35
+
36
+ //AssetDatabase.CreateAsset(clip, clipName);
38
37
#if UNITY_2018_3_OR_NEWER
39
38
aInput . gameObjectRecorder . SaveToClip ( clip , ars . frameRate ) ;
40
39
#else
41
40
aInput . gameObjectRecorder . SaveToClip ( clip ) ;
42
41
#endif
43
42
var root = ( ( AnimationInputSettings ) aInput . settings ) . gameObject ;
44
43
clip . name = "recorded_clip" ;
45
- Animation animator = root . AddComponent < Animation > ( ) ;
44
+ clip . legacy = true ;
45
+ Animation animator = root . GetComponent < Animation > ( ) ;
46
+ bool hasAnimComponent = true ;
47
+ if ( ! animator )
48
+ {
49
+ animator = root . AddComponent < Animation > ( ) ;
50
+ hasAnimComponent = false ;
51
+ }
52
+
53
+ AnimationClip [ ] prevAnimClips = null ;
54
+ if ( hasAnimComponent )
55
+ {
56
+ prevAnimClips = AnimationUtility . GetAnimationClips ( root ) ;
57
+ }
58
+
46
59
AnimationUtility . SetAnimationClips ( animator , new AnimationClip [ ] { clip } ) ;
47
60
var exportSettings = new ExportModelSettingsSerialize ( ) ;
48
- exportSettings . SetModelAnimIncludeOption ( ExportSettings . Include . Anim ) ;
61
+ var toInclude = ExportSettings . Include . ModelAndAnim ;
62
+ if ( ! ars . ExportGeometry )
63
+ {
64
+ toInclude = ExportSettings . Include . Anim ;
65
+ }
66
+ exportSettings . SetModelAnimIncludeOption ( toInclude ) ;
49
67
ModelExporter . ExportObject ( clipName , root , exportSettings ) ;
50
68
51
69
52
- Object . DestroyImmediate ( animator ) ;
70
+ if ( hasAnimComponent )
71
+ {
72
+ AnimationUtility . SetAnimationClips ( animator , prevAnimClips ) ;
73
+ }
74
+ else
75
+ {
76
+ Object . DestroyImmediate ( animator ) ;
77
+ }
53
78
aInput . gameObjectRecorder . ResetRecording ( ) ;
54
79
}
55
-
56
80
base . EndRecording ( session ) ;
57
81
}
58
82
}
0 commit comments