예제 #1
0
    public void OnDrop(PointerEventData eventData)
    {
        //Debug.Log (eventData.pointerDrag.name + " OnDrop to " + gameObject.name);

        Dragable dropedObject = eventData.pointerDrag.GetComponent <Dragable>();

        if (dropedObject != null && !occupied)
        {
            // removing the object from the previous DropZone && unregistering it
            if (dropedObject.GetDropZoneParentK() != null)
            {
                DropZone_Katakana dod = dropedObject.GetDropZoneParentK(); // Droped Object Dropzone
                int dodsn             = dod.GetSlotNumber();               // Droped Object Dropzone Slot Number
                dod.objectInThisSpot = null;
                GCDnD.unsetInputKatakana(dodsn);
            }

            dropedObject.parentToReturnTo = this.transform;
            objectInThisSpot = eventData.pointerDrag;

            int slotNum = this.GetSlotNumber();
            GCDnD.setInputHirgana(slotNum, eventData.pointerDrag.name);

            this.transform.GetComponent <Image>().color = colorWhite;
        }
        else if (dropedObject != null && occupied)
        {
            int slotNum = -1;

            // Object In this spot handler for moving to new spot
            Transform         parentTransform = dropedObject.parentToReturnTo;
            DropZone_Katakana parentDropZone  = parentTransform.GetComponent <DropZone_Katakana>();
            if (parentDropZone != null)
            {
                parentDropZone.objectInThisSpot = objectInThisSpot;
            }

            objectInThisSpot.GetComponent <Dragable>().parentToReturnTo = dropedObject.parentToReturnTo;
            objectInThisSpot.transform.SetParent(dropedObject.parentToReturnTo);
            objectInThisSpot.transform.SetSiblingIndex(dropedObject.GetPlaceholderSiblingIndex());
            if (dropedObject.GetDropZoneParentK() != null)
            {
                slotNum = dropedObject.GetDropZoneParentK().GetSlotNumber();
                GCDnD.setInputHirgana(slotNum, objectInThisSpot.name);
            }
            dropedObject.parentToReturnTo.transform.GetComponent <Image>().color = colorWhite;

            // Object coming into this spot handler
            dropedObject.parentToReturnTo = this.transform;
            eventData.pointerDrag.transform.SetParent(this.transform);
            objectInThisSpot = eventData.pointerDrag;
            slotNum          = this.GetSlotNumber();
            GCDnD.setInputHirgana(slotNum, eventData.pointerDrag.name);
            this.transform.GetComponent <Image>().color = colorWhite;
        }

        //Debug.Log("Occupied = " + occupied);
    }