Guest User

GUITest

a guest
Feb 8th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class guitest : MonoBehaviour {
  5.  
  6. public Texture2D[] textures;
  7.  
  8.     void Start(){
  9.         Topan.GUI.DropBox textureField = new Topan.GUI.DropBox(GUIContent.none);
  10.         textureField.size = new Vector2(200f, 200f);
  11.         textureField.onDroppedObjects = (object[] inputObjects) => {
  12.             if (inputObjects[0].GetType() == typeof(Texture2D)){
  13.                 Debug.Log("SETTING TEX TO " + (Texture2D)inputObjects[0]);
  14.                 textureField.content = new GUIContent( (Texture2D)inputObjects[0]);
  15.             }
  16.         };
  17.        
  18.        
  19.         foreach (Texture2D tex in textures){
  20.             Topan.GUI.Button button = new Topan.GUI.Button(tex.name);
  21.             button.size = new Vector2(100f, 100f);
  22.             button.canDrag = true;
  23.             button.objectValue = tex;
  24.             button.onUpdateDrag = () => {
  25.                 Vector2 tempPosition = Event.current.mousePosition;
  26.                 tempPosition.x -= button.size.x / 2f;           //I do all this to set the CENTER of the button to be on the mouse, since the button's pivot is somewhy top left. GAAHHHH
  27.                 tempPosition.y -= button.size.y / 2f;
  28.                 button.position = tempPosition;
  29.             };
  30.             button.onStartDrag = () =>{
  31.                 button.customProperties["OrigPosition"] = button.position;
  32.             };
  33.             button.onEndDrag = () => {
  34.                 button.position = (Vector2)button.customProperties["OrigPosition"];
  35.             };
  36.             button.AutoSize(Topan.GUI.GetMainContainer());
  37.             Topan.GUI.AddWidget(button, 1);
  38.         }
  39.        
  40.        
  41.         Topan.GUI.AddWidget(textureField);
  42.        
  43.    
  44.     }
  45.    
  46.  
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment