What is a proper way to create a Menu for multiple resolutions.
Using Unity 5.6.6
Currently just have a simple main menu, well technically known as the DevMenu as I want to use it as a base for the other menus down the line. So far this menu allows the cursor to move from top to bottom and loop back from the last option to the first and vise-versa. The canvas has also been set to Scale with Screen Size and the reference resolution has been set to 640 X 480. while this works fine on the current resolution setting that I need being 400X240 for hardware-specific reasons, I want to have the option to still be able to have the option to have resolutions higher than 720p and not have anything break such as the screen positions and cursor movement. Is there a better way to do this? I understand that when porting to PC some things might need to be changed but I don't want to go through the hassle to change stuff around for every resolution possible. I'll provide screenshots below to show what I'm referring to.
Edit: also if code is needed for reference to the cursor, i'll also go ahead and provide it here if needed as i'm not sure if this is a coding issue or a UI / Canvas Issue.
Answer by SimonMK7 · Aug 12, 2020 at 02:46 AM
Here's the Menu at a resolution of 400X240
https://drive.google.com/file/d/1AFrvNH2PWf8uWeNA4cCQiTDuMCK5CHFi/view?usp=sharing
and here's the Menu set to a resolution of 320X240 just for reference. This also happens if set to 1280X720 and 1920X1080.
https://drive.google.com/file/d/1V9v2b2oazOMxNznDgxieCcDy_IPt4LM5/view?usp=sharing
Answer by okaybj · Aug 12, 2020 at 04:41 AM
make the reference resolution the highest you would want it to be then make sure depending on the desired ratio slide the match nob closer to width or height and play with the reference pixel per unit. That worked for me
@okaybj ok looks like all is in check in terms of resizing the menu to other aspect ratios, however, I'm still having problems with the cursor in terms of movement. I don't want to edit the movement variables for every resolution possible so I now know that the code needs to be improved a little. If possible, what might be the best suggestion to get this to work for multiple resolutions? I'll go ahead and provide the code below to see if I can get some feedback on this but in general, the variables for the cursor movement and looping positions are all here and I hope this better illustrates what I'm trying to do with it.
[Header("Cursor Navigation Variables")]
[Tooltip("The current position of the cursor deter$$anonymous$$ed by the amount of levels allowed to be selected.")]
public int _CurrentCurIndex;
[Tooltip("The total amount of units the cursor is allowed to travel.")]
public int _totalCursorLevels;
[Tooltip("the amount of space per unit.")]
public float _CursorYoffset = 1f;
[Header("Cursor Reset Positions")]
[Tooltip("When the cursor reaches the amount of units given in 'totalCursorLevels' or reaches 0," +
"\nThis variable will control the Cursor's xaxis position when it resets.")]
public float _CursorXPos;
[Tooltip("When the cursor reaches 0 for it's index, the cursor will loop to the last option of the menu." +
"\nThis variable will control the Cursor's Yaxis to reset the position of the cursor to the last option of the menu.")]
public float _CursorTopYPos;
[Tooltip("When the cursor reaches the amount of units given in 'totalCursorLevels', the cursor will loop back to the first option of the menu." +
"\nThis variable will control the Cursor's Yaxis to reset the position of the cursor to the first option of the menu.")]
public float _CursorBottomYPos;
private void $$anonymous$$oveUporDown (bool bVert)
{
if (!bVert)
{
if (_CurrentCurIndex < _totalCursorLevels - 1)
{
_CurrentCurIndex++;
Vector2 position = transform.position;
position.y -= _CursorYoffset;
transform.position = position;
}
else if (_CurrentCurIndex >= _totalCursorLevels -1)
{
_CurrentCurIndex = 0;
transform.position = new Vector2 (_CursorXPos, _CursorTopYPos);
}
}
else
{
if (_CurrentCurIndex > 0)
{
_CurrentCurIndex--;
Vector2 position = transform.position;
position.y += _CursorYoffset;
transform.position = position;
}
else if (_CurrentCurIndex <= 0)
{
_CurrentCurIndex = _totalCursorLevels - 1;
transform.position = new Vector2 (_CursorXPos, _CursorBottomYPos);
}
}
}
private void LevelSelect(bool bLevSel)
{
if (bLevSel && _CurrentCurIndex == 1)
{
if (Index_LS > 0)
{
Index_LS--;
LSValue -= 1;
}
else if (Index_LS <= 0)
{
Index_LS = LevelSelectTotal - 1;
LSValue = LevelSelectTotal - 1;
}
}
else if (!bLevSel && _CurrentCurIndex == 1)
{
if (Index_LS < LevelSelectTotal - 1)
{
Index_LS++;
LSValue += 1;
}
else if (Index_LS >= LevelSelectTotal - 1)
{
Index_LS = 0;
LSValue = 0;
}
}
}
private void PlayerInput()
{
//UpKey
if (Input.GetKeyDown (KeyCode.DownArrow))
{
$$anonymous$$oveUporDown (false);
}
//DownKey
if (Input.GetKeyDown (KeyCode.UpArrow))
{
$$anonymous$$oveUporDown (true);
}
}
void Update ()
{
PlayerInput ();
}
Your answer
Follow this Question
Related Questions
Start Menu to First Person Controller cursor issues 0 Answers
Cursor dissapearing in my menu 0 Answers
Problem with animated image on canvas 0 Answers
How can i show my cursor in my inventory menu? 0 Answers
Options menu won't work 0 Answers