Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Funcion Alternativa de arrastre de Ventana

Iniciado por Naxz, Junio 13, 2016, 09:00:32 PM

Tema anterior - Siguiente tema
Junio 13, 2016, 09:00:32 PM Ultima modificación: Septiembre 16, 2016, 02:24:39 PM por pioj
Hola buenas tiempo sin postear nada :)
 
Aquí les traigo una función algo básica, pero que a muchos quizás les cueste hacer, es un método alternativo para hacer ventanas que se puedan arrastrar, como habréis notado en las ultimas versiones de Unity el GUI.Window parece estar bugeado a la hora de arrastrar la ventana, así que aquí esta:
 

/* Variables */
private bool IsWindowMove = false;
private Vector2 LastMousePos = Vector2.zero;
/* Funcion dentro del callback */
Rect newRect = new Rect(0,0,350,200);   //Este es el Rect o Posicion del GUI que quiere mover
Event currentEvent = Event.current;
//Comprobamos si el mouse o puntero se encuentra encima del GUI que queremos mover
if (newRect.Contains (currentEvent.mousePosition) || IsWindowMove)
{
//Comprobamos si se esta haciendo click con el boton principal del mouse
if(currentEvent.isMouse && currentEvent.button ==  && currentEvent.type == EventType.mouseDrag)
{
   if(LastMousePos != Vector2.zero)
   {
      newRect.x = newRect.x + (currentEvent.mousePosition.x - LastMousePos.x);
      newRect.y = newRect.y + (currentEvent.mousePosition.y - LastMousePos.y);
   }
   LastMousePos = currentEvent.mousePosition;
   IsWindowMove = true;
}
//Al levantar el mouse las variables se devuelven a su valor por defecto
if(currentEvent.isMouse && currentEvent.button ==  && currentEvent.type == EventType.mouseUp)
{
   LastMousePos = Vector2.zero;
   IsWindowMove = false;
}
}

Etiquetas: