| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using Cysharp.Threading.Tasks.Linq; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Providers; |
| | 5 | | using DCLServices.MapRendererV2.CoordsUtils; |
| | 6 | | using DCLServices.MapRendererV2.Culling; |
| | 7 | | using DCLServices.MapRendererV2.MapLayers; |
| | 8 | | using DCLServices.MapRendererV2.MapLayers.UsersMarkers.HotArea; |
| | 9 | | using MainScripts.DCL.Helpers.Utils; |
| | 10 | | using System.Collections.Generic; |
| | 11 | | using System.Threading; |
| | 12 | | using System.Threading.Tasks; |
| | 13 | | using UnityEngine; |
| | 14 | | using UnityEngine.Pool; |
| | 15 | |
|
| | 16 | | namespace DCLServices.MapRendererV2.ComponentsFactory |
| | 17 | | { |
| | 18 | | internal struct HotUsersMarkersInstaller |
| | 19 | | { |
| | 20 | | private const string HOT_USER_MARKER_ADDRESS = "HotUserMarker"; |
| | 21 | | private const int HOT_USER_MARKERS_PREWARM_COUNT = 30; |
| | 22 | |
|
| | 23 | | private Service<IAddressableResourceProvider> addressablesProvider; |
| | 24 | |
|
| | 25 | | public async UniTask Install( |
| | 26 | | Dictionary<MapLayer, IMapLayerController> writer, |
| | 27 | | MapRendererConfiguration configuration, |
| | 28 | | ICoordsUtils coordsUtils, |
| | 29 | | IMapCullingController cullingController, |
| | 30 | | CancellationToken cancellationToken) |
| | 31 | | { |
| 98 | 32 | | var prefab = await GetPrefab(cancellationToken); |
| | 33 | |
|
| | 34 | | void OnCreate(HotUserMarkerObject obj) |
| | 35 | | { |
| 16980 | 36 | | for (var i = 0; i < obj.spriteRenderers.Length; i++) |
| 5660 | 37 | | obj.spriteRenderers[i].sortingOrder = MapRendererDrawOrder.HOT_USER_MARKERS; |
| | 38 | |
|
| 2830 | 39 | | coordsUtils.SetObjectScale(obj); |
| 2830 | 40 | | } |
| | 41 | |
|
| 96 | 42 | | var objectsPool = new UnityObjectPool<HotUserMarkerObject>(prefab, configuration.HotUserMarkersRoot, actionO |
| | 43 | |
|
| | 44 | | IHotUserMarker CreateWrap() => |
| 2880 | 45 | | new HotUserMarker(objectsPool, cullingController, coordsUtils, CommonScriptableObjects.worldOffset); |
| | 46 | |
|
| 2976 | 47 | | var wrapsPool = new ObjectPool<IHotUserMarker>(CreateWrap, actionOnRelease: m => m.Dispose(), defaultCapacit |
| | 48 | |
|
| 96 | 49 | | var controller = new UsersMarkersHotAreaController(DataStore.i.player.otherPlayers, objectsPool, wrapsPool, |
| | 50 | |
|
| 288 | 51 | | await controller.Initialize(cancellationToken); |
| 89 | 52 | | writer.Add(MapLayer.HotUsersMarkers, controller); |
| 89 | 53 | | } |
| | 54 | |
|
| | 55 | | internal async Task<HotUserMarkerObject> GetPrefab(CancellationToken cancellationToken) => |
| 98 | 56 | | await addressablesProvider.Ref.GetAddressable<HotUserMarkerObject>(HOT_USER_MARKER_ADDRESS, cancellationToke |
| | 57 | | } |
| | 58 | | } |