Skip to content

Commit aec1d03

Browse files
authored
fix: sdk7 avatar shape transform-tween reaction (#6019)
* Added needed OnTransformChanged event call on sdk7 Transform handler and Tween systems, so that the AvatarShape can reacto to the transform modifications and interpolate accordingly. * Removed in modifier in some OnTransformChanged() methods
1 parent 0a70545 commit aec1d03

File tree

10 files changed

+25
-22
lines changed

10 files changed

+25
-22
lines changed

unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/AvatarShape/AvatarShape.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@ public void EnablePassport()
381381
onPointerDown.SetPassportEnabled(true);
382382
}
383383

384-
private void OnEntityTransformChanged(object newModel)
384+
private void OnEntityTransformChanged(Vector3 newPosition, Quaternion newRotation)
385385
{
386-
DCLTransform.Model newTransformModel = (DCLTransform.Model)newModel;
387-
OnEntityTransformChanged(newTransformModel.position, newTransformModel.rotation, !initializedPosition);
386+
OnEntityTransformChanged(newPosition, newRotation, !initializedPosition);
388387
}
389388

390-
private void OnEntityTransformChanged(in Vector3 position, in Quaternion rotation, bool inmediate)
389+
private void OnEntityTransformChanged(Vector3 position, Quaternion rotation, bool inmediate)
391390
{
392391
if (entity == null)
393392
return;

unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Transform/Handler/ECSTransformHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, ECSTr
9292

9393
if (scaleChange || rotationChange)
9494
sbcInternalComponent.OnTransformScaleRotationChanged(scene, entity);
95+
96+
// Same AvatarShape interpolation used at DCLTransform from SDK6
97+
entity.OnTransformChange?.Invoke(model.position, model.rotation);
9598
}
9699

97100
private static void ProcessNewParent(IParcelScene scene, IDCLEntity entity, long parentId)

unity-renderer/Assets/DCLPlugins/ECS7/Systems/TweenSystem/ECSTweenSystem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ private void UpdateTweenComponentModel(KeyValueSetTriplet<IParcelScene, long, EC
9494

9595
model.currentTime = currentTime;
9696
tweenInternalComponent.PutFor(scene, entityId, model);
97+
98+
// Same AvatarShape interpolation used at DCLTransform from SDK6
99+
entity.OnTransformChange?.Invoke(model.transform.localPosition, model.transform.localRotation);
97100
}
98101

99102
private void UpdateTransformComponent(IParcelScene scene, IDCLEntity entity, Transform entityTransform, ComponentWriter writer)

unity-renderer/Assets/DCLPlugins/ECS7/TestsUtils/ECS7TestEntity.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ Action<object> IDCLEntity.OnNameChange
132132
set => throw new NotImplementedException();
133133
}
134134

135-
Action<object> IDCLEntity.OnTransformChange
135+
Action<Vector3, Quaternion> IDCLEntity.OnTransformChange
136136
{
137-
get => throw new NotImplementedException();
138-
set => throw new NotImplementedException();
137+
get;
138+
set;
139139
}
140140

141141
public Action<IDCLEntity, bool> OnOuterBoundariesChanged

unity-renderer/Assets/Scripts/MainScripts/DCL/AvatarSystem/Definitions/IAvatarMovementController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public interface IAvatarMovementController
1515
/// </summary>
1616
/// <param name="avatarTransform"></param>
1717
void SetAvatarTransform(Transform avatarTransform);
18-
18+
1919
/// <summary>
2020
/// This will report the change of the transform, so it can be reported to kernel accordingly
2121
/// </summary>
2222
/// <param name="position"></param>
2323
/// <param name="rotation"></param>
24-
/// <param name="inmediate"></param>
25-
void OnTransformChanged(in Vector3 position, in Quaternion rotation, bool inmediate);
24+
/// <param name="immediate"></param>
25+
void OnTransformChanged(Vector3 position, Quaternion rotation, bool immediate);
2626
}
27-
}
27+
}

unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarMovementController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,19 @@ private void OnWorldReposition(Vector3 current, Vector3 previous)
9494
AvatarTransform.position = PositionUtils.WorldToUnityPosition(currentWorldPosition);
9595
}
9696

97-
public void OnTransformChanged(object model)
97+
public void OnTransformChanged(Vector3 newPosition, Quaternion newRotation)
9898
{
99-
DCLTransform.Model transformModel = (DCLTransform.Model)model;
100-
OnTransformChanged(transformModel.position, transformModel.rotation, false);
99+
OnTransformChanged(newPosition, newRotation, false);
101100
}
102101

103-
public void OnTransformChanged(in Vector3 position, in Quaternion rotation, bool inmediate)
102+
public void OnTransformChanged(Vector3 position, Quaternion rotation, bool immediate)
104103
{
105104
float characterMinHeight = DCLCharacterController.i.characterController.height * 0.5f;
106105

107106
MoveTo(
108107
new Vector3(position.x, Math.Max(position.y - characterMinHeight, -characterMinHeight), position.z), // To fix the "always flying" avatars issue, We report the chara's centered position but the body hast its pivot at its feet
109108
rotation,
110-
inmediate);
109+
immediate);
111110
}
112111

113112
public void MoveTo(Vector3 position, Quaternion rotation, bool immediate = false)

unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarShape.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,9 @@ private void Update()
374374
}
375375
}
376376

377-
private void OnEntityTransformChanged(object newModel)
377+
private void OnEntityTransformChanged(Vector3 newPosition, Quaternion newRotation)
378378
{
379-
DCLTransform.Model newTransformModel = (DCLTransform.Model)newModel;
380-
OnEntityTransformChanged(newTransformModel.position, newTransformModel.rotation, !initializedPosition);
379+
OnEntityTransformChanged(newPosition, newRotation, !initializedPosition);
381380
}
382381

383382
private void OnEntityTransformChanged(in Vector3 position, in Quaternion rotation, bool inmediate)

unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Transform/DCLTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void UpdateFromModel(BaseModel model)
7474
// and those values are used for the interpolation.
7575
if (entity.OnTransformChange != null)
7676
{
77-
entity.OnTransformChange.Invoke(DCLTransform.model);
77+
entity.OnTransformChange.Invoke(DCLTransform.model.position, DCLTransform.model.rotation);
7878
}
7979
else
8080
{

unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class DecentralandEntity : IDCLEntity
2828
public Action<IDCLEntity> OnShapeUpdated { get; set; }
2929
public Action<IDCLEntity> OnShapeLoaded { get; set; }
3030
public Action<object> OnNameChange { get; set; }
31-
public Action<object> OnTransformChange { get; set; }
31+
public Action<Vector3, Quaternion> OnTransformChange { get; set; }
3232
public Action<IDCLEntity> OnRemoved { get; set; }
3333
public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
3434
public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }

unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Interfaces/IDCLEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface IDCLEntity : ICleanable, ICleanableEventDispatcher
3131
Action<CLASS_ID_COMPONENT, IDCLEntity> OnBaseComponentAdded { get; set; }
3232

3333
Action<object> OnNameChange { get; set; }
34-
Action<object> OnTransformChange { get; set; }
34+
Action<Vector3, Quaternion> OnTransformChange { get; set; }
3535
Action<IDCLEntity, bool> OnInsideBoundariesChanged { get; set; }
3636
Action<IDCLEntity, bool> OnOuterBoundariesChanged { get; set; }
3737
long parentId { get; set; }

0 commit comments

Comments
 (0)