@@ -161,8 +161,18 @@ public void AnticipateMove(Vector3 newPosition)
161161 {
162162 return ;
163163 }
164- transform . position = newPosition ;
164+
165+ if ( InLocalSpace )
166+ {
167+ transform . localPosition = newPosition ;
168+ }
169+ else
170+ {
171+ transform . position = newPosition ;
172+ }
173+
165174 m_AnticipatedTransform . Position = newPosition ;
175+
166176 if ( CanCommitToTransform )
167177 {
168178 m_AuthoritativeTransform . Position = newPosition ;
@@ -187,7 +197,15 @@ public void AnticipateRotate(Quaternion newRotation)
187197 {
188198 return ;
189199 }
190- transform . rotation = newRotation ;
200+
201+ if ( InLocalSpace )
202+ {
203+ transform . localRotation = newRotation ;
204+ }
205+ else
206+ {
207+ transform . rotation = newRotation ;
208+ }
191209 m_AnticipatedTransform . Rotation = newRotation ;
192210 if ( CanCommitToTransform )
193211 {
@@ -240,7 +258,14 @@ public void AnticipateState(TransformState newState)
240258 return ;
241259 }
242260 var transform_ = transform ;
243- transform_ . SetPositionAndRotation ( newState . Position , newState . Rotation ) ;
261+ if ( InLocalSpace )
262+ {
263+ transform_ . SetLocalPositionAndRotation ( newState . Position , newState . Rotation ) ;
264+ }
265+ else
266+ {
267+ transform_ . SetPositionAndRotation ( newState . Position , newState . Rotation ) ;
268+ }
244269 transform_ . localScale = newState . Scale ;
245270 m_AnticipatedTransform = newState ;
246271 if ( CanCommitToTransform )
@@ -277,7 +302,17 @@ private void ProcessSmoothing()
277302 m_PreviousAnticipatedTransform = m_AnticipatedTransform ;
278303 if ( ! CanCommitToTransform )
279304 {
280- transform_ . SetPositionAndRotation ( m_AnticipatedTransform . Position , m_AnticipatedTransform . Rotation ) ;
305+ if ( InLocalSpace )
306+ {
307+ transform_ . SetLocalPositionAndRotation ( m_AnticipatedTransform . Position ,
308+ m_AnticipatedTransform . Rotation ) ;
309+ }
310+ else
311+ {
312+ transform_ . SetPositionAndRotation ( m_AnticipatedTransform . Position ,
313+ m_AnticipatedTransform . Rotation ) ;
314+ }
315+
281316 transform_ . localScale = m_AnticipatedTransform . Scale ;
282317 }
283318 }
@@ -320,12 +355,25 @@ public void SetupForRender()
320355 if ( Transform . CanCommitToTransform )
321356 {
322357 var transform_ = Transform . transform ;
323- Transform . m_AuthoritativeTransform = new TransformState
358+ if ( Transform . InLocalSpace )
324359 {
325- Position = transform_ . position ,
326- Rotation = transform_ . rotation ,
327- Scale = transform_ . localScale
328- } ;
360+ Transform . m_AuthoritativeTransform = new TransformState
361+ {
362+ Position = transform_ . localPosition ,
363+ Rotation = transform_ . localRotation ,
364+ Scale = transform_ . localScale
365+ } ;
366+ }
367+ else
368+ {
369+ Transform . m_AuthoritativeTransform = new TransformState
370+ {
371+ Position = transform_ . position ,
372+ Rotation = transform_ . rotation ,
373+ Scale = transform_ . localScale
374+ } ;
375+ }
376+
329377 if ( Transform . m_CurrentSmoothTime >= Transform . m_SmoothDuration )
330378 {
331379 // If we've had a call to Smooth() we'll continue interpolating.
@@ -334,7 +382,17 @@ public void SetupForRender()
334382 Transform . m_AnticipatedTransform = Transform . m_AuthoritativeTransform ;
335383 }
336384
337- transform_ . SetPositionAndRotation ( Transform . m_AnticipatedTransform . Position , Transform . m_AnticipatedTransform . Rotation ) ;
385+ if ( Transform . InLocalSpace )
386+ {
387+ transform_ . SetLocalPositionAndRotation ( Transform . m_AnticipatedTransform . Position ,
388+ Transform . m_AnticipatedTransform . Rotation ) ;
389+ }
390+ else
391+ {
392+ transform_ . SetPositionAndRotation ( Transform . m_AnticipatedTransform . Position ,
393+ Transform . m_AnticipatedTransform . Rotation ) ;
394+ }
395+
338396 transform_ . localScale = Transform . m_AnticipatedTransform . Scale ;
339397 }
340398 }
@@ -344,7 +402,17 @@ public void SetupForUpdate()
344402 if ( Transform . CanCommitToTransform )
345403 {
346404 var transform_ = Transform . transform ;
347- transform_ . SetPositionAndRotation ( Transform . m_AuthoritativeTransform . Position , Transform . m_AuthoritativeTransform . Rotation ) ;
405+ if ( Transform . InLocalSpace )
406+ {
407+ transform_ . SetLocalPositionAndRotation ( Transform . m_AuthoritativeTransform . Position ,
408+ Transform . m_AuthoritativeTransform . Rotation ) ;
409+ }
410+ else
411+ {
412+ transform_ . SetPositionAndRotation ( Transform . m_AuthoritativeTransform . Position ,
413+ Transform . m_AuthoritativeTransform . Rotation ) ;
414+ }
415+
348416 transform_ . localScale = Transform . m_AuthoritativeTransform . Scale ;
349417 }
350418 }
@@ -367,12 +435,25 @@ public void ResetAnticipation()
367435 private void ResetAnticipatedState ( )
368436 {
369437 var transform_ = transform ;
370- m_AuthoritativeTransform = new TransformState
438+ if ( InLocalSpace )
439+ {
440+ m_AuthoritativeTransform = new TransformState
441+ {
442+ Position = transform_ . localPosition ,
443+ Rotation = transform_ . localRotation ,
444+ Scale = transform_ . localScale
445+ } ;
446+ }
447+ else
371448 {
372- Position = transform_ . position ,
373- Rotation = transform_ . rotation ,
374- Scale = transform_ . localScale
375- } ;
449+ m_AuthoritativeTransform = new TransformState
450+ {
451+ Position = transform_ . position ,
452+ Rotation = transform_ . rotation ,
453+ Scale = transform_ . localScale
454+ } ;
455+ }
456+
376457 m_AnticipatedTransform = m_AuthoritativeTransform ;
377458 m_PreviousAnticipatedTransform = m_AnticipatedTransform ;
378459
@@ -439,7 +520,7 @@ public override void OnNetworkSpawn()
439520 return ;
440521 }
441522 m_OutstandingAuthorityChange = true ;
442- ApplyAuthoritativeState ( ) ;
523+ // ApplyAuthoritativeState();
443524 ResetAnticipatedState ( ) ;
444525
445526 m_AnticipatedObject = new AnticipatedObject { Transform = this } ;
@@ -491,7 +572,15 @@ public void Smooth(TransformState from, TransformState to, float durationSeconds
491572 {
492573 m_AnticipatedTransform = to ;
493574 m_PreviousAnticipatedTransform = m_AnticipatedTransform ;
494- transform_ . SetPositionAndRotation ( to . Position , to . Rotation ) ;
575+ if ( InLocalSpace )
576+ {
577+ transform_ . SetLocalPositionAndRotation ( to . Position , to . Rotation ) ;
578+ }
579+ else
580+ {
581+ transform_ . SetPositionAndRotation ( to . Position , to . Rotation ) ;
582+ }
583+
495584 transform_ . localScale = to . Scale ;
496585 m_SmoothDuration = 0 ;
497586 m_CurrentSmoothTime = 0 ;
@@ -502,7 +591,15 @@ public void Smooth(TransformState from, TransformState to, float durationSeconds
502591
503592 if ( ! CanCommitToTransform )
504593 {
505- transform_ . SetPositionAndRotation ( from . Position , from . Rotation ) ;
594+ if ( InLocalSpace )
595+ {
596+ transform_ . SetLocalPositionAndRotation ( from . Position , from . Rotation ) ;
597+ }
598+ else
599+ {
600+ transform_ . SetPositionAndRotation ( from . Position , from . Rotation ) ;
601+ }
602+
506603 transform_ . localScale = from . Scale ;
507604 }
508605
@@ -543,22 +640,48 @@ protected override void OnTransformUpdated()
543640 var previousAnticipatedTransform = m_AnticipatedTransform ;
544641
545642 // Update authority state to catch any possible interpolation data
546- m_AuthoritativeTransform . Position = transform_ . position ;
547- m_AuthoritativeTransform . Rotation = transform_ . rotation ;
548- m_AuthoritativeTransform . Scale = transform_ . localScale ;
643+ if ( InLocalSpace )
644+ {
645+ m_AuthoritativeTransform . Position = transform_ . localPosition ;
646+ m_AuthoritativeTransform . Rotation = transform_ . localRotation ;
647+ m_AuthoritativeTransform . Scale = transform_ . localScale ;
648+ }
649+ else
650+ {
651+ m_AuthoritativeTransform . Position = transform_ . position ;
652+ m_AuthoritativeTransform . Rotation = transform_ . rotation ;
653+ m_AuthoritativeTransform . Scale = transform_ . localScale ;
654+ }
549655
550656 if ( ! m_OutstandingAuthorityChange )
551657 {
552658 // Keep the anticipated value unchanged, we have no updates from the server at all.
553- transform_ . SetPositionAndRotation ( previousAnticipatedTransform . Position , previousAnticipatedTransform . Rotation ) ;
659+ if ( InLocalSpace )
660+ {
661+ transform_ . SetLocalPositionAndRotation ( previousAnticipatedTransform . Position , previousAnticipatedTransform . Rotation ) ;
662+ }
663+ else
664+ {
665+ transform_ . SetPositionAndRotation ( previousAnticipatedTransform . Position , previousAnticipatedTransform . Rotation ) ;
666+ }
554667 transform_ . localScale = previousAnticipatedTransform . Scale ;
555668 return ;
556669 }
557670
558671 if ( StaleDataHandling == StaleDataHandling . Ignore && m_LastAnticipaionCounter > m_LastAuthorityUpdateCounter )
559672 {
560673 // Keep the anticipated value unchanged because it is more recent than the authoritative one.
561- transform_ . SetPositionAndRotation ( previousAnticipatedTransform . Position , previousAnticipatedTransform . Rotation ) ;
674+ if ( InLocalSpace )
675+ {
676+ transform_ . SetLocalPositionAndRotation ( previousAnticipatedTransform . Position ,
677+ previousAnticipatedTransform . Rotation ) ;
678+ }
679+ else
680+ {
681+ transform_ . SetPositionAndRotation ( previousAnticipatedTransform . Position ,
682+ previousAnticipatedTransform . Rotation ) ;
683+ }
684+
562685 transform_ . localScale = previousAnticipatedTransform . Scale ;
563686 return ;
564687 }
0 commit comments