Advertisement
Guest User

Menu

a guest
Jul 6th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.34 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class MENU : MonoBehaviour {
  4.    private AudioListener[] AudioListners;
  5.    public Texture QualidadeGrafica,Resolucoes,ModoJanelaOuTelaCheia,Volume,TexturaCreditos,TexturaFundosMenu,TexturaGraficos;
  6.    private bool EstaNoMenuPrincipal,EstaNosGraficos,EstaNosCreditos;
  7.    public GUIStyle EstiloDosBotoesPrincipais,EstiloDosBotoesGraficos;
  8.    private string ResolucaoLargura = "1024",ResolucaoAltura = "768";
  9.    private float VOLUME;
  10.    private int qualidadeGrafica;
  11.    public Font Fonte;
  12.    public int tamanhoDaLetra = 4;
  13.    void Awake (){
  14.       DontDestroyOnLoad (transform.gameObject);
  15.    }
  16.    void Start (){
  17.       EstaNoMenuPrincipal = true;
  18.       Cursor.visible = true;
  19.       Time.timeScale = 1;
  20.       // PREFERENCIAS SALVAS
  21.       if (PlayerPrefs.HasKey ("VOLUME")) {
  22.          VOLUME = PlayerPrefs.GetFloat ("VOLUME");
  23.       } else {
  24.          PlayerPrefs.SetFloat ("VOLUME", VOLUME);
  25.       }
  26.       //
  27.       if (PlayerPrefs.HasKey ("qualidadeGrafica")) {
  28.          qualidadeGrafica = PlayerPrefs.GetInt ("qualidadeGrafica");
  29.          QualitySettings.SetQualityLevel(qualidadeGrafica);
  30.       } else {
  31.          PlayerPrefs.SetInt ("qualidadeGrafica", qualidadeGrafica);
  32.       }
  33.    }
  34.    void Update (){
  35.       //Preencher Arrays
  36.       if (Application.loadedLevelName != "MENU") {
  37.          AudioListners = GameObject.FindObjectsOfType(typeof(AudioListener)) as AudioListener[];
  38.          AudioListener.volume = VOLUME;
  39.          Destroy (gameObject);
  40.       }
  41.    }
  42.    void OnGUI (){
  43.       GUI.skin.font = Fonte;
  44.       EstiloDosBotoesPrincipais.fontSize = Screen.height / 100 * tamanhoDaLetra;
  45.       EstiloDosBotoesGraficos.fontSize = Screen.height / 100 * tamanhoDaLetra;
  46.       //=============================== SE ESTA NA PARTE PRINCIPAL DO MENU ===================//
  47.       if (EstaNoMenuPrincipal == true) {
  48.          GUI.skin.button = EstiloDosBotoesPrincipais;
  49.          GUI.DrawTexture(new Rect(Screen.width/2-Screen.width/2,Screen.height/2-Screen.height/2,Screen.width,Screen.height),TexturaFundosMenu);
  50.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/5.5f,Screen.width/8,Screen.height/14),"Jogar")){
  51.             Application.LoadLevel ("AI");// NOME DA CENA DO SEU JOGO
  52.          }
  53.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/16,Screen.width/8,Screen.height/14),"Opçoes")){
  54.             EstaNoMenuPrincipal = false;
  55.             EstaNosGraficos = true;
  56.          }
  57.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/16,Screen.height/2+Screen.height/16,Screen.width/8,Screen.height/14),"Creditos")){
  58.             EstaNoMenuPrincipal = false;
  59.             EstaNosCreditos = true;
  60.          }
  61.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/16,Screen.height/2+Screen.height/5.5f,Screen.width/8,Screen.height/14),"Sair")){
  62.             Application.Quit ();
  63.          }
  64.       }
  65.       //=============================== SE ESTA NA PARTE DOS GRAFICOS DO MENU ===================//
  66.       if (EstaNosGraficos == true) {
  67.          GUI.skin.button = EstiloDosBotoesGraficos;
  68.          GUI.DrawTexture(new Rect(Screen.width/2-Screen.width/2,Screen.height/2-Screen.height/2,Screen.width,Screen.height),TexturaGraficos);
  69.          GUI.DrawTexture(new Rect(Screen.width/2-Screen.width/3,Screen.height/2-Screen.height/2.5f,Screen.width/8,Screen.height/14),QualidadeGrafica);
  70.          GUI.DrawTexture(new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/2.5f,Screen.width/8,Screen.height/14),Resolucoes);
  71.          GUI.DrawTexture(new Rect(Screen.width/2+Screen.width/5,Screen.height/2-Screen.height/2.5f,Screen.width/8,Screen.height/14),ModoJanelaOuTelaCheia);
  72.          GUI.DrawTexture(new Rect(Screen.width/2+Screen.width/5,Screen.height/2-Screen.height/10,Screen.width/8,Screen.height/14),Volume);
  73.          //
  74.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/2.2f,Screen.height/2+Screen.height/2.5f,Screen.width/8,Screen.height/14),"VOLTAR")){
  75.             EstaNoMenuPrincipal = true;
  76.             EstaNosGraficos = false;
  77.          }
  78.          //QUALIDADES
  79.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2-Screen.height/4,Screen.width/8,Screen.height/14),"PESSIMO")){
  80.             QualitySettings.SetQualityLevel(0);
  81.             qualidadeGrafica = 0;
  82.          }
  83.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2-Screen.height/6,Screen.width/8,Screen.height/14),"RUIM")){
  84.             QualitySettings.SetQualityLevel(1);
  85.             qualidadeGrafica = 1;
  86.          }
  87.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2-Screen.height/12,Screen.width/8,Screen.height/14),"SIMPLES")){
  88.             QualitySettings.SetQualityLevel(2);
  89.             qualidadeGrafica = 2;
  90.          }
  91.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2,Screen.width/8,Screen.height/14),"BOM")){
  92.             QualitySettings.SetQualityLevel(3);
  93.             qualidadeGrafica = 3;
  94.          }
  95.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2+Screen.height/12,Screen.width/8,Screen.height/14),"OTIMO")){
  96.             QualitySettings.SetQualityLevel(4);
  97.             qualidadeGrafica = 4;
  98.          }
  99.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/3,Screen.height/2+Screen.height/6,Screen.width/8,Screen.height/14),"FANTASTICO")){
  100.             QualitySettings.SetQualityLevel(5);
  101.             qualidadeGrafica = 5;
  102.          }
  103.          //RESOLUCOES
  104.          ResolucaoLargura = GUI.TextField(new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/4,Screen.width/8,Screen.height/14),ResolucaoLargura);
  105.          ResolucaoAltura = GUI.TextField(new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/6,Screen.width/8,Screen.height/14),ResolucaoAltura);
  106.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/16,Screen.height/2-Screen.height/12,Screen.width/8,Screen.height/14),"Aplicar")){
  107.             Screen.SetResolution(int.Parse (ResolucaoLargura),int.Parse (ResolucaoAltura),true);
  108.          }
  109.          //TELACHEIA
  110.          if(GUI.Button(new Rect(Screen.width/2+Screen.width/5,Screen.height/2-Screen.height/4,Screen.width/8,Screen.height/14),"Trocar")){
  111.             Screen.fullScreen = !Screen.fullScreen;
  112.          }
  113.          //VOLUME
  114.          VOLUME = GUI.HorizontalSlider(new Rect(Screen.width/2+Screen.width/5,Screen.height/2,Screen.width/8,Screen.height/14),VOLUME,0,1);
  115.          //SALVAR PREFERENCIAS
  116.          if(GUI.Button(new Rect(Screen.width/2+Screen.width/5,Screen.height/2+Screen.height/3,Screen.width/8,Screen.height/14),"SALVAR PREF.")){
  117.             PlayerPrefs.SetFloat("VOLUME",VOLUME);
  118.             PlayerPrefs.SetInt("qualidadeGrafica",qualidadeGrafica);
  119.          }
  120.       }  
  121.       //=============================== SE ESTA NA PARTE DOS CREDITOS DO MENU ===================//
  122.       if (EstaNosCreditos == true) {
  123.          GUI.skin.button = EstiloDosBotoesGraficos;
  124.          GUI.DrawTexture(new Rect(Screen.width/2-Screen.width/2,Screen.height/2-Screen.height/2,Screen.width,Screen.height),TexturaCreditos);
  125.          if(GUI.Button (new Rect(Screen.width/2-Screen.width/2.2f,Screen.height/2+Screen.height/2.5f,Screen.width/8,Screen.height/14),"VOLTAR")){
  126.             EstaNoMenuPrincipal = true;
  127.             EstaNosCreditos = false;
  128.          }
  129.       }
  130.    }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement