Search Unity

GUI Layout 'Fading' on changing QualitySettings

Discussion in 'Android' started by Exalia, Aug 19, 2013.

  1. Exalia

    Exalia

    Joined:
    Aug 14, 2013
    Posts:
    22
    Hi there, I have a menu with a button that changes Anti Aliasing Settings on and off (from x0 to x4) however when I push this button my GUILayout of Buttons seem to fade out. I have decided to remove everything from my scene apart from a camera and a GUIText (the GUI text is part of my FPS reader) and I still get this problem. :(

    I can navigate the entire menu and change resolutions without the same effect.

    One the effect occurs I haven't found a way to get rid of it, it persists even when AA is changed back.
    The code works fine on PC.

    This is my code, I'm running it on a Nexus 10.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class ResolutionMenu : MonoBehaviour
    6. {
    7.     public bool Statistics = true;
    8.     public bool DragWindow = false;
    9.     public bool FullScreen = true;
    10.     public string levelToLoadWhenClickedPlay = "";
    11.     public string[] AboutTextLines = new string[0];
    12.     private string MessageDisplayOnAbout = "Welcome to DrEvil! \n Use WASD to move your character \n Press the Space Key to plant a Bomb! \n";
    13.     private Rect WindowRect = new Rect(Screen.width / 16, Screen.height / 16, 200, 770);
    14.     private float volume = 1.0f;
    15.     private Rect OptionsRect = new Rect(Screen.width / 16, Screen.height / 16, 200, 770);
    16.     private string clicked = "";
    17.     private int nativeResolutionH;
    18.     private int nativeResolutionW;
    19.     private float buttonSize = 100;
    20.     private float boxSize = 25;
    21.     private Resolution nativeRes;
    22.     private int currentResolutionH;
    23.     private int currentResolutionW;
    24.     private float resolutionRatio = 1;
    25.     public GUIStyle myStyle;
    26.     public GUIStyle myStyle2;
    27.     public GUIStyle myStyle3;
    28.  
    29.     void Start()
    30.     {
    31.         nativeResolutionH = Screen.currentResolution.height;
    32.         nativeResolutionW = Screen.currentResolution.width;
    33.  
    34.         for (int x = 0; x < AboutTextLines.Length; x++)
    35.         {
    36.             MessageDisplayOnAbout += AboutTextLines[x] + " \n ";
    37.         }
    38.         MessageDisplayOnAbout += "Press Esc To Go Back";
    39.     }
    40.  
    41.     private void OnGUI()
    42.     {
    43.         if (clicked == "")
    44.         {
    45.             WindowRect = GUI.Window(0, WindowRect, menuFunc, "Main Menu", myStyle);
    46.         }
    47.         if (clicked == "options")
    48.         {
    49.             OptionsRect = GUI.Window(1, OptionsRect, buttonFunc, "Options", myStyle);
    50.         }
    51.         if (clicked == "native")
    52.         {
    53.             Screen.SetResolution(nativeResolutionW, nativeResolutionH, FullScreen);
    54.             clicked = "options";
    55.         }
    56.         else if (clicked == "1080")
    57.         {
    58.             Screen.SetResolution(1920, 1080, FullScreen);
    59.             clicked = "options";
    60.         }
    61.         else if (clicked == "720")
    62.         {
    63.             Screen.SetResolution(1280, 720, FullScreen);
    64.             clicked = "options";
    65.         }
    66.         else if (clicked == "0")
    67.         {
    68.             QualitySettings.antiAliasing = 0;
    69.             clicked = "options";
    70.         }
    71.         else if (clicked == "4")
    72.         {
    73.             QualitySettings.antiAliasing = 4;
    74.             clicked = "options";
    75.         }
    76.         else if (clicked == "statson")
    77.         {
    78.             Statistics = true;
    79.             clicked = "options";
    80.         }
    81.         else if (clicked == "statsoff")
    82.         {
    83.             Statistics = false;
    84.             clicked = "options";
    85.         }
    86.     }
    87.  
    88.     private void menuFunc(int id)
    89.     {
    90.         //buttons
    91.         if (GUILayout.Button("Play Game", myStyle2))
    92.         {
    93.             //play game is clicked
    94.             Application.LoadLevel(levelToLoadWhenClickedPlay);
    95.         }
    96.         if (GUILayout.Button("Demo Mode", myStyle2))
    97.         {
    98.             //Load Demo Mode
    99.         }
    100.         if (GUILayout.Button("Configuration", myStyle2))
    101.         {
    102.             clicked = "options";
    103.         }
    104.         if (GUILayout.Button("Credits", myStyle2))
    105.         {
    106.             clicked = "about";
    107.         }
    108.         if (GUILayout.Button("Quit Game", myStyle2))
    109.         {
    110.             Application.Quit();
    111.         }
    112.     }
    113.  
    114.     private void buttonFunc(int id)
    115.     {
    116.         GUILayout.Box("Graphics", myStyle3);
    117.         GUILayout.Box("Resolution", myStyle3);
    118.         if (GUILayout.Button("1080p", myStyle2))
    119.         {
    120.             clicked = "1080";
    121.         }
    122.         if (GUILayout.Button("720p", myStyle2))
    123.         {
    124.             clicked = "720";
    125.         }
    126.         if (GUILayout.Button("Native", myStyle2))
    127.         {
    128.             clicked = "native";
    129.         }
    130.         GUILayout.Box("Anti Aliasing", myStyle3);
    131.         if (GUILayout.Button("Off", myStyle2))
    132.         {
    133.             clicked = "0";
    134.         }
    135.         if (GUILayout.Button("On", myStyle2))
    136.         {
    137.             clicked = "4";
    138.         }
    139.         GUILayout.Box("Volume", myStyle3);
    140.         GUILayout.Box("Sounds", myStyle3);
    141.         volume = GUILayout.HorizontalSlider(volume, 0.0f, 1.0f);
    142.         AudioListener.volume = volume;
    143.         GUILayout.Box("Music", myStyle3);
    144.         volume = GUILayout.HorizontalSlider(volume, 0.0f, 1.0f);
    145.         GUILayout.Box("Statistics", myStyle3);
    146.         if (GUILayout.Button("On", myStyle2))
    147.         {
    148.             clicked = "statson";
    149.         }
    150.         if (GUILayout.Button("Off", myStyle2))
    151.         {
    152.             clicked = "statsoff";
    153.         }
    154.  
    155.         if (GUILayout.Button("Back", myStyle2))
    156.         {
    157.             clicked = "";
    158.         }
    159.     }
    160.  
    161.     private void Update()
    162.     {
    163.         currentResolutionH = Screen.currentResolution.height;
    164.         currentResolutionW = Screen.currentResolution.width;
    165.         resolutionRatio =  ((float)nativeResolutionH / (float)currentResolutionH);
    166.         OptionsRect = new Rect(currentResolutionW / 32, currentResolutionH / 32, 400 / resolutionRatio, 1200 / resolutionRatio);
    167.         WindowRect = new Rect(currentResolutionW / 32, currentResolutionH / 32, 400 / resolutionRatio, 470 / resolutionRatio);
    168.         buttonSize = (100 / resolutionRatio);
    169.         boxSize = (25 / resolutionRatio);
    170.         myStyle.fontSize = (int)(50 / resolutionRatio);
    171.         myStyle.contentOffset = new Vector2(0,(-100 / resolutionRatio));
    172.         myStyle2.fontSize = (int)(40 / resolutionRatio);
    173.         myStyle3.fontSize = (int)(40 / resolutionRatio);
    174.         if (clicked == "about"  Input.GetKey(KeyCode.Escape))
    175.             clicked = "";
    176.     }
    177. }
    178.  
     
    Last edited: Aug 19, 2013
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    If you're developing for iOS/Android you should especially get away from the bad performance of Unity's built-in GUI and invest in NGUI. There is even a free edition. It will solve your problems too.
     
  3. Exalia

    Exalia

    Joined:
    Aug 14, 2013
    Posts:
    22
    I'm curious about this free edition, could I get a link I did a quick search and couldn't find it

    Thanks
     
  4. Exalia

    Exalia

    Joined:
    Aug 14, 2013
    Posts:
    22
    Any chance of getting a location of this free edition?