using UnityEngine; public class EarthMapScrollRect : PinchableScrollRect { RectTransform canvas; RectTransform map; protected override void Start() { _minZoom = .25f; _maxZoom = 50f; canvas = GetComponentInParent().GetComponent(); map = transform.Find("ScrollableContent/WorldMap").GetComponent(); Debug.Log($"canvas={canvas} map={map} "); _zoomMode = ZoomMode.RectSize; base.Start(); _initialWidth = 2000; _initialHeight = 1000; UpdateMargins(); SetZoom(_currentZoom); verticalNormalizedPosition = 0.5f; horizontalNormalizedPosition = 0.5f; } protected override void OnRectTransformDimensionsChange() { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { base.OnRectTransformDimensionsChange(); return; } #endif UpdateMargins(); base.OnRectTransformDimensionsChange(); if (canvas != null && map != null) SetZoom(_currentZoom); } void UpdateMargins() { if (canvas == null || map == null) return; float canvasls = canvas.localScale.x; float contents = content.lossyScale.x; _horizMargin = (transform as RectTransform).rect.width * 0.5f/* / canvas.localScale.x*/; _vertMargin = (transform as RectTransform).rect.height * 0.5f/* * canvas.localScale.y*/; map.offsetMin = new Vector2(_horizMargin, _vertMargin); map.offsetMax = new Vector2(-_horizMargin, -_vertMargin); } public void DebugReport() { Debug.Log("EarthMapScrollRect.Debug:"); Debug.Log($"_initialWidth: {_initialWidth}"); Debug.Log($"_initialHeight: {_initialHeight}"); Debug.Log($"_currentZoom: {_currentZoom}"); Debug.Log($"_targetZoom: {_targetZoom}"); Debug.Log($"_horizMargin: {_horizMargin}"); Debug.Log($"_vertMargin: {_vertMargin}"); Debug.Log($"canvas.localScale: {canvas.localScale}"); Debug.Log($"scrollrect.lossyScale: { (transform as RectTransform).lossyScale}"); Debug.Log($"scrollrect.rect: {(transform as RectTransform).rect}"); Debug.Log($"content.lossyScale: {content.lossyScale}"); Debug.Log($"content.localScale: {content.localScale}"); Debug.Log($"content.pivot: {content.pivot}"); Debug.Log($"content.rect: {content.rect}"); Debug.Log($"content.sizeDelta: {content.sizeDelta}"); Debug.Log($"map.rect: {map.rect}"); Debug.Log($"map.offsetMin: {map.offsetMin}"); Debug.Log($"map.offsetMax: {map.offsetMax}"); } }