Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: 20231127 #5975

Merged
merged 8 commits into from
Nov 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using DG.Tweening;
using System.Collections.Generic;
using UnityEngine;

using static DCL.ECSComponents.EasingFunction;
using static DG.Tweening.Ease;

Expand Down Expand Up @@ -49,6 +48,7 @@ public class ECSTweenHandler : IECSComponentHandler<PBTween>

private readonly IInternalECSComponent<InternalTween> internalTweenComponent;
private readonly IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent;
private Tweener currentTweener;

public ECSTweenHandler(IInternalECSComponent<InternalTween> internalTweenComponent, IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent)
{
Expand All @@ -60,6 +60,7 @@ public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }

public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
{
currentTweener.Kill(false);
internalTweenComponent.RemoveFor(scene, entity, new InternalTween()
{
removed = true
Expand All @@ -77,23 +78,22 @@ public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBTwe
bool isPlaying = !model.HasPlaying || model.Playing;

var internalComponentModel = internalTweenComponent.GetFor(scene, entity)?.model ?? new InternalTween();

if (!AreSameModels(model, internalComponentModel.lastModel))
{
Transform entityTransform = entity.gameObject.transform;
float durationInSeconds = model.Duration / 1000;
Tweener tweener = internalComponentModel.tweener;
currentTweener = internalComponentModel.tweener;

if (tweener == null)
if (currentTweener == null)
{
// There may be a tween running for the entity transform, even though internalComponentModel.tweener
// is null, e.g: during preview mode hot-reload.
var transformTweens = DOTween.TweensByTarget(entityTransform, true);
transformTweens?[0].Rewind();
transformTweens?[0].Rewind(false);
}
else
{
tweener.Rewind();
currentTweener.Rewind(false);
}

internalComponentModel.transform = entityTransform;
Expand All @@ -105,28 +105,28 @@ public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBTwe
switch (model.ModeCase)
{
case PBTween.ModeOneofCase.Rotate:
tweener = SetupRotationTween(scene, entity,
currentTweener = SetupRotationTween(scene, entity,
ProtoConvertUtils.PBQuaternionToUnityQuaternion(model.Rotate.Start),
ProtoConvertUtils.PBQuaternionToUnityQuaternion(model.Rotate.End),
durationInSeconds, ease);
break;
case PBTween.ModeOneofCase.Scale:
tweener = SetupScaleTween(scene, entity,
currentTweener = SetupScaleTween(scene, entity,
ProtoConvertUtils.PBVectorToUnityVector(model.Scale.Start),
ProtoConvertUtils.PBVectorToUnityVector(model.Scale.End),
durationInSeconds, ease);
break;
case PBTween.ModeOneofCase.Move:
default:
tweener = SetupPositionTween(scene, entity,
currentTweener = SetupPositionTween(scene, entity,
ProtoConvertUtils.PBVectorToUnityVector(model.Move.Start),
ProtoConvertUtils.PBVectorToUnityVector(model.Move.End),
durationInSeconds, ease, model.Move.HasFaceDirection && model.Move.FaceDirection);
break;
}

tweener.Goto(model.CurrentTime * durationInSeconds, isPlaying);
internalComponentModel.tweener = tweener;
currentTweener.Goto(model.CurrentTime * durationInSeconds, isPlaying);
internalComponentModel.tweener = currentTweener;
internalComponentModel.tweenMode = model.ModeCase;
}
else if (internalComponentModel.playing == isPlaying)
Expand Down Expand Up @@ -178,7 +178,7 @@ private Tweener SetupRotationTween(IParcelScene scene, IDCLEntity entity, Quater
return tweener;
}

Tweener SetupScaleTween(IParcelScene scene, IDCLEntity entity, Vector3 startScale,
private Tweener SetupScaleTween(IParcelScene scene, IDCLEntity entity, Vector3 startScale,
Vector3 endScale, float durationInSeconds, Ease ease)
{
var entityTransform = entity.gameObject.transform;
Expand All @@ -190,7 +190,7 @@ Tweener SetupScaleTween(IParcelScene scene, IDCLEntity entity, Vector3 startScal
return tweener;
}

Tweener SetupPositionTween(IParcelScene scene, IDCLEntity entity, Vector3 startPosition,
private Tweener SetupPositionTween(IParcelScene scene, IDCLEntity entity, Vector3 startPosition,
Vector3 endPosition, float durationInSeconds, Ease ease, bool faceDirection)
{
var entityTransform = entity.gameObject.transform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,33 @@ public void HandleCustomInitialCurrentTime()
var transformTweens = DOTween.TweensByTarget(entityTransform, true);
Assert.AreEqual(initialTime, transformTweens[0].ElapsedPercentage());
}

[Test]
public void KillTweenerImmediatelyOnComponentRemove()
{
Vector3 startScale = Vector3.one;
Vector3 endScale = new Vector3(5f, 5f, 5f);

var model = new PBTween()
{
Duration = 3000,
Scale = new Scale()
{
Start = new Decentraland.Common.Vector3() { X = startScale.x, Y = startScale.y, Z = startScale.z },
End = new Decentraland.Common.Vector3() { X = endScale.x, Y = endScale.y, Z = endScale.z }
},
Playing = true
};

componentHandler.OnComponentModelUpdated(scene, entity, model);

// Check tween is running
var tweens = DOTween.PlayingTweens();
Assert.AreEqual(1, tweens.Count);

componentHandler.OnComponentRemoved(scene, entity);
tweens = DOTween.PlayingTweens();
Assert.IsNull(tweens);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private void UpdateTweenComponentModel(KeyValueSetTriplet<IParcelScene, long, EC

if (model.removed)
{
model.tweener.Kill();
writer.Remove(entityId, ComponentID.TWEEN_STATE);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 3070034299990149503}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 21.470001, y: -1}
m_SizeDelta: {x: 15.47, y: 18}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 21.470001, y: 0}
m_SizeDelta: {x: 0, y: 18}
m_Pivot: {x: 1, y: 1}
--- !u!222 &855587454889126652
CanvasRenderer:
Expand Down Expand Up @@ -793,7 +793,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &3070034299990149503
RectTransform:
m_ObjectHideFlags: 0
Expand All @@ -809,11 +809,11 @@ RectTransform:
- {fileID: 8386155808995088844}
m_Father: {fileID: 4635205700294361718}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 126, y: -106}
m_SizeDelta: {x: 27.470001, y: 20}
m_Pivot: {x: 1, y: 1}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -2.5, y: 2.5}
m_SizeDelta: {x: 0, y: 20}
m_Pivot: {x: 1, y: 0}
--- !u!222 &1699403652616276435
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -851,7 +851,7 @@ MonoBehaviour:
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 3.5
m_PixelsPerUnitMultiplier: 4
--- !u!114 &8216168553677623558
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ RectTransform:
m_Father: {fileID: 661289199007478368}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 10}
m_SizeDelta: {x: 0, y: -20}
m_Pivot: {x: 0.5, y: 0}
Expand Down Expand Up @@ -622,7 +622,7 @@ MonoBehaviour:
m_Left: 15
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Bottom: 100
m_ChildAlignment: 0
m_Spacing: 0
m_ChildForceExpandWidth: 1
Expand Down Expand Up @@ -663,7 +663,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &661289199007478368
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2066,7 +2066,7 @@ PrefabInstance:
- target: {fileID: 2026062374757361563, guid: a0b08d9ca8421644db83c1bd3f2e2e48,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2026062374757361563, guid: a0b08d9ca8421644db83c1bd3f2e2e48,
type: 3}
Expand All @@ -2076,12 +2076,12 @@ PrefabInstance:
- target: {fileID: 2026062374757361563, guid: a0b08d9ca8421644db83c1bd3f2e2e48,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2026062374757361563, guid: a0b08d9ca8421644db83c1bd3f2e2e48,
type: 3}
propertyPath: m_SizeDelta.x
value: 1455
value: 2106
objectReference: {fileID: 0}
- target: {fileID: 2026062374757361563, guid: a0b08d9ca8421644db83c1bd3f2e2e48,
type: 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void SendWearableCreatorGoTo(string creatorName) =>
public void SendAvatarEditSuccessNuxAnalytic() =>
newUserExperienceAnalytics.AvatarEditSuccessNux();

public void SendEquipWearableAnalytic(string category, string rarity, EquipWearableSource source)
public void SendEquipWearableAnalytic(string id, string category, string rarity, EquipWearableSource source)
{
Dictionary<string, string> data = new Dictionary<string, string>
{
Expand All @@ -87,7 +87,7 @@ public void SendEquipWearableAnalytic(string category, string rarity, EquipWeara
analytics.SendAnalytic(EQUIP_WEARABLE_METRIC, data);
}

public void SendUnequippedWearableAnalytic(string category, string rarity, UnequipWearableSource source)
public void SendUnequippedWearableAnalytic(string id, string category, string rarity, UnequipWearableSource source)
{
Dictionary<string, string> data = new Dictionary<string, string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ private void EquipWearable(WearableItem wearable,
avatarIsDirty = true;

if (source != EquipWearableSource.None)
backpackAnalyticsService.SendEquipWearableAnalytic(wearable.data.category, wearable.rarity, source);
backpackAnalyticsService.SendEquipWearableAnalytic(wearable.id, wearable.data.category, wearable.rarity, source);

if (updateAvatarPreview)
{
Expand Down Expand Up @@ -685,7 +685,7 @@ private void UnEquipWearable(WearableItem wearable,
string wearableId = wearable.id;

if (source != UnequipWearableSource.None)
backpackAnalyticsService.SendUnequippedWearableAnalytic(wearable.data.category, wearable.rarity, source);
backpackAnalyticsService.SendUnequippedWearableAnalytic(wearable.id, wearable.data.category, wearable.rarity, source);

ResetOverridesOfAffectedCategories(wearable, setAsDirty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface IBackpackAnalyticsService
void SendWearablePreviewRotated();
void SendWearableCreatorGoTo(string creatorName);
void SendAvatarEditSuccessNuxAnalytic();
void SendEquipWearableAnalytic(string category, string rarity, EquipWearableSource source);
void SendUnequippedWearableAnalytic(string category, string rarity, UnequipWearableSource source);
void SendEquipWearableAnalytic(string id, string category, string rarity, EquipWearableSource source);
void SendUnequippedWearableAnalytic(string id, string category, string rarity, UnequipWearableSource source);
void SendAvatarColorPick();
void SendForceHideWearable(string category);
void SendForceShowWearable(string category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ RectTransform:
- {fileID: 5888312532399504360}
m_Father: {fileID: 2293051074121960227}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 51.2, y: 51}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -6, y: -6}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
m_Pivot: {x: 1, y: 1}
--- !u!222 &1389017365883158615
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -659,11 +659,11 @@ RectTransform:
- {fileID: 2044936580504766235}
m_Father: {fileID: 2293051074121960227}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 130.3, y: -109.099976}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -6, y: 6}
m_SizeDelta: {x: 0, y: 20}
m_Pivot: {x: 1, y: 1}
m_Pivot: {x: 1, y: 0}
--- !u!222 &4210780993511388512
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -701,7 +701,7 @@ MonoBehaviour:
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 3.5
m_PixelsPerUnitMultiplier: 4
--- !u!114 &5386043443272512827
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2317,8 +2317,8 @@ RectTransform:
- {fileID: 5071096869884117952}
- {fileID: 3578954038529326123}
- {fileID: 1743110760381771954}
- {fileID: 4598811192155891101}
- {fileID: 3297396670104606826}
- {fileID: 4598811192155891101}
- {fileID: 4558418130336684269}
- {fileID: 8152899778130412207}
- {fileID: 2667185010987982867}
Expand All @@ -2332,7 +2332,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 85.64746, y: 0}
m_SizeDelta: {x: 140, y: 140}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &5451991589991224328
Expand Down Expand Up @@ -2790,11 +2790,11 @@ RectTransform:
- {fileID: 1004753941569948756}
m_Father: {fileID: 2293051074121960227}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 94, y: -109.1}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -6, y: 6}
m_SizeDelta: {x: 36, y: 20}
m_Pivot: {x: 0, y: 1}
m_Pivot: {x: 1, y: 0}
--- !u!222 &2629571911631745412
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2832,7 +2832,7 @@ MonoBehaviour:
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 3.5
m_PixelsPerUnitMultiplier: 4
--- !u!1 &9110061562146683237
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public void SendAvatarEditSuccessNuxAnalyticCorrectly()
[Test]
public void SendEquipAnalyticCorrectly()
{
backpackAnalyticsService.SendEquipWearableAnalytic("testcat", "rare", EquipWearableSource.Wearable);
backpackAnalyticsService.SendEquipWearableAnalytic("testid", "testcat", "rare", EquipWearableSource.Wearable);

analytics.Received(1).SendAnalytic("equip_wearable", Arg.Any<Dictionary<string, string>>());
}

[Test]
public void SendUnEquipAnalyticCorrectly()
{
backpackAnalyticsService.SendUnequippedWearableAnalytic("testcat", "rare", UnequipWearableSource.AvatarSlot);
backpackAnalyticsService.SendUnequippedWearableAnalytic("testid", "testcat", "rare", UnequipWearableSource.AvatarSlot);

analytics.Received(1).SendAnalytic("unequip_wearable", Arg.Any<Dictionary<string, string>>());
}
Expand Down
Loading
Loading