Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class guitest : MonoBehaviour {
- public Texture2D[] textures;
- void Start(){
- Topan.GUI.DropBox textureField = new Topan.GUI.DropBox(GUIContent.none);
- textureField.size = new Vector2(200f, 200f);
- textureField.onDroppedObjects = (object[] inputObjects) => {
- if (inputObjects[0].GetType() == typeof(Texture2D)){
- Debug.Log("SETTING TEX TO " + (Texture2D)inputObjects[0]);
- textureField.content = new GUIContent( (Texture2D)inputObjects[0]);
- }
- };
- foreach (Texture2D tex in textures){
- Topan.GUI.Button button = new Topan.GUI.Button(tex.name);
- button.size = new Vector2(100f, 100f);
- button.canDrag = true;
- button.objectValue = tex;
- button.onUpdateDrag = () => {
- Vector2 tempPosition = Event.current.mousePosition;
- 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
- tempPosition.y -= button.size.y / 2f;
- button.position = tempPosition;
- };
- button.onStartDrag = () =>{
- button.customProperties["OrigPosition"] = button.position;
- };
- button.onEndDrag = () => {
- button.position = (Vector2)button.customProperties["OrigPosition"];
- };
- button.AutoSize(Topan.GUI.GetMainContainer());
- Topan.GUI.AddWidget(button, 1);
- }
- Topan.GUI.AddWidget(textureField);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment