2
2
using UnityEngine ;
3
3
using UnityEditor ;
4
4
using System . Collections ;
5
+ using System . Collections . Generic ;
5
6
6
7
public class UnityAnimationRecorder : MonoBehaviour {
7
8
@@ -27,8 +28,13 @@ public class UnityAnimationRecorder : MonoBehaviour {
27
28
public float timeScaleOnStart = 0.0f ;
28
29
public float timeScaleOnRecord = 1.0f ;
29
30
31
+ public bool recordBlendShape = false ;
32
+
33
+
30
34
Transform [ ] recordObjs ;
35
+ SkinnedMeshRenderer [ ] blendShapeObjs ;
31
36
UnityObjectAnimation [ ] objRecorders ;
37
+ List < UnityBlendShapeAnimation > blendShapeRecorders ;
32
38
33
39
bool isStart = false ;
34
40
float nowTime = 0.0f ;
@@ -42,13 +48,26 @@ void Start () {
42
48
void SetupRecorders ( ) {
43
49
recordObjs = gameObject . GetComponentsInChildren < Transform > ( ) ;
44
50
objRecorders = new UnityObjectAnimation [ recordObjs . Length ] ;
51
+ blendShapeRecorders = new List < UnityBlendShapeAnimation > ( ) ;
45
52
46
53
frameIndex = 0 ;
47
54
nowTime = 0.0f ;
48
55
49
56
for ( int i = 0 ; i < recordObjs . Length ; i ++ ) {
50
57
string path = AnimationRecorderHelper . GetTransformPathName ( transform , recordObjs [ i ] ) ;
51
58
objRecorders [ i ] = new UnityObjectAnimation ( path , recordObjs [ i ] ) ;
59
+
60
+ // check if theres blendShape
61
+ if ( recordBlendShape ) {
62
+ if ( recordObjs [ i ] . GetComponent < SkinnedMeshRenderer > ( ) ) {
63
+ SkinnedMeshRenderer tempSkinMeshRenderer = recordObjs [ i ] . GetComponent < SkinnedMeshRenderer > ( ) ;
64
+
65
+ // there is blendShape exist
66
+ if ( tempSkinMeshRenderer . sharedMesh . blendShapeCount > 0 ) {
67
+ blendShapeRecorders . Add ( new UnityBlendShapeAnimation ( path , tempSkinMeshRenderer ) ) ;
68
+ }
69
+ }
70
+ }
52
71
}
53
72
54
73
if ( changeTimeScale )
@@ -72,6 +91,12 @@ void Update () {
72
91
for ( int i = 0 ; i < objRecorders . Length ; i ++ ) {
73
92
objRecorders [ i ] . AddFrame ( nowTime ) ;
74
93
}
94
+
95
+ if ( recordBlendShape ) {
96
+ for ( int i = 0 ; i < blendShapeRecorders . Count ; i ++ ) {
97
+ blendShapeRecorders [ i ] . AddFrame ( nowTime ) ;
98
+ }
99
+ }
75
100
}
76
101
77
102
}
@@ -145,6 +170,18 @@ void ExportAnimationClip () {
145
170
}
146
171
}
147
172
173
+ if ( recordBlendShape ) {
174
+ for ( int i = 0 ; i < blendShapeRecorders . Count ; i ++ ) {
175
+
176
+ UnityCurveContainer [ ] curves = blendShapeRecorders [ i ] . curves ;
177
+
178
+ for ( int x = 0 ; x < curves . Length ; x ++ ) {
179
+ clip . SetCurve ( blendShapeRecorders [ i ] . pathName , typeof ( SkinnedMeshRenderer ) , curves [ x ] . propertyName , curves [ x ] . animCurve ) ;
180
+ }
181
+
182
+ }
183
+ }
184
+
148
185
clip . EnsureQuaternionContinuity ( ) ;
149
186
AssetDatabase . CreateAsset ( clip , exportFilePath ) ;
150
187
0 commit comments