@@ -545,9 +545,7 @@ public static void calcControlPoints(Vector2 a, Vector2 b, Vector2 c, Vector2 d,
545
545
546
546
//this is not working method
547
547
public static void setCustomTangents ( AnimationCurve curve , int i , int nextI , JsonData tangentArray ) {
548
- Keyframe thisKeyframe = curve [ i ] ;
549
- Keyframe nextKeyframe = curve [ nextI ] ;
550
- float diff = nextKeyframe . value - thisKeyframe . value ;
548
+ float diff = curve [ i ] . value - curve [ nextI ] . value ;
551
549
if ( diff == 0 )
552
550
return ;
553
551
float cx1 = parseFloat ( tangentArray [ 0 ] ) ;
@@ -578,17 +576,36 @@ public static void setCustomTangents(AnimationCurve curve, int i, int nextI, Jso
578
576
Debug.Log("ewerything is "+(ok?"ok":"bad"));
579
577
*/
580
578
581
- c2 = p3 - c2 ;
579
+ c2 = c2 - p3 ;
582
580
583
581
float outTangent = c1 . y / c1 . x ;
584
582
float inTangent = c2 . y / c1 . y ;
585
583
586
- if ( nextKeyframe . value < thisKeyframe . value )
587
- inTangent *= - 1 ;
584
+ if ( diff < 0 ) {
585
+ inTangent *= - 1 ;
586
+ outTangent *= - 1 ;
587
+ }
588
+
589
+ object thisKeyframeBoxed = curve [ i ] ;
590
+ object nextKeyframeBoxed = curve [ nextI ] ;
591
+
592
+
593
+ if ( ! KeyframeUtil . isKeyBroken ( thisKeyframeBoxed ) ) {
594
+ KeyframeUtil . SetKeyBroken ( thisKeyframeBoxed , true ) ;
595
+ KeyframeUtil . SetKeyTangentMode ( thisKeyframeBoxed , 1 , TangentMode . Editable ) ;
596
+ }
597
+ if ( KeyframeUtil . isKeyBroken ( nextKeyframeBoxed ) ) {
598
+ KeyframeUtil . SetKeyBroken ( nextKeyframeBoxed , true ) ;
599
+ KeyframeUtil . SetKeyTangentMode ( nextKeyframeBoxed , 0 , TangentMode . Editable ) ;
600
+ }
601
+
602
+ Keyframe thisKeyframe = ( Keyframe ) thisKeyframeBoxed ;
603
+ Keyframe nextKeyframe = ( Keyframe ) nextKeyframeBoxed ;
588
604
589
605
thisKeyframe . outTangent = outTangent ;
590
606
nextKeyframe . inTangent = inTangent ;
591
607
608
+ Debug . Log ( "is broken = " + KeyframeUtil . isKeyBroken ( thisKeyframe ) ) ;
592
609
curve . MoveKey ( i , thisKeyframe ) ;
593
610
curve . MoveKey ( nextI , nextKeyframe ) ;
594
611
}
0 commit comments