| | 1 | | using DCLServices.MapRendererV2.CommonBehavior; |
| | 2 | | using DCLServices.MapRendererV2.Culling; |
| | 3 | | using MainScripts.DCL.Helpers.Utils; |
| | 4 | | using System; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCLServices.MapRendererV2.MapLayers.Favorites |
| | 8 | | { |
| | 9 | | internal class FavoritesMarker : IFavoritesMarker |
| | 10 | | { |
| | 11 | | internal const int MAX_TITLE_LENGTH = 29; |
| | 12 | | private float currentBaseScale; |
| | 13 | | private float currentNewScale; |
| | 14 | |
|
| 0 | 15 | | public Vector3 CurrentPosition => poolableBehavior.currentPosition; |
| | 16 | |
|
| 0 | 17 | | public bool IsVisible => poolableBehavior.isVisible; |
| | 18 | |
|
| 0 | 19 | | public Vector2 Pivot => poolableBehavior.objectsPool.Prefab.pivot; |
| | 20 | |
|
| 0 | 21 | | internal string title { get; private set; } |
| | 22 | |
|
| | 23 | | private MapMarkerPoolableBehavior<FavoriteMarkerObject> poolableBehavior; |
| | 24 | |
|
| | 25 | | private readonly IMapCullingController cullingController; |
| | 26 | |
|
| 0 | 27 | | public FavoritesMarker(IUnityObjectPool<FavoriteMarkerObject> objectsPool, IMapCullingController cullingControll |
| | 28 | | { |
| 0 | 29 | | poolableBehavior = new MapMarkerPoolableBehavior<FavoriteMarkerObject>(objectsPool); |
| 0 | 30 | | this.cullingController = cullingController; |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public void SetData(string title, Vector3 position) |
| | 34 | | { |
| 0 | 35 | | poolableBehavior.SetCurrentPosition(position); |
| 0 | 36 | | this.title = title.Length > MAX_TITLE_LENGTH ? title.Substring(0, MAX_TITLE_LENGTH) : title; |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | public void OnBecameVisible() |
| | 40 | | { |
| 0 | 41 | | poolableBehavior.OnBecameVisible().title.text = title; |
| | 42 | |
|
| 0 | 43 | | if(currentBaseScale != 0) |
| 0 | 44 | | poolableBehavior.instance.SetScale(currentBaseScale, currentNewScale); |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | public void OnBecameInvisible() |
| | 48 | | { |
| 0 | 49 | | poolableBehavior.OnBecameInvisible(); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public void SetZoom(float baseScale, float baseZoom, float zoom) |
| | 53 | | { |
| 0 | 54 | | currentBaseScale = baseScale; |
| 0 | 55 | | currentNewScale = Math.Max(zoom / baseZoom * baseScale, baseScale); |
| | 56 | |
|
| 0 | 57 | | if (poolableBehavior.instance != null) |
| 0 | 58 | | poolableBehavior.instance.SetScale(currentBaseScale, currentNewScale); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | public void ResetScale(float scale) |
| | 62 | | { |
| 0 | 63 | | currentNewScale = scale; |
| | 64 | |
|
| 0 | 65 | | if (poolableBehavior.instance != null) |
| 0 | 66 | | poolableBehavior.instance.SetScale(scale, scale); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public void Dispose() |
| | 70 | | { |
| 0 | 71 | | OnBecameInvisible(); |
| 0 | 72 | | cullingController.StopTracking(this); |
| 0 | 73 | | } |
| | 74 | | } |
| | 75 | | } |