Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question How do you resize texture displayed on inspector (GUILayout)?

Discussion in 'Immediate Mode GUI (IMGUI)' started by hyperkvlt, Jul 30, 2023.

  1. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38
    Hi. I tried to figure out how to resize texture when it displayed on inspector. The method I found could only set the max size of the texture displayed but I cannot figure out how to set the minimum size for texture displayed on inspector.

    For bigger texture they will be displayed smaller to fit the layout group. While for smaller texture they remained the same size. Is there a way to display the smaller texture bigger?


    Here's my script:

    Code (CSharp):
    1. GUILayout.BeginVertical(GUILayout.Width(50), GUILayout.Height(50));
    2. GUILayout.Box(texture, GUILayout.Width(50), GUILayout.Height(50), GUILayout.MinWidth(50), GUILayout.MinHeight(50));
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    819
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    819
    Another option you could try would be to create a new GUIStyle from the Box Style and enabled StretchWidth and StretchHeight. That might work.