SebastianLawe

Untitled

Apr 27th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LevelSelectHandler : MonoBehaviour {
  5.  
  6.     private LevelSelectController LSC = null;
  7.     public string thisDoorsLevel = "Level1"; /// <summary>
  8.     /// This is for the Level Selection Stuff
  9.     /// Not required for the New Game button or Continue Game Button
  10.     /// or the Level Arrow Stuff
  11.     /// </summary>
  12.     public int thisDoorsLevelNumber = 1; /// <summary>
  13.     /// This is for the Level Selection Stuff
  14.     /// Not required for the New Game button or Continue Game Button
  15.     /// or the Level Arrow Stuff
  16.     /// </summary>
  17.     // Use this for initialization
  18.     public Sprite spriteNewGame;
  19.     public Sprite spriteContinueGame;
  20.     public Sprite spriteLevelNext;
  21.     public Sprite spriteLevelBack;
  22.     public Sprite spritePlay;
  23.     public GUITexture textureNewGame = new GUITexture();
  24.     public GUITexture textureContinueGame = new GUITexture();
  25.     public GUITexture textureLevelNext = new GUITexture();
  26.     public GUITexture textureLevelBack = new GUITexture();
  27.     public GUITexture texturePlay = new GUITexture();
  28.     public GUIStyle NewGameButton = new GUIStyle();
  29.     public GUIStyle ContinueGameButton = new GUIStyle();
  30.     public GUIStyle LevelNextButton = new GUIStyle();
  31.     public GUIStyle LevelBackButton = new GUIStyle();
  32.     public GUIStyle PlayButton = new GUIStyle();
  33.     public int buttonHeight;
  34.     public int buttonWidth;
  35.     public int levelButtonWidth;
  36.     public int levelButtonHeight;
  37.  
  38.     public Texture2D texture2DFromSprite(Sprite sprite)
  39.     {
  40.         //if (sprite.rect.width != sprite.texture.width) {
  41.             Texture2D newText = new Texture2D ((int)sprite.rect.width, (int)sprite.rect.height);
  42.             Color[] newColors = sprite.texture.GetPixels ((int)sprite.textureRect.x,
  43.                                                          (int)sprite.textureRect.y,
  44.                                                          (int)sprite.textureRect.width,
  45.                                                          (int)sprite.textureRect.height);
  46.             newText.SetPixels (newColors);
  47.             newText.Apply ();
  48.             return newText;
  49.         //} else {
  50.             //return sprite.texture;
  51.         //}
  52.     }
  53.     void Start()
  54.     {
  55.                 textureNewGame = new GUITexture();
  56.                 textureContinueGame = new GUITexture();
  57.                 textureLevelNext = new GUITexture();
  58.                 textureLevelBack = new GUITexture();
  59.                 texturePlay = new GUITexture();
  60.                 newGameButton = new GUIStyle();
  61.                 ContinueGameButton = new GUIStyle();
  62.                 LevelNextButton = new GUIStyle();
  63.                 LevelBackButton = new GUIStyle();
  64.                 PlayButton = new GUIStyle();
  65.         textureNewGame.texture = texture2DFromSprite (spriteNewGame);
  66.         textureContinueGame.texture = texture2DFromSprite (spriteContinueGame);
  67.         textureLevelNext.texture = texture2DFromSprite (spriteLevelNext);
  68.         textureLevelBack.texture = texture2DFromSprite (spriteLevelBack);
  69.         texturePlay.texture = texture2DFromSprite (spritePlay);
  70.  
  71.         //The GUIStyle Textures are Setup Below
  72.         NewGameButton.normal.background = textureNewGame.texture as Texture2D;
  73.         ContinueGameButton.normal.background = textureContinueGame.texture as Texture2D;
  74.         LevelNextButton.normal.background = textureLevelNext.texture as Texture2D;
  75.         LevelBackButton.normal.background = textureLevelBack.texture as Texture2D;
  76.         PlayButton.normal.background = texturePlay.texture as Texture2D;
  77.     }
  78.     // Update is called once per frame
  79.     void Update () {
  80.        
  81.     }
  82.     void OnGUI()
  83.     {
  84.         if (GUI.Button (RelativeRect.GetExact (25, 20, buttonWidth, buttonHeight, true), "", NewGameButton)) {
  85.             Debug.Log ("Clicked New Game");
  86.         }
  87.         if (GUI.Button (RelativeRect.GetExact (25, 30, buttonWidth, buttonHeight, true), "", ContinueGameButton)) {
  88.             Debug.Log ("This is stupid");
  89.         }
  90.         if (GUI.Button (RelativeRect.GetExact (25,40,levelButtonWidth,levelButtonHeight,true),"",LevelBackButton))
  91.         {
  92.             Debug.Log ("Back 1 Level");
  93.         }
  94.         if (GUI.Button (RelativeRect.GetExact (65, 40, levelButtonWidth, levelButtonHeight, true), "", LevelNextButton)) {
  95.             Debug.Log ("Forward 1 Level");
  96.         }
  97.     }
  98.     void OnMouseDown()
  99.     {
  100.         /*if (gameObject.tag == "NewGame") {
  101.             Debug.Log ("New Game Started");
  102.             LSC.NewGame ();
  103.         }
  104.         if (gameObject.tag == "LevelDoor") {
  105.             if (thisDoorsLevel != null) {
  106.                 Debug.Log ("You click this!");
  107.                 LSC.LoadSpecificLevel (thisDoorsLevel, thisDoorsLevelNumber);
  108.                 //hi
  109.             }
  110.         }
  111.         if (gameObject.tag == "ContinueButton") {
  112.             LSC.ContinueCurrentLevel ();
  113.         }
  114.         if (gameObject.tag == "LevelUpButton") {
  115.             thisDoorsLevelNumber += 1;
  116.         }
  117.         if (gameObject.tag == "LevelDownButton") {
  118.             if (thisDoorsLevelNumber > 1) {
  119.                 thisDoorsLevelNumber -= 1;
  120.             }
  121.         }*/
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment