Skip to content

Commit

Permalink
fix: map avatar points (#1893)
Browse files Browse the repository at this point in the history
* MinimapPlugin AsUniTaskResult, remove unnecessary state machine creation

* nullables

* HotUserMarkerObject internal initialize

* fix points and avatar instantiation after clean-up
  • Loading branch information
NickKhalow authored Aug 27, 2024
1 parent b846bb4 commit 5446349
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ private void CreateAvatar(ICharacterControllerSettings characterControllerSettin

transformComp.Transform.name = $"RANDOM_AVATAR_{avatarIndex}";

CharacterController characterController = transformComp.Transform.gameObject.AddComponent<CharacterController>();
CharacterController characterController = transformComp.Transform.TryGetComponent<CharacterController>(out var component)
? component
: transformComp.Transform.gameObject.AddComponent<CharacterController>();
characterController.radius = 0.4f;
characterController.height = 2;
characterController.center = Vector3.up;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4175020263976144273}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
Expand All @@ -31,7 +32,6 @@ Transform:
- {fileID: 3972535992487305214}
- {fileID: 1882238951119396974}
m_Father: {fileID: 6490643975463183000}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6634102564137692517
GameObject:
Expand All @@ -57,14 +57,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6634102564137692517}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8293322612040113748}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6723780352267149330
MonoBehaviour:
Expand All @@ -79,7 +79,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
<pivot>k__BackingField: {x: 0.5, y: 0.5}
<spriteRenderers>k__BackingField:
spriteRenderers:
- {fileID: 6574531059262994368}
- {fileID: 6527134346746202169}
--- !u!1 &8549977302113203150
Expand All @@ -106,13 +106,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8549977302113203150}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.45, y: 0.45, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8293322612040113748}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &6574531059262994368
SpriteRenderer:
Expand Down Expand Up @@ -190,13 +190,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9041844299909259778}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.026}
m_LocalScale: {x: 0.38, y: 0.38, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8293322612040113748}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &6527134346746202169
SpriteRenderer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DCL.MapRenderer.Culling;
using DCL.MapRenderer.MapLayers;
using DCL.MapRenderer.MapLayers.Users;
using DCL.MapRenderer.MapLayers.UsersMarker;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
Expand Down Expand Up @@ -50,10 +51,7 @@ IHotUserMarker CreateWrap() =>
private static HotUserMarkerObject CreatePoolMethod(MapRendererConfiguration configuration, HotUserMarkerObject prefab, ICoordsUtils coordsUtils)
{
HotUserMarkerObject markerObject = Object.Instantiate(prefab, configuration.HotUserMarkersRoot);

for (var i = 0; i < markerObject.spriteRenderers.Length; i++)
markerObject.spriteRenderers[i].sortingOrder = MapRendererDrawOrder.HOT_USER_MARKERS;

markerObject.UpdateSortOrder(MapRendererDrawOrder.HOT_USER_MARKERS);
coordsUtils.SetObjectScale(markerObject);
return markerObject;
}
Expand Down
1 change: 1 addition & 0 deletions Explorer/Assets/DCL/MapRenderer/ConsumerUtils/csc.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-nullable:enable
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/MapRenderer/ConsumerUtils/csc.rsp.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Explorer/Assets/DCL/MapRenderer/IMapRendererSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DCL.MapRenderer.MapLayers.PlayerMarker;
using DCL.MapRenderer.MapLayers.PointsOfInterest;
using DCL.MapRenderer.MapLayers.Users;
using DCL.MapRenderer.MapLayers.UsersMarker;
using System;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Cysharp.Threading.Tasks;
using DCL.MapRenderer.CommonBehavior;
using DCL.MapRenderer.CommonBehavior;
using DCL.MapRenderer.CoordsUtils;
using DCL.MapRenderer.Culling;
using System.Threading;
using DCL.MapRenderer.MapLayers.UsersMarker;
using UnityEngine;
using UnityEngine.Pool;
using Utility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using UnityEngine;
using System;
using UnityEngine;

namespace DCL.MapRenderer.MapLayers.Users
namespace DCL.MapRenderer.MapLayers.UsersMarker
{
public class HotUserMarkerObject : MapRendererMarkerBase
{
[field: SerializeField]
internal SpriteRenderer[] spriteRenderers { get; private set; }
private SpriteRenderer[] spriteRenderers = Array.Empty<SpriteRenderer>();

public void UpdateSortOrder(int sortingOrder)
{
for (var i = 0; i < spriteRenderers.Length; i++)
spriteRenderers[i].sortingOrder = sortingOrder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using DCL.CharacterPreview.Components;
using DCL.MapRenderer.CoordsUtils;
using DCL.MapRenderer.Culling;
using DCL.MapRenderer.MapLayers.UsersMarker;
using ECS.Groups;
using ECS.LifeCycle.Components;
using MVC;
using System.Collections.Generic;
Expand Down Expand Up @@ -55,15 +57,14 @@ public void CreateSystems(ref ArchSystemsWorldBuilder<World> builder)
untrackSystem.Activate();
}

[All(typeof(CharacterTransform))]
[None(typeof(PlayerComponent), typeof(CharacterPreviewComponent))]
[Query]
[None(typeof(PlayerComponent), typeof(CharacterPreviewComponent), typeof(DeleteEntityIntention))]
private void SetPlayerMarker(in CharacterTransform transformComponent, in AvatarShapeComponent avatarShape)
{
if (!isEnabled)
return;

if(markers.TryGetValue(avatarShape.ID, out var marker))
if (markers.TryGetValue(avatarShape.ID, out var marker))
{
marker.UpdateMarkerPosition(avatarShape.ID, transformComponent.Transform.position);
mapCullingController.SetTrackedObjectPositionDirty(marker);
Expand All @@ -77,7 +78,8 @@ private void SetPlayerMarker(in CharacterTransform transformComponent, in Avatar
}

[Query]
private void RemoveMarker(in AvatarShapeComponent avatarShape, in DeleteEntityIntention deleteEntityIntention)
[All(typeof(DeleteEntityIntention))]
private void RemoveMarker(in AvatarShapeComponent avatarShape)
{
if (markers.TryGetValue(avatarShape.ID, out var marker))
{
Expand Down Expand Up @@ -115,6 +117,7 @@ public partial class TrackPlayersPositionSystem : ControllerECSBridgeSystem
internal TrackPlayersPositionSystem(World world) : base(world) { }
}

[UpdateAfter(typeof(TrackPlayersPositionSystem))]
[UpdateInGroup(typeof(PresentationSystemGroup))]
public partial class RemovedTrackedPlayersPositionSystem : ControllerECSBridgeSystem
{
Expand Down
35 changes: 24 additions & 11 deletions Explorer/Assets/DCL/PluginSystem/Global/MinimapPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using ECS.SceneLifeCycle;
using ECS.SceneLifeCycle.Realm;
using Utility.Tasks;

namespace DCL.PluginSystem.Global
{
Expand Down Expand Up @@ -41,20 +42,32 @@ public MinimapPlugin(IMVCManager mvcManager, MapRendererContainer mapRendererCon
this.mainUIView = mainUIView;
}

protected override async UniTask<ContinueInitialization?> InitializeInternalAsync(MinimapSettings settings, CancellationToken ct)
protected override UniTask<ContinueInitialization?> InitializeInternalAsync(MinimapSettings settings, CancellationToken ct)
{
return (ref ArchSystemsWorldBuilder<Arch.Core.World> world, in GlobalPluginArguments _) =>
ContinueInitialization initialization = (ref ArchSystemsWorldBuilder<Arch.Core.World> world, in GlobalPluginArguments _) =>
{
mvcManager.RegisterController(new MinimapController(
() =>
{
MinimapView? view = mainUIView.MinimapView;
view.gameObject.SetActive(true);
return view;
},
mapRendererContainer.MapRenderer, mvcManager, placesAPIService, TrackPlayerPositionSystem.InjectToWorld(ref world),
realmData, chatMessagesBus, realmNavigator, scenesCache, mapPathEventBus));
mvcManager.RegisterController(
new MinimapController(
() =>
{
MinimapView? view = mainUIView.MinimapView;
view.gameObject.SetActive(true);
return view;
},
mapRendererContainer.MapRenderer,
mvcManager,
placesAPIService,
TrackPlayerPositionSystem.InjectToWorld(ref world),
realmData,
chatMessagesBus,
realmNavigator,
scenesCache,
mapPathEventBus
)
);
};

return initialization.AsUniTaskResult<ContinueInitialization?>();
}

protected override void InjectSystems(ref ArchSystemsWorldBuilder<Arch.Core.World> builder, in GlobalPluginArguments arguments) { }
Expand Down

0 comments on commit 5446349

Please sign in to comment.