Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 8.06 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #pragma strict
  2. //var dialog : GameObject;
  3. var pauseMenuActive : boolean = false;
  4. var main : MainClass;
  5. var menuState : String = "Main";
  6. var centerScreenWidth : float;
  7. var centerScreenHeight : float;
  8. var pauseTexture : Texture;
  9. var headingSkin : GUISkin;
  10. var descriptionText : GUISkin;
  11. var textSkin : GUISkin;
  12. var skillButtonText : GUISkin;
  13. var tooltipText : GUISkin;
  14. private var skillDescription : GUIContent;
  15. var placementRect : Rect;
  16. var playerStats : PlayerStats;
  17. private var player : Transform;
  18. var pauseMenuBG : Texture ;
  19. var leftButton : Texture;
  20. var rightButton : Texture;
  21. var menuBox : Texture;
  22. var inventoryScrollPosition : Vector2 = new Vector2(100,100);
  23. var skillScrollPosition : Vector2 = Vector2.zero;
  24. var longString = "This is a long-ish string";
  25.  
  26. //////////////////////////////////////////////
  27. // Skills
  28. var skillA : GUIContent;
  29. var skillB : GUIContent;
  30. var skillC : GUIContent;
  31. var skillD : GUIContent;
  32. var skillE : GUIContent;
  33. var skillF : GUIContent;
  34. var skillG : GUIContent;
  35. var skillH : GUIContent;
  36. var skillI : GUIContent;
  37. var skillJ : GUIContent;
  38. var skillK : GUIContent;
  39. var skillL : GUIContent;
  40. var skillM : GUIContent;
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. function Awake(){
  49.         var go : GameObject = GameObject.FindGameObjectWithTag("Player");      
  50.         player = go.transform;
  51.         playerStats = player.GetComponent(PlayerStats);
  52.  
  53.         centerScreenWidth = Screen.width / 2;
  54.         centerScreenHeight = Screen.height / 2;
  55.         placementRect = new Rect(10,10,100,100);
  56.  
  57. }
  58.  
  59. function Start(){
  60.         DisablePauseMenu();
  61. }
  62.  
  63. function Update(){
  64.  
  65.         if(Input.GetKeyDown(KeyCode.K)){
  66.                 TogglePauseMenu();
  67.         }
  68.        
  69. }
  70.  
  71. function TogglePauseMenu(){
  72.         switch(pauseMenuActive){
  73.                 case true:
  74.                         DisablePauseMenu();
  75.                 break;
  76.                 case false:
  77.                         menuState = "Status";
  78.                         EnablePauseMenu();
  79.                 break;
  80.         }
  81. }
  82.  
  83. function EnablePauseMenu(){
  84.  
  85.         main.PauseGame();
  86.         Screen.lockCursor = false;
  87.         pauseMenuActive = true;
  88.        
  89. }
  90.  
  91. function DisablePauseMenu(){
  92.  
  93.         main.UnpauseGame();
  94.         Screen.lockCursor = true;
  95.         pauseMenuActive = false;
  96.                
  97. }
  98.  
  99. function OnGUI(){
  100.         if(pauseMenuActive){
  101.        
  102.         //Check for pause menu background texture
  103.         if(!pauseTexture){
  104.         Debug.LogError("You need to assign a Pause Menu background texture!");
  105.         return;
  106.     }
  107.    
  108.         //////////////////////////////////////////////////
  109.                 // Main Container Group
  110.                 GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));
  111.                        
  112.                         //Draw background Texture
  113.                         GUI.DrawTexture(Rect(0,0,800,600), pauseTexture, ScaleMode.StretchToFill, true, 10.0f);
  114.                         GUI.DrawTexture(Rect(64,58,671,485), pauseMenuBG, ScaleMode.StretchToFill, true, 10.0f);
  115.                         GUI.color = new Color(1,1,1,1);
  116.                         GUI.backgroundColor = Color.clear;
  117.                         GUI.skin = headingSkin;
  118.                         //Label the menu
  119.                         GUI.Label(new Rect(190,75,400,72),menuState);
  120.                        
  121.                         /////////////////////////////////////////////                          
  122.                         // Navigation buttons
  123.                         GUI.backgroundColor = Color.clear;
  124.                         GUI.skin = null;
  125.                         if(GUI.Button(Rect(650,80,50,50),rightButton)){
  126.                                 switch(menuState){
  127.                                 case "Status":
  128.                                         menuState = "Inventory";
  129.                                 break;
  130.                                 case "Inventory":
  131.                                         menuState = "Skills";
  132.                                 break;
  133.                                 case "Skills":
  134.                                         menuState = "FadeSkills";
  135.                                 break;
  136.                                 case "FadeSkills":
  137.                                         menuState = "FadeSkills";
  138.                                 break;
  139.                                 }
  140.                         }
  141.                         if(GUI.Button(Rect(100,80,50,50),leftButton)){
  142.                                 switch(menuState){
  143.                                 case "Status":
  144.                                 break;
  145.                                 case "Inventory":
  146.                                         menuState = "Status";
  147.                                 break;
  148.                                 case "Skills":
  149.                                         menuState = "Inventory";
  150.                                 break;
  151.                                 case "FadeSkills":
  152.                                         menuState = "Skills";
  153.                                 break;
  154.                                 }
  155.                         }
  156.                        
  157.                 ///////////////////////////////////////////////////    
  158.                 // Sub Menu Groups
  159.                 switch(menuState){
  160.                         case "Status":
  161.                                 GUI.BeginGroup(new Rect(5,75,795,525));
  162.                                         GUI.DrawTexture(Rect(75,85,300,355),menuBox,ScaleMode.StretchToFill,true,10.0f);
  163.                                         GUI.DrawTexture(Rect(415,85,300,355),menuBox,ScaleMode.StretchToFill,true,10.0f);
  164.  
  165.                                         GUI.skin = textSkin;
  166.                                         // Vital Stats
  167.                                         GUI.Label(new Rect(89,89,200,140),"Level: "+playerStats.GetCurrentLevel() +
  168.                                                 "\nHP: "+playerStats.GetCurrentHealth() +"/" +playerStats.GetMaxHealth() +
  169.                                                 "\nEP: "+playerStats.GetCurrentEnergy() +"/" +playerStats.GetMaxEnergy() +
  170.                                                 "\nXP: "+playerStats.GetCurrentXP() +"/" +playerStats.GetXPToLevel()
  171.                                                 );
  172.                                         //Basic Stats
  173.                                         GUI.Label(new Rect(89,264,200,150),"Strength: "+playerStats.GetStrength() +
  174.                                                 "\nStamina: " + playerStats.GetStamina() +
  175.                                                 "\nAgility: " + playerStats.GetAgility() +
  176.                                                 "\nWillpower: " + playerStats.GetWillpower()
  177.                                                 );
  178.                                 GUI.EndGroup();
  179.                         break;
  180.                         case "Skills":
  181.                                 GUI.BeginGroup(new Rect(5,75,795,525));
  182.                
  183.                                         /////////////////////////////////////////
  184.                                         // ScrollView
  185.                                         GUI.skin = skillButtonText;
  186.                                         GUI.backgroundColor = Color.white;
  187.                                     skillScrollPosition = GUI.BeginScrollView (new Rect(96,80,600,350),
  188.                                 skillScrollPosition, Rect (0, 0, 580, 900));
  189.                                
  190.  
  191.                                
  192.                                
  193.                                                 GUI.backgroundColor = Color.cyan;
  194.                                                 GUI.Box(new Rect(0,0,580,170), "");
  195.                                                 GUI.backgroundColor = Color.blue;
  196.                                                 /////////////////////////////////////////////////
  197.                                                     // Skilltree A
  198.                                                     GUI.Button (Rect (5,42.5,75,75), skillA);
  199.                                                     GUI.Button (Rect (85,5,75,75), skillB);
  200.                                                     GUI.Button (Rect (85,85,75,75), skillC);
  201.                                                     GUI.Button (Rect (165,5,75,75), skillD);
  202.                                                     GUI.Button (Rect (165,85,75,75), skillE);
  203.                                                    
  204.                                                     GUI.backgroundColor = Color.red;
  205.                                                 GUI.Box(new Rect(0,175,580,170), "");
  206.                                                 GUI.backgroundColor = Color.blue;
  207.                                                    
  208.  
  209.  
  210.                                                    
  211.                                                    
  212.                                                    
  213.                                                                                                    
  214.                                 // End the scroll view that we began above.
  215.                                 GUI.EndScrollView ();
  216.    
  217.                                 GUI.backgroundColor = Color.clear;
  218.                        
  219.                                 //Display the tooltip if there is one
  220.  
  221.                                 if(GUI.tooltip){
  222.                                         GUI.skin = tooltipText;
  223.                                         GUI.backgroundColor=Color.clear;
  224.                                         GUI.BeginGroup (Rect (Input.mousePosition.x-230, Screen.height-Input.mousePosition.y-150, 275, 125));                                  
  225.                                         GUI.DrawTexture(Rect (0,0,275,125),menuBox);
  226.                                         GUI.Label(Rect (0,0,275,125),GUI.tooltip +"\n" +playerStats.GetCurrentHealth() +"/" +playerStats.GetMaxHealth());                                      
  227.                                         //GUI.Label(Rect(0,10,250,100), playerStats.GetCurrentHealth() +"/" +playerStats.GetMaxHealth());
  228.                                                 GUI.EndGroup();
  229.                                         }
  230.                                
  231.                                
  232.                                 GUI.EndGroup();
  233.                         break;
  234.                         case "Inventory":
  235.                                 GUI.BeginGroup(new Rect(5,75,795,525));
  236.  
  237.                                         /////////////////////////////////////////
  238.                                         // ScrollView
  239.                                         GUI.backgroundColor=Color.gray;
  240.                                        
  241.                                         // Item portrait
  242.                                         GUI.Box(new Rect(125,77,200,200),"");
  243.                                        
  244.                                         // Item Description
  245.                                         GUI.skin = descriptionText;
  246.                                         GUI.Label(new Rect(108,300,235,300),"Descriptive Text Here. Hell I can put whatever I want, I'm just glad to be makin' games!");
  247.                                        
  248.                                         //Inventory List
  249.                                     inventoryScrollPosition = GUI.BeginScrollView (new Rect(400,80,300,350),
  250.                                 inventoryScrollPosition, Rect (0, 0, 280, 900));
  251.                                
  252.                                 GUI.Box(new Rect(0,0,380,900),"");
  253.  
  254.                            
  255.                                 // End the scroll view that we began above.
  256.                                 GUI.EndScrollView ();
  257.  
  258.                                 GUI.EndGroup();
  259.                         break;
  260.                                                 case "Fade Skill":
  261.                                 GUI.BeginGroup(new Rect(5,75,795,525));
  262.  
  263.                                         /////////////////////////////////////////
  264.                                         // ScrollView
  265.                                         GUI.backgroundColor=Color.gray;
  266.                                        
  267.                                          //Item portrait
  268.                                         //GUI.Box(new Rect(125,77,200,200),"");
  269.                                        
  270.                                         // Item Description
  271.                                         //GUI.skin = descriptionText;
  272.                                         //GUI.Label(new Rect(108,300,235,300),"Descriptive Text Here. Hell I can put whatever I want, I'm just glad to be makin' games!");
  273.                                        
  274.                                         //Inventory List
  275.                                     //inventoryScrollPosition = GUI.BeginScrollView (new Rect(400,80,300,350),
  276.                                 //inventoryScrollPosition, Rect (0, 0, 280, 900));
  277.                                
  278.                                 GUI.Box(placementRect,"");
  279.  
  280.                            
  281.                                 // End the scroll view that we began above.
  282.                                 GUI.EndScrollView ();
  283.  
  284.                                 GUI.EndGroup();
  285.                         break;
  286.                 }
  287.                        
  288.                
  289.                 GUI.EndGroup();
  290.                
  291.                
  292.         }
  293. }
  294.  
  295. // GUI.box