/// <summary> /// Send drag and drop request to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns> result from desc.permission </returns> private bool SendRequest(DropEventDescriptor desc) { bool result = false; if (desc != null) { desc.triggerType = TriggerType.DropRequest; desc.permission = true; if (cellType == CellType.DropOnly) { /*if (transform.childCount == 0 && transform.name.Trim() == desc.sourceCell.transform.GetChild(0).GetComponent<Image>().AnsItem.name.Trim()) * { * desc.permission = true; * Debug.Log("This " + transform.name + " is equal " + desc.sourceCell.transform.name); * } * else * { * desc.permission = false; * }*/ if (transform.childCount == 0 && AnsItem == desc.sourceCell.transform.GetChild(0).gameObject) { desc.permission = true; Debug.Log("This " + AnsItem.name + " is equal " + desc.sourceCell.transform.GetChild(0).GetComponent <Image>().sprite.name); } else { desc.permission = false; } } SendNotification(desc); result = desc.permission; } return(result); }
/// <summary> /// Send drag and drop information to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> private void SendNotification(DropEventDescriptor desc) { if (desc != null) { // Send message with DragAndDrop info to parents GameObjects gameObject.SendMessageUpwards("OnSimpleDragAndDropEvent", desc, SendMessageOptions.DontRequireReceiver); } }
/// <summary> /// Wait for event end and send notification to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns></returns> private IEnumerator NotifyOnDragEnd(DropEventDescriptor desc) { // Wait end of drag operation while (DragAndDropItem.draggedItem != null) { yield return(new WaitForEndOfFrame()); } desc.triggerType = TriggerType.DropEventEnd; }
/// <summary> /// Wait for event end and send notification to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns></returns> private IEnumerator NotifyOnDragEnd(DropEventDescriptor desc) { // Wait end of drag operation while (Item.draggedItem != null) { yield return(new WaitForEndOfFrame()); } desc.triggerType = TriggerType.DropEventEnd; SendNotification(desc); //yield return new WaitForSeconds(.1f); }
/// <summary> /// Send drag and drop request to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns> result from desc.permission </returns> private bool SendRequest(DropEventDescriptor desc) { bool result = false; if (desc != null) { desc.triggerType = TriggerType.DropRequest; desc.permission = true; result = desc.permission; } return(result); }
/// <summary> /// Manualy add item into this cell /// </summary> /// <param name="newItem"> New item </param> public void AddItem(DragAndDropItem newItem) { if (newItem != null) { PlaceItem(newItem); DropEventDescriptor desc = new DropEventDescriptor(); // Fill event descriptor desc.triggerType = TriggerType.ItemAdded; desc.item = newItem; desc.sourceCell = this; desc.destinationCell = this; } }
/// <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(); } }
/// <summary> /// Item is dropped in this cell /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { if (Item.icon != null) { Item item = Item.draggedItem; Cell sourceCell = Item.sourceCell; if (Item.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 // 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: Debug.Log("Drag Only"); break; } } } if (item != null) { if (item.GetComponentInParent <Cell>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } } UpdateMyItem(); sourceCell.UpdateMyItem(); } }
/// <summary> /// Destroy item in this cell /// </summary> private void DestroyItem() { UpdateMyItem(); if (myDadItem != null) { DropEventDescriptor desc = new DropEventDescriptor(); // Fill event descriptor desc.triggerType = TriggerType.ItemWillBeDestroyed; desc.item = myDadItem; desc.sourceCell = this; desc.destinationCell = this; SendNotification(desc); // Notify application about item destruction if (myDadItem != null) { Destroy(myDadItem.gameObject); } } myDadItem = null; }
/// <summary> /// Send drag and drop request to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns> result from desc.permission </returns> private bool SendRequest(DropEventDescriptor desc) { bool result = false; if (desc != null) { desc.triggerType = TriggerType.DropRequest; if (transform.childCount == 0 && transform.name.Trim() == desc.sourceCell.transform.name.Trim()) { desc.permission = true; Debug.Log("This " + transform.name + " is equal " + desc.sourceCell.transform.name); } else { desc.permission = false; } SendNotification(desc); result = desc.permission; } return(result); }
/// <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(); } }
/// <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(); } }
/// <summary> /// Item is dropped in this cell /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { if (Item.itemDragging != null) { Item item = Item.draggedItem; Cell sourceCell = Item.sourceCell; if (Item.itemDragging.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 * { * Debug.Log("Delete old item and place dropped item into this cell"); * PlaceItem( * item); // Delete old item and place dropped item into this cell * }*/ } else { Debug.Log("Place dropped item into this empty cell"); 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 } else { item.transform.SetParent(desc.sourceCell.transform); item.transform.position = desc.sourceCell.transform.position; } break; default: Debug.Log("Drag Only"); item.transform.SetParent(sourceCell.transform); item.transform.position = sourceCell.transform.position; break; } } } if (item != null) { if (item.GetComponentInParent <Cell>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } } UpdateMyItem(); UpdateBackgroundState(); sourceCell.UpdateMyItem(); sourceCell.UpdateBackgroundState(); } }
/// <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(); } }
/// <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(); } }
/// <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(); } }