Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: Centauro5legs en Diciembre 09, 2015, 10:50:47 PM

Título: Ayuda con Drag and Drop en Canvas
Publicado por: Centauro5legs en Diciembre 09, 2015, 10:50:47 PM
Quiero hacer un inventario, usando un Script de Drag and Drop, ya tengo la lógica, pero me falta algo. Tengo el Siguiente Scrip;
 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Drag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
    public static GameObject itemBeginDrag;
    Vector3 startposition;
    Transform startparent;
    #region IBeginDragHandler implementation
    //------------------------------------------//
    //          Agarra un Item           //
    //------------------------------------------//
    public void OnBeginDrag (PointerEventData eventData)
    {
        itemBeginDrag = gameObject;
        startposition = transform.position;
        startparent = transform.parent;
        GetComponent<CanvasGroup> ().blocksRaycasts = false;
    }
    
    #endregion
    //------------------------------------------//
    //          Mueve un Item           //
    //------------------------------------------//
    #region IDragHandler implementation
    public void OnDrag (PointerEventData eventData)
    {
        transform.position = Input.mousePosition;
    }
    #endregion
    //------------------------------------------//
    //          Suelta el Item           //
    //------------------------------------------//
    #region IEndDragHandler implementation
    
    public void OnEndDrag (PointerEventData eventData)
    {
        DataInventary inventario = new DataInventary();
        itemBeginDrag = null;
 
        //Obtenemos el id de lo que contiene el Botón
        int indice = GetComponent<ChangedIcon>().indice;
        //Si se sobreposiciono sobre otro boton, cambiamos el contenido del botón
         /*
         * if("item esta sobre otro item"){
         *         int tempo = ItemSeleccionado;
         *         ItemSeleccionado = ItemSobreposicionado;
         *         ItemSobreposicionado = tempo;
         * }
         */
        GetComponent<ChangedIcon> ().cambiaricono ();
 
        //Devolvemos a la posición original
 
        GetComponent<CanvasGroup> ().blocksRaycasts = true;
        if (transform.parent != startparent) {
            transform.position = startposition; 
        }
    }
    
    #endregion
    //------------------------------------------//
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 
El Script funciona, en el sentido que puedo arrastrar los Items, pero mi pregunta es. ¿Cómo puedo saber sobre que botón esta sobreposicionado el botón que estoy arrastrando, para así poder cambiar su ID?....
 
(//%3CfileStore.core_Attachment%3E/monthly_2015_12/captura.thumb.png.24d9a78a44e59e296ce3201a9a507585.png)
Título: Ayuda con Drag and Drop en Canvas
Publicado por: leocub58 en Diciembre 09, 2015, 11:42:28 PM
Con event triggers puedes hacerlo.