//---------------------------------------------------------------------------------- // Draw and handle element according to it type public void OnGUI() { if (skin) { GUI.skin = skin; } switch (type) { case ElementTypes.button_CloseGoTo: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.close_GoToWindow, parameterFloat); } } break; case ElementTypes.button_GoTo: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.GoToWindow, parameterFloat); } } break; case ElementTypes.button_Back: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.GoToPreviousWindow); } } break; case ElementTypes.button_Next: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.GoToNextWindow); } } break; case ElementTypes.button_CloseBack: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.close_GoToPreviousWindow); } } break; case ElementTypes.button_CloseNext: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.close_GoToNextWindow); } } break; case ElementTypes.button_ExitGame: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { Application.Quit(); } } break; case ElementTypes.button_LoadLevel: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { if (parentElement.gameObject.GetComponent <AudioSource>()) { beenClicked = true; parentElement.gameObject.GetComponent <AudioSource>().Play(); } else { Application.LoadLevel((int)parameterFloat); } } } if (parentElement) { if (parentElement.gameObject.GetComponent <AudioSource>() && beenClicked) { if (!parentElement.gameObject.GetComponent <AudioSource>().isPlaying) { Application.LoadLevel((int)parameterFloat); } } } break; case ElementTypes.button_SetQuality: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { switch (parameter) { case "Fastest": QualitySettings.SetQualityLevel(0); break; case "Fast": QualitySettings.SetQualityLevel(1); break; case "Simple": QualitySettings.SetQualityLevel(2); break; case "Good": QualitySettings.SetQualityLevel(3); break; case "Beautiful": QualitySettings.SetQualityLevel(4); break; case "Fantastic": QualitySettings.SetQualityLevel(5); break; } if (parameterFloat != 0) { parentElement.SetAction(Action.close_GoToPreviousWindow); } } } break; case ElementTypes.button_IncQuality: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { QualitySettings.IncreaseLevel(); } } break; case ElementTypes.button_DecQuality: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { QualitySettings.DecreaseLevel(); } } break; case ElementTypes.scroll_Resolutions: if (!locked) { Resolution[] resolutions = Screen.resolutions; scrollPosition = GUI.BeginScrollView(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), scrollPosition, new Rect(0, 0, size.x * 0.8f, resolutions.Length * parameterFloat)); int i = 0; foreach (Resolution res in resolutions) { if (GUI.RepeatButton(new Rect(0, i * parameterFloat, size.x * 0.9f, parameterFloat * 1.1f), res.width + "x" + res.height)) { Screen.SetResolution(res.width, res.height, Screen.fullScreen); Application.LoadLevel(Application.loadedLevel); } i++; } GUI.EndScrollView(); } break; case ElementTypes.toggle_Fullscreen: bool isFullScreen = Screen.fullScreen; Fullscreen_toggleBool = GUI.Toggle(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), isFullScreen, new GUIContent(caption, icon)); if (!locked) { if (Fullscreen_toggleBool != isFullScreen) { Screen.fullScreen = Fullscreen_toggleBool; } } break; case ElementTypes.slider_MouseSens: GUI.Label(new Rect(currentPosition.x, currentPosition.y, caption.Length * parameterFloat, size.y), new GUIContent(caption, icon)); if (!locked) { MouseSens = GUI.HorizontalSlider(new Rect(currentPosition.x + caption.Length * parameterFloat, currentPosition.y, size.x - caption.Length * parameterFloat, size.y), MouseSens, 1, 100); } break; case ElementTypes.button_Resume: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { Time.timeScale = 1; parentElement.SetAction(Action.close); } } break; case ElementTypes.button_Restart: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { Time.timeScale = 1; Application.LoadLevel(Application.loadedLevel); } } break; case ElementTypes.button_OpenURL: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { Application.OpenURL(parameter); } } break; case ElementTypes.label: GUI.Label(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption + parameter, icon)); break; case ElementTypes.stars: for (int i = 0; i < parameterFloat; i++) { GUI.DrawTexture(new Rect((currentPosition.x - (parameterFloat * size.x * 1.1f - size.x) / 2) + i * size.x * 1.1f, currentPosition.y, size.x, size.y), icon, ScaleMode.StretchToFill, true); } break; case ElementTypes.button_CloseEverything: if (GUI.Button(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), new GUIContent(caption, icon))) { if (!locked) { parentElement.SetAction(Action.close_MenuManager); } } break; case ElementTypes.textArea: scrollPosition = GUI.BeginScrollView(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), scrollPosition, new Rect(0, 0, size.x - 18, size.y * parameterFloat)); string textAreaString = GUI.TextArea(new Rect(0, 0, size.x - 15, size.y * (parameterFloat + 1)), parameter); //var textAreaString = GUI.TextArea (new Rect (currentPosition.x, currentPosition.y, size.x, size.y), parameter); GUI.EndScrollView(); if (!locked) { parameter = textAreaString; } else { GUI.SetNextControlName("none"); GUI.FocusControl("none"); } break; case ElementTypes.image: if (icon) { GUI.DrawTexture(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), icon, ScaleMode.StretchToFill, true); } break; case ElementTypes.toggle_Sound: AudioListener audioListener = GameObject.FindObjectOfType <AudioListener>(); bool isSoundEnabled = GUI.Toggle(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), audioListener.enabled, new GUIContent(caption, icon)); if (!locked) { audioListener.enabled = isSoundEnabled; } break; case ElementTypes.slider_masterVolume: GUI.Label(new Rect(currentPosition.x, currentPosition.y, caption.Length * parameterFloat, size.y), new GUIContent(caption, icon)); if (!locked) { AudioListener.volume = GUI.HorizontalSlider(new Rect(currentPosition.x + caption.Length * parameterFloat, currentPosition.y, size.x - caption.Length * parameterFloat, size.y), AudioListener.volume, 0, 1); } break; } if (locked) { if (lockImage) { GUI.DrawTexture(new Rect(currentPosition.x, currentPosition.y, size.x, size.y), lockImage, ScaleMode.ScaleToFit, true); } } }