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!
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → 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!
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.
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).
Thank you!
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();
}
}
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!
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.
Infinity Code Forum → Online Maps Help → How can I make a 2D map fullscreen?
Powered by PunBB, supported by Informer Technologies, Inc.