Advertisement
CassataGames

Untitled

May 25th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. public class Toolbar : MonoBehaviour
  2. {
  3.      public static bool leftClick;
  4.     [System.Serializable]
  5.     public class ButtonsClass
  6.     {
  7.         public bool MouseOver;
  8.         public Vector2 ButtonSize;
  9.         public Vector2 ButtonPosition;
  10.         public Texture2D ButtonTexture;
  11.         public Texture2D HighlightTexture;
  12.         Texture2D CurrentTexture;
  13.         public enum ButtonType { Color, Direction, Orientation, Object }
  14.         public ButtonType Type;
  15.         public string Name;
  16.        
  17.         public Rect ButtonRect()
  18.         {
  19.             return new Rect((int)(ButtonPosition.x * (Screen.height * 0.01f)), // Left
  20.                             (int)(ButtonPosition.y * (Screen.height * 0.01f)), // Top
  21.                             (int)(ButtonSize.x * (Screen.height * 0.01f)), // Width
  22.                             (int)(ButtonSize.y * (Screen.height * 0.01f))); // Height
  23.         }
  24.         public Rect ButtonRect(int xMulti)
  25.         {
  26.             return new Rect((int)((ButtonPosition.x*xMulti) * (Screen.height * 0.01f)), // Left
  27.                             (int)(ButtonPosition.y * (Screen.height * 0.01f)), // Top
  28.                             (int)(ButtonSize.x * (Screen.height * 0.01f)), // Width
  29.                             (int)(ButtonSize.y * (Screen.height * 0.01f))); // Height
  30.         }
  31.         public void DrawButton()
  32.         {
  33.             CheckMouse(1);
  34.             GUI.DrawTexture(ButtonRect(), CurrentTexture, ScaleMode.StretchToFill, true);
  35.         }
  36.         public void DrawButton(int xMultiply)
  37.         {
  38.             CheckMouse(xMultiply);
  39.             GUI.DrawTexture(ButtonRect(xMultiply), CurrentTexture, ScaleMode.StretchToFill, true);
  40.         }
  41.         void CheckMouse(int xMulti)
  42.         {
  43.             Vector2 MousePos = new Vector2(Input.mousePosition.x-2,((Input.mousePosition.y - Screen.height) * -1)-2); // Gives us an easier to use variable
  44.  
  45.             if (MousePos.x > ButtonRect(xMulti).x & MousePos.y > ButtonRect(xMulti).y & MousePos.x < ButtonRect(xMulti).xMax & MousePos.y < ButtonRect(xMulti).yMax)
  46.             {
  47.                 CurrentTexture = HighlightTexture;
  48.                 if (leftClick)
  49.                 {
  50.                     ButtonClicked();
  51.                     leftClick = false;
  52.                 }
  53.             }
  54.             else
  55.             {
  56.                 CurrentTexture = ButtonTexture;
  57.             }
  58.         }
  59.         void ButtonClicked()
  60.         {
  61.             switch (Type)
  62.             {
  63.                 case ButtonType.Color:
  64.                     SetColor(Name); // Fix this tomorrow
  65.                     break;
  66.                 default:
  67.                     Debug.Log("No type selected.");
  68.                     break;
  69.             }
  70.         }
  71.     }
  72.  
  73.     public void SetColor(string recievedName)
  74.     {
  75.         switch (recievedName)
  76.         {
  77.             case "red":
  78.                 break;
  79.             default:
  80.                 Debug.Log("Color name invalid.");
  81.                 break;
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement