@@ -1227,6 +1227,14 @@ private void GenerateMissingCurves(float endTime, Transform tr, ref Dictionary<s
12271227 foreach ( var kvp in current . propertyCurves )
12281228 {
12291229 var prop = kvp . Value ;
1230+
1231+ void AddMissingCurve ( string curveName , float constantValue )
1232+ {
1233+ var curve = CreateConstantCurve ( constantValue , endTime ) ;
1234+ prop . curve . Add ( curve ) ;
1235+ prop . curveName . Add ( curveName ) ;
1236+ }
1237+
12301238 if ( prop . propertyType == typeof ( Color ) )
12311239 {
12321240 // In case of colors, but Unity uses x,y,z,w for the channel names, we convert them to r,g,b,a
@@ -1262,11 +1270,68 @@ private void GenerateMissingCurves(float endTime, Transform tr, ref Dictionary<s
12621270 if ( ! hasBlueChannel ) AddMissingCurve ( memberName + ".b" , col . b ) ;
12631271 if ( ! hasAlphaChannel ) AddMissingCurve ( memberName + ".a" , col . a ) ;
12641272
1265- void AddMissingCurve ( string curveName , float constantValue )
1273+ }
1274+ }
1275+
1276+ if ( prop . propertyType == typeof ( Vector2 ) )
1277+ {
1278+ if ( prop . propertyName == "anchoredPosition" || prop . propertyName == "sizeDelta" || prop . propertyName == "pivot" )
1279+ {
1280+ // Generate missing Vector2 curves (so a Vector2 always has keyframes for both channels)
1281+ var memberName = prop . propertyName ;
1282+ if ( TryGetCurrentValue ( prop . target , memberName , out var value ) )
1283+ {
1284+ var vec = ( Vector2 ) value ;
1285+
1286+ var hasX = prop . FindIndex ( v => v . EndsWith ( ".x" ) ) >= 0 ;
1287+ var hasY = prop . FindIndex ( v => v . EndsWith ( ".y" ) ) >= 0 ;
1288+
1289+ if ( ! hasX ) AddMissingCurve ( memberName + ".x" , vec . x ) ;
1290+ if ( ! hasY ) AddMissingCurve ( memberName + ".y" , vec . y ) ;
1291+ }
1292+ }
1293+ }
1294+
1295+ if ( prop . propertyType == typeof ( Vector3 ) )
1296+ {
1297+ if ( prop . propertyName == "localPosition" || prop . propertyName == "position" || prop . propertyName == "localScale" || prop . propertyName == "scale" )
1298+ {
1299+ // Generate missing transform curves (so a transform always has keyframes for all 3 channels)
1300+ var memberName = prop . propertyName ;
1301+ if ( TryGetCurrentValue ( prop . target , memberName , out var value ) )
1302+ {
1303+ var vec = ( Vector3 ) value ;
1304+
1305+ var hasX = prop . FindIndex ( v => v . EndsWith ( ".x" ) ) >= 0 ;
1306+ var hasY = prop . FindIndex ( v => v . EndsWith ( ".y" ) ) >= 0 ;
1307+ var hasZ = prop . FindIndex ( v => v . EndsWith ( ".z" ) ) >= 0 ;
1308+
1309+ if ( ! hasX ) AddMissingCurve ( memberName + ".x" , vec . x ) ;
1310+ if ( ! hasY ) AddMissingCurve ( memberName + ".y" , vec . y ) ;
1311+ if ( ! hasZ ) AddMissingCurve ( memberName + ".z" , vec . z ) ;
1312+ }
1313+ }
1314+ }
1315+ if ( prop . propertyType == typeof ( Vector4 ) )
1316+ {
1317+ if ( prop . propertyName == "localRotation" || prop . propertyName == "rotation" )
1318+ {
1319+ // Generate missing rotation curves (so a rotation always has keyframes for all 4 channels)
1320+ var memberName = prop . propertyName ;
1321+ if ( TryGetCurrentValue ( prop . target , memberName , out var value ) )
12661322 {
1267- var curve = CreateConstantCurve ( constantValue , endTime ) ;
1268- prop . curve . Add ( curve ) ;
1269- prop . curveName . Add ( curveName ) ;
1323+ var vec = ( Quaternion ) value ;
1324+
1325+ var hasX = prop . FindIndex ( v => v . EndsWith ( ".x" ) ) >= 0 ;
1326+ var hasY = prop . FindIndex ( v => v . EndsWith ( ".y" ) ) >= 0 ;
1327+ var hasZ = prop . FindIndex ( v => v . EndsWith ( ".z" ) ) >= 0 ;
1328+ var hasW = prop . FindIndex ( v => v . EndsWith ( ".w" ) ) >= 0 ;
1329+
1330+ if ( ! hasX ) AddMissingCurve ( memberName + ".x" , vec . x ) ;
1331+ if ( ! hasY ) AddMissingCurve ( memberName + ".y" , vec . y ) ;
1332+ if ( ! hasZ ) AddMissingCurve ( memberName + ".z" , vec . z ) ;
1333+ if ( ! hasW ) AddMissingCurve ( memberName + ".w" , vec . w ) ;
1334+
12701335 }
12711336 }
12721337 }
0 commit comments