@@ -286,24 +286,24 @@ private void ConvertInterpolateStateValues(Transform parent, bool inLocalSpace)
286
286
}
287
287
288
288
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
289
- private void ConvertTransformSpace ( )
289
+ private void ConvertTransformSpace ( BufferedItem newTarget )
290
290
{
291
291
if ( ! AutoConvertTransformSpace )
292
292
{
293
293
return ;
294
294
}
295
- if ( InterpolateState . TargetParent != Parent )
295
+ if ( InterpolateState . TargetParent != newTarget . MeasurementParent )
296
296
{
297
297
if ( InterpolateState . TargetParent != null )
298
298
{
299
299
// Convert to world space or local space depending upon what our current parent is.
300
300
ConvertInterpolateStateValues ( InterpolateState . TargetParent , false ) ;
301
301
}
302
302
303
- if ( Parent != null )
303
+ if ( newTarget . MeasurementParent != null )
304
304
{
305
305
// Convert to local space.
306
- ConvertInterpolateStateValues ( Parent , true ) ;
306
+ ConvertInterpolateStateValues ( newTarget . MeasurementParent , true ) ;
307
307
}
308
308
}
309
309
}
@@ -366,7 +366,7 @@ private void TryConsumeFromBuffer(double renderTime, double minDeltaTime, double
366
366
{
367
367
if ( m_BufferQueue . TryDequeue ( out BufferedItem target ) )
368
368
{
369
- ConvertTransformSpace ( ) ;
369
+ ConvertTransformSpace ( target ) ;
370
370
371
371
if ( ! InterpolateState . Target . HasValue )
372
372
{
@@ -516,7 +516,7 @@ private void TryConsumeFromBuffer(double renderTime, double serverTime)
516
516
{
517
517
if ( m_BufferQueue . TryDequeue ( out BufferedItem target ) )
518
518
{
519
- ConvertTransformSpace ( ) ;
519
+ ConvertTransformSpace ( target ) ;
520
520
if ( ! InterpolateState . Target . HasValue )
521
521
{
522
522
InterpolateState . Target = target ;
@@ -679,6 +679,29 @@ internal void AddMeasurement(Transform parent, T newMeasurement, double sentTime
679
679
}
680
680
}
681
681
682
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
683
+ private T GetParentRelativeValue ( T currentValue )
684
+ {
685
+ if ( ! AutoConvertTransformSpace || InterpolateState . TargetParent == Parent )
686
+ {
687
+ return currentValue ;
688
+ }
689
+
690
+ // Just convert on the fly until the next state is reached where it will do a full
691
+ // conversion when popped from the queue.
692
+ if ( InterpolateState . TargetParent )
693
+ {
694
+ currentValue = OnConvertTransformSpace ( InterpolateState . TargetParent , currentValue , false ) ;
695
+ }
696
+
697
+ if ( Parent != null )
698
+ {
699
+ var previousCurrent = currentValue . ToString ( ) ;
700
+ currentValue = OnConvertTransformSpace ( Parent , currentValue , true ) ;
701
+ }
702
+ return currentValue ;
703
+ }
704
+
682
705
/// <summary>
683
706
/// Gets latest value from the interpolator. This is updated every update as time goes by.
684
707
/// </summary>
@@ -689,16 +712,17 @@ public T GetInterpolatedValue()
689
712
var currentValue = InterpolateState . CurrentValue ;
690
713
if ( AutoConvertTransformSpace && InterpolateState . TargetParent != Parent )
691
714
{
692
- // Just convert on the fly until the next state is reached where it will do a full
693
- // conversion when popped from the queue.
694
- if ( InterpolateState . TargetParent != null )
695
- {
696
- currentValue = OnConvertTransformSpace ( InterpolateState . TargetParent , currentValue , false ) ;
697
- }
715
+ currentValue = GetParentRelativeValue ( currentValue ) ;
698
716
699
- if ( Parent != null )
717
+ // When there are no more states and we have reached our target,
718
+ // hijack the last state as if it was submitted by the current
719
+ // parent.
720
+ if ( m_BufferQueue . Count == 0 && ( InterpolateState . TargetReached || ! InterpolateState . Target . HasValue ) )
700
721
{
701
- currentValue = OnConvertTransformSpace ( Parent , currentValue , true ) ;
722
+ InterpolateState . CurrentValue = currentValue ;
723
+ InterpolateState . NextValue = currentValue ;
724
+ InterpolateState . PreviousValue = currentValue ;
725
+ InterpolateState . TargetParent = Parent ;
702
726
}
703
727
}
704
728
return currentValue ;
0 commit comments