Exemplo n.º 1
0
        protected override Vector2 CalculatePosition(QT_MapMarker marker)
        {
            Vector2 mapSize    = rectTransform.rect.size;
            Vector2 worldToMap = new Vector2(mapSize.x / WorldSize.x, mapSize.y / WorldSize.y);
            Vector2 difference = marker.Object.Position(Type) - ReferenceObject.Position(Type);

            Zoom = Mathf.Clamp(Zoom, MinZoom, MaxZoom);
            Vector2 position = new Vector2(difference.x * worldToMap.x * Zoom, difference.y * worldToMap.y * Zoom);

            if (MapCollider == QT_MapColliderType.Rectangle)
            {
                position.x = Mathf.Clamp(position.x, -mapSize.x / 2, mapSize.x / 2);
                position.y = Mathf.Clamp(position.y, -mapSize.y / 2, mapSize.y / 2);
            }
            else if (MapCollider == QT_MapColliderType.Circle)
            {
                float magnitude = Mathf.Clamp(position.magnitude, 1, Mathf.Min(mapSize.x, mapSize.y) / 2);
                position.Normalize();
                position *= magnitude;
            }

            return(position);
        }