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