예제 #1
0
 /// <summary>
 /// Swap items between two cells
 /// </summary>
 /// <param name="firstCell"> Cell </param>
 /// <param name="secondCell"> Cell </param>
 public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
 {
     if ((firstCell != null) && (secondCell != null))
     {
         DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
         DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
                                                                         // Swap items
         if (firstItem != null)
         {
             firstItem.transform.SetParent(secondCell.transform, false);
             firstItem.transform.localPosition = Vector3.zero;
             firstItem.MakeRaycast(true);
         }
         if (secondItem != null)
         {
             secondItem.transform.SetParent(firstCell.transform, false);
             secondItem.transform.localPosition = Vector3.zero;
             secondItem.MakeRaycast(true);
         }
         // Update states
         firstCell.UpdateMyItem();
         secondCell.UpdateMyItem();
         firstCell.UpdateBackgroundState();
         secondCell.UpdateBackgroundState();
     }
 }
예제 #2
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true) // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)       // Check this cell's type
                    {
                    case CellType.DropOnly: // Item only can be dropped into destination cell
                        Text labelText = this.transform.Find("labelTemplate").GetComponent <Text> ();

                        if (labelText.text == "Choose One")
                        {
                            break;
                        }

                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                     // Send drop request
                        FindObjectOfType <AudioManager> ().Play("tileInBucket");
                        StartCoroutine(NotifyOnDragEnd(desc)); // Send notification after drop will be finished
                        if (desc.permission == true)           // If drop permitted by application
                        {
                            PlaceItem(item);                   // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell> () == null) // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
예제 #3
0
    /// <summary>
    /// Swap items between two cells
    /// </summary>
    /// <param name="firstCell"> Cell </param>
    /// <param name="secondCell"> Cell </param>
    public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
    {
        if ((firstCell != null) && (secondCell != null))
        {
            DragAndDropItem firstItem  = DragAndDropItem.draggedItem;       // Get item from first cell
            DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
                                                                            // Swap items
            if (secondItem != null)
            {
                if (secondItem.transform.parent != null)
                {
                    secondItem.transform.parent.DetachChildren();
                    DragAndDropItem tempItem = Instantiate(secondItem);
                    tempItem.GetComponent <PorteScript>().SetEntree1(false);
                    tempItem.GetComponent <PorteScript>().SetEntree2(false);
                    tempItem.GetComponent <PorteScript>().SetSortie(false);

                    Destroy(secondItem.gameObject);
                    secondItem = null;
                    secondItem = tempItem;
                }
                secondItem.transform.SetParent(firstCell.transform, false);
                secondItem.transform.localPosition = Vector3.zero;
                secondItem.MakeRaycast(true);
            }
            if (firstItem != null)
            {
                firstItem.transform.SetParent(secondCell.transform, false);
                firstItem.transform.localPosition = Vector3.zero;
                firstItem.MakeRaycast(true);
            }

            // Update states
            firstCell.UpdateMyItem();
            secondCell.UpdateMyItem();
            //Debug.Log(secondItem.GetComponent<PorteScript>().IsSortie());
            //firstCell.UpdateBackgroundState();
            //secondCell.UpdateBackgroundState();
        }
    }
예제 #4
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)                    // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    // if (item.equipmentType.Equals(equipmentType) || equipmentType.Equals(EquipmentType.Generic))
                    // {

                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)                                       // Check this cell's type
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                                                                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                            // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));        // Send notification after drop will be finished
                            if (desc.permission == true)                  // If drop permitted by application
                            {
                                if (myDadItem != null)                    // If destination cell has item
                                {
                                    // Fill event descriptor
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    {
                                        SwapItems(sourceCell, this);                        // Swap items between cells
                                    }
                                    else
                                    {
                                        PlaceItem(item);                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                        // Place dropped item into this empty cell
                                }
                            }
                            break;

                        default:                                            // Item in source cell can not be swapped
                                                                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                                                                            // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished
                        if (desc.permission == true)                        // If drop permitted by application
                        {
                            PlaceItem(item);                                // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
                //}
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
예제 #5
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                             // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));         // Send notification after drop will be finished
                            if (desc.permission == true)                   // If drop permitted by application
                            {
                                if (myDadItem != null)                     // If destination cell has item
                                // Fill event descriptor
                                {
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    // stack or swap
                                    {
                                        var movingCell  = this.myDadItem.gameObject;
                                        var currentCell = sourceCell.transform.GetChild(0).gameObject;
                                        if (!InventoryService.CanStack(currentCell, movingCell))
                                        {
                                            SwapItems(sourceCell, this);                     // Swap items between cells
                                        }
                                    }
                                    else
                                    {
                                        PlaceItem(item);                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                        // Place dropped item into this empty cell
                                }
                            }
                            InventoryService.RefreshToolBar();
                            break;

                        default:                                            // Item in source cell can not be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                        // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished
                        if (desc.permission == true)                        // If drop permitted by application
                        {
                            PlaceItem(item);                                // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
예제 #6
0
    /// <summary>
    /// Swap items between two cells
    /// </summary>
    /// <param name="firstCell"> Cell </param>
    /// <param name="secondCell"> Cell </param>
    public SwapType SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
    {
        var swapType = SwapType.None;

        if ((firstCell != null) && (secondCell != null))
        {
            DragAndDropItem firstDragAndDropItem  = firstCell.GetItem();               // Get item from first cell
            DragAndDropItem secondDragAndDropItem = secondCell.GetItem();              // Get item from second cell

            //try stack
            var isStacked = false;
            if (firstDragAndDropItem != null && secondDragAndDropItem != null)
            {
                var firstItemBehaviour  = firstDragAndDropItem.GetComponent <SlotItemBehaviour>();
                var secondItemBehaviour = secondDragAndDropItem.GetComponent <SlotItemBehaviour>();
                if (firstItemBehaviour != null && secondItemBehaviour != null)
                {
                    if (firstItemBehaviour.Item.Id.Equals(secondItemBehaviour.Item.Id))
                    {
                        if (secondItemBehaviour.Item.Quantity < secondItemBehaviour.Item.MaxStack)
                        {
                            //requirements match for stack we can stack here
                            var stackableAmount = secondItemBehaviour.Item.MaxStack - secondItemBehaviour.Item.Quantity;

                            if (firstItemBehaviour.Item.Quantity <= stackableAmount)
                            {
                                // all of them will be stacked to second cell
                                var inventoryBehaviour = secondItemBehaviour.GetComponentInParent <InventoryBehavior>();
                                var itemToStack        = inventoryBehaviour.ItemDatabase.getItemByID(firstItemBehaviour.Item.Id);
                                itemToStack.Quantity = firstItemBehaviour.Item.Quantity;
                                secondItemBehaviour.Stack(itemToStack);



                                //remove first Item slot
                                var firstItemSlotBehaviour = firstItemBehaviour.GetComponentInParent <SlotBehaviour>();
                                firstItemSlotBehaviour.RemoveItem();

                                swapType = SwapType.FullyStacked;
                            }
                            else
                            {
                                var initialFirstAmount  = firstItemBehaviour.Item.Quantity;
                                var initialSecondAmount = secondItemBehaviour.Item.Quantity;

                                secondItemBehaviour.Item.Quantity = firstItemBehaviour.Item.MaxStack;
                                firstItemBehaviour.Item.Quantity  = initialSecondAmount - (secondItemBehaviour.Item.MaxStack - initialFirstAmount);

                                firstItemBehaviour.SetItemAmount(firstItemBehaviour.Item.Quantity);
                                secondItemBehaviour.SetItemAmount(secondItemBehaviour.Item.Quantity);

                                if (firstItemBehaviour.Item.Quantity == 0)
                                {
                                    var firstItemSlotBehaviour = firstItemBehaviour.GetComponentInParent <SlotBehaviour>();
                                    firstItemSlotBehaviour.RemoveItem();
                                }

                                swapType = SwapType.PartiallyStacked;
                            }


                            isStacked = true;
                            //stacking process is done here
                        }
                    }
                }
            }

            if (!isStacked)
            {
                // Swap items
                if (firstDragAndDropItem != null)
                {
                    firstDragAndDropItem.transform.SetParent(secondCell.transform, false);
                    firstDragAndDropItem.transform.localPosition = Vector3.zero;
                    firstDragAndDropItem.MakeRaycast(true);
                }
                if (secondDragAndDropItem != null)
                {
                    secondDragAndDropItem.transform.SetParent(firstCell.transform, false);
                    secondDragAndDropItem.transform.localPosition = Vector3.zero;
                    secondDragAndDropItem.MakeRaycast(true);
                }

                swapType = SwapType.Swapped;
            }

            firstCell.UpdateMyItem();
            firstCell.UpdateBackgroundState();

            secondCell.UpdateMyItem();
            secondCell.UpdateBackgroundState();
        }
        return(swapType);
    }
예제 #7
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.draggedItem /*icon*/ != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)                    // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)                                       // Check this cell's type
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                if (myDadItem != null)                      // If destination cell has item
                                {
                                    // Fill event descriptor
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    {
                                        SwapItems(sourceCell, this);                        // Swap items between cells

                                        if (this.GetComponent <SocleScript>() != null)
                                        {
                                            this.GetComponent <SocleScript>().cableSortie.SetActif(false);
                                        }
                                    }
                                    else
                                    {
                                        PlaceItem(item);                                                                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    if (this.GetComponent <SocleScript>() != null)
                                    {
                                        this.GetComponent <SocleScript>().cableSortie.SetActif(false);
                                    }
                                    PlaceItem(item);                        // Place dropped item into this empty cell
                                    if (this.GetComponent <SocleScript>() != null)
                                    {
                                        this.GetComponent <SocleScript>().cableSortie.SetActif(false);
                                    }
                                }
                            }
                            break;

                        default:                                            // Item in source cell can not be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                        // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished
                        if (desc.permission == true)                        // If drop permitted by application
                        {
                            PlaceItem(item);                                // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
예제 #8
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)                    // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)                                       // Check this cell's type
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                if (myDadItem != null)                      // If destination cell has item
                                {
                                    // Fill event descriptor
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    {
                                        SwapItems(sourceCell, this);                        // Swap items between cells
                                    }
                                    else
                                    {
                                        PlaceItem(item);                                                                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                                                                    // Place dropped item into this empty cell
                                }
                            }
                            break;

                        default:                                            // Item in source cell can not be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                        // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished

                        //Object Parent
                        GameObject parent = this.transform.parent.gameObject;

                        if (!Tutorial)
                        {
                            if (this.Action && item.Action && desc.permission == true)
                            {
                                PlaceItem(item);
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                switch (item.name)
                                {
                                case ("Jump"):

                                    DisableDropOtherblocks(2);
                                    break;

                                case ("PickUp"):
                                case ("Drop"):
                                    DisableDropOtherblocks(1);
                                    break;

                                default:
                                    DisableDropOtherblocks(0);
                                    break;
                                }
                            }
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                            }
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                            }
                        }
                        else     //Tutorial Enable ------------------------------------------------------------------------------------
                        {
                            //Swim
                            if (this.Action && item.Action && desc.permission == true && item.name.Equals("Swim") && Tutorialstep == 1)
                            {
                                PlaceItem(item);
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar.";
                                Tutorialstep++;
                            }
                            //Right
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Right") && Tutorialstep == 2)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Indícame cuantos espacios debo nadar.";
                                Tutorialstep++;
                            }
                            //4
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true && item.name.Equals("4") && Tutorialstep == 3)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a saber qué hacer con el aluminio.";
                                Tutorialstep++;
                            }
                            //Pick Up
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("PickUp") && Tutorialstep == 4 && item.name.Equals("PickUp"))
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a llevar la botella sobre el contenedor de reciclaje de aluminio.";
                                Tutorialstep++;
                                DisableDropOtherblocks(1);
                            }
                            //Swim
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Swim") && Tutorialstep == 5)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a llevar la botella sobre el contenedor de reciclaje de aluminio.";
                                Tutorialstep++;
                            }
                            //Down
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Down") && Tutorialstep == 6)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a llevar la botella sobre el contenedor de reciclaje de aluminio.";
                                Tutorialstep++;
                            }
                            //4
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true && item.name.Equals("4") && Tutorialstep == 7)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a saber qué hacer cuando este sobre el contenedor.";
                                Tutorialstep++;
                            }
                            //Drop
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Drop") && Tutorialstep == 8 && item.name.Equals("Drop"))
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Presiona Play para correr el algoritmo de recoger y desechar la lata de aluminio.";
                                Tutorialstep++;
                                DisableDropOtherblocks(1);
                            }
                            //Wait for play button
                            else if (Tutorialstep == 9)    // wait for play button
                            {
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                            }
                            //Secon Part -----------------------
                            //swim
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Swim") && Tutorialstep == 10)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //left
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Left") && Tutorialstep == 11)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //1
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true && item.name.Equals("1") && Tutorialstep == 12)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a recoger la botella de cristal.";
                                Tutorialstep++;
                            }
                            //pick up
                            else if (this.Action && item.Action && desc.permission == true && Tutorialstep == 13 && item.name.Equals("PickUp"))
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                                DisableDropOtherblocks(1);
                            }
                            //Swim
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Swim") && Tutorialstep == 14)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //Up
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Up") && Tutorialstep == 15)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //2
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true && item.name.Equals("2") && Tutorialstep == 16)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //Swim
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Swim") && Tutorialstep == 17)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //Right
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Right") && Tutorialstep == 18)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Dirígeme hacia dónde debo nadar para alcanzar el cristal.";
                                Tutorialstep++;
                            }
                            //2
                            else if (this.Quantiy && item.Quantiy && desc.permission == true && this.canDrop == true && item.name.Equals("2") && Tutorialstep == 19)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 2);
                                PlaceItem(item);
                                Dialogue.text = "Ayudame a recoger la botella de cristal.";
                                Tutorialstep++;
                            }
                            //PickUp
                            else if (this.Action && item.Action && desc.permission == true && Tutorialstep == 20 && item.name.Equals("PickUp"))
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a llevar la botella sobre el contenedor de reciclaje de cristal.";
                                Tutorialstep++;
                                DisableDropOtherblocks(1);
                            }
                            //Jump
                            else if (this.Action && item.Action && desc.permission == true && item.name.Equals("Jump") && Tutorialstep == 21)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a llevar la botella sobre el contenedor de reciclaje de cristal.";
                                Tutorialstep++;
                                DisableDropOtherblocks(2);
                            }
                            //Down
                            else if (this.Direction && item.Direction && desc.permission == true && this.canDrop == true && item.name.Equals("Down") && Tutorialstep == 22)
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 1);
                                PlaceItem(item);
                                Dialogue.text = "Ayúdame a saber que hago con la botella de cristal en el contendor.";
                                Tutorialstep++;
                            }
                            //Drop
                            else if (this.Action && item.Action && desc.permission == true && Tutorialstep == 23 && item.name.Equals("Drop"))
                            {
                                AlgothimDevelopment.addCellArray(item.name, parent.name, 0);
                                PlaceItem(item);
                                Dialogue.text = "Presiona el botón de play para correr el algoritmo.";
                                Tutorialstep++;
                                DisableDropOtherblocks(1);
                            }
                        }     //ends tutorial ---------------------------------------------------------------------------------------------
                        break;

                    default:
                        break;
                    }
                }
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
예제 #9
0
 /// <summary>
 /// Item is dropped in this cell
 /// </summary>
 /// <param name="data"></param>
 public void OnDrop(PointerEventData data)
 {
     if (DragAndDropItem.icon != null)
     {
         DragAndDropItem item       = DragAndDropItem.draggedItem;
         DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
         if (DragAndDropItem.icon.activeSelf == true)                    // If icon inactive do not need to drop item into cell
         {
             if ((item != null) && (sourceCell != this))
             {
                 DropEventDescriptor desc = new DropEventDescriptor();
                 if (cellType == CellType.Swap)                                       // Check this cell's type
                 {
                     UpdateMyItem();
                     if (sourceCell.cellType == CellType.Swap)
                     {
                         desc.item            = item;
                         desc.sourceCell      = sourceCell;
                         desc.destinationCell = this;
                         SendRequest(desc);                     // Send drop request
                         StartCoroutine(NotifyOnDragEnd(desc)); // Send notification after drop will be finished
                         if (desc.permission == true)           // If drop permitted by application
                         {
                             if (myDadItem != null)             // If destination cell has item
                             {
                                 // Fill event descriptor
                                 DropEventDescriptor descAutoswap = new DropEventDescriptor
                                 {
                                     item            = myDadItem,
                                     sourceCell      = this,
                                     destinationCell = sourceCell
                                 };
                                 SendRequest(descAutoswap);                      // Send drop request
                                 StartCoroutine(NotifyOnDragEnd(descAutoswap));  // Send notification after drop will be finished
                                 if (descAutoswap.permission == true)            // If drop permitted by application
                                 {
                                     SwapItems(sourceCell, this);                // Swap items between cells
                                 }
                                 else
                                 {
                                     PlaceItem(item);            // Delete old item and place dropped item into this cell
                                 }
                             }
                             else
                             {
                                 PlaceItem(item);                // Place dropped item into this empty cell
                             }
                         }
                     }
                     else
                     {
                         desc.item            = item;
                         desc.sourceCell      = sourceCell;
                         desc.destinationCell = this;
                         SendRequest(desc);                      // Send drop request
                         StartCoroutine(NotifyOnDragEnd(desc));  // Send notification after drop will be finished
                         if (desc.permission == true)            // If drop permitted by application
                         {
                             PlaceItem(item);                    // Place dropped item into this cell
                         }
                     }
                 }
             }
         }
         if (item != null)
         {
             if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
             {
                 Destroy(item.gameObject);                               // Destroy it
             }
         }
         UpdateMyItem();
         sourceCell.UpdateMyItem();
     }
 }