Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

New GUI: How to do Button/Text optimized for each Resolution?

Discussion in 'Immediate Mode GUI (IMGUI)' started by benzuk, Aug 21, 2014.

  1. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    Hello, I have a question how to do Button or Text optimized for each Resolution in New GUI?
    Thanks!
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  3. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    Yes. I know about this, But I don't know how to do with Reference Resolution component to every Resolution.
    Anyway thanks.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I don't understand what you are trying to achieve. Do you want a pixel perfect solution for certain resolutions? Do you want that the elements are correctly placed even if you have different resolutions?
     
  5. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    I want to do Button or Text to the same size and position for each Resolution, But I do not know how to do it with "Reference Resolution", But I tried and it didn't work.

    Sorry for my bad English.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What do you mean with the "same size"? The same physical size or the same size relative to the screen size (e.g. 10% of the screen size)?
     
  7. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    Yes, Look:




    How to do the GUI adjusted for each Resolution?
     
  8. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
  9. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    No, it is only for the old GUI.

    Check the videos to understand how you can achieve it. In your case, you may e.g. use a reference resolution to have a consistent height. Then you just need to anchor the UI elements correctly to the left and right side of the screen, as shown here:
     
  11. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    Why not? Matrix4x4 is same object in old and new Unity version.

    Using Matrix4x4 you don't need resize Rect object, or calculate its new position.

    Matrix4x4 does it for you, using a reference resolution also to calculate Matrix4x4 scale.
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Ok, it may work with the new GUI as well, but there is no reason to use it, because there is already a Reference Resolution script, specifically made for the new GUI. The problem is not the scaling or resolution, but the anchoring.
     
  13. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    Okay, I'll use Reference Resolution but What I need to set at Resolution X:Y in component?

    What I did:
    private void Awake()
    {
    GameObject.Find("Canvas").GetComponent<ReferenceResolution>().resolution = new Vector2(Screen.width, Screen.height);
    }

    And It doesn't work.

    Sorry for my bad English again, I hope you understand.
     
  14. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Just use the default values for now.
     
  15. benzuk

    benzuk

    Joined:
    Mar 11, 2014
    Posts:
    117
    Thank you!