Topic: How can I make a 2D map fullscreen?

How can I make a 2D map to always take the full screen of the mobile device, regardless the screen orientation?

Thank you!

Re: How can I make a 2D map fullscreen?

Hello.

Which control do you use?
I looked at the history of your messages, and before that you used tileset.
For tileset, I have already given you a solution.
If you ask again, then you need this for another control.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

3 (edited by Rumata 2017-09-30 18:06:49)

Re: How can I make a 2D map fullscreen?

Hello, Alex Vertax,
Thank you very much for your help with the previous solution!

Yes, previously I was talking about a 3D map, now it is a 2D map with a GUITexture controller.

I was going to turn a 3D map into 2D map by disabling the "Allow Camera Control" option in the "Online Maps Tile Control" component. However, in this case, the previous solution You have sent me doesn't work since it can't control the camera distance in this case.

Also, I would appreciate your recommendation on which controller to use for the 2D map among the following (or is there any description of pros/cons for these options).

https://thumb.ibb.co/kneK3w/Screen_Shot_2017_09_30_at_8_49_31_PM.png

Thank you!

Re: How can I make a 2D map fullscreen?

Better to use UIImage or UIRawImage.
GUITexture is the worst choice, because it uses the old UI system.
In Online Maps v3 GUITexture control will be removed.

Example of how to make the adjustment of the map size to the screen size for Raw Image:

using UnityEngine;
using UnityEngine.UI;

public class AdjustMapToScreen3 : MonoBehaviour
{
    private int screenWidth;
    private int screenHeight;
    private Texture2D texture;

    private void ResizeMap()
    {
        screenWidth = Screen.width;
        screenHeight = Screen.height;

        int mapWidth = screenWidth / 256 * 256;
        int mapHeight = screenHeight / 256 * 256;
        if (screenWidth % 256 != 0) mapWidth += 256;
        if (screenHeight % 256 != 0) mapHeight += 256;

        if (texture != null)
        {
            if (mapWidth == texture.width && mapHeight == texture.height) return;
        }

        texture = new Texture2D(mapWidth, mapHeight, TextureFormat.RGB24, false);
        OnlineMaps.instance.SetTexture(texture);
        OnlineMaps.instance.RedrawImmediately();

        RawImage rawImage = GetComponent<RawImage>();
        rawImage.texture = texture;
        RectTransform rt = transform as RectTransform;
        rt.sizeDelta = new Vector2(mapWidth, mapHeight);
    }

    private void Start()
    {
        ResizeMap();
    }

    private void Update()
    {
        if (screenWidth != Screen.width || screenHeight != Screen.height) ResizeMap();
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

5 (edited by Rumata 2017-10-02 21:07:02)

Re: How can I make a 2D map fullscreen?

Thank you, Alex Vertax!

The script works great! Though I noticed that the card goes beyond the canvas a bit (a UIRawImage 2D map can only be created as a canvas child), should it be so?

I also noticed that I can't use a UIRawImage 2D map if the canvas-parent is set to "Screen Space-Camera". In this case, the card is not aligned to the canvas. Will the "Screen Space - Camera" canvas be supported for a 2D map in the future?

Thank you!

Re: How can I make a 2D map fullscreen?

This is because the map must have a size of 256 * N.
You can set any RectTransform.sizeDelta to have a size of the map equal to the size of the canvas, but if it is different you will lose the aspect ratio.

I just checked the work of the map and script with "Screen Space-Camera", and it works well.
Perhaps the problem is in some other setting.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.