/// <summary> /// Put item into this cell. /// </summary> /// <param name="item">Item.</param> private void PlaceItem(DragAndDropItem item) { if (item != null) { DestroyItem(); // Remove current item from this cell myDadItem = null; DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>(); if (cell != null) { if (cell.unlimitedSource == true) { string itemName = item.name; item = Instantiate(item); // Clone item from source cell item.name = itemName; } } item.transform.SetParent(transform, false); item.transform.localPosition = Vector3.zero; item.MakeRaycast(true); myDadItem = item; Image dadImage = myDadItem.GetComponent <Image>(); if (dadImage.color.a == 0) { float r = dadImage.color.r; float g = dadImage.color.g; float b = dadImage.color.b; dadImage.color = new Color(r, g, b, 1); } } 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.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> /// Put item into this cell. /// </summary> /// <param name="item">Item.</param> private void PlaceItem(DragAndDropItem item) { if (item != null) { DestroyItem(); // Remove current item from this cell myDadItem = null; DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>(); if (cell != null) { if (cell.unlimitedSource == true) { string itemName = item.name; item = Instantiate(item); // Clone item from source cell item.name = itemName; } } item.transform.SetParent(transform, false); item.transform.localPosition = Vector3.zero; item.MakeRaycast(true); myDadItem = item; myDadItem.GetComponent <CanvasGroup>().alpha = 0.5f; //Hace que el item no sea visible cuando llega a la boca GameObject canvas = gameObject.transform.parent.gameObject; AtributosMascota atributos = canvas.transform.Find("MANAGER CANVAS").GetComponent <AtributosMascota>(); Animator anim = LINCE.GetComponent <Animator>(); anim.SetInteger("estaComiendo", 2); GestionComida gestorComida = canvas.transform.Find("Plato").GetComponent <GestionComida>(); GameObject comida = canvas.transform.Find("Plato").gameObject.transform.Find("Comida").gameObject; TMP_Text porcentaje = canvas.transform.Find("Plato").gameObject.transform.Find("Porcentaje").gameObject.GetComponent <TMP_Text>(); comida.GetComponent <DragAndDropItem>().enabled = false;; atributos.subirHambre(int.Parse(porcentaje.text)); gestorComida.EliminarItem(item.gameObject); Image imagen = comida.GetComponent <Image>(); imagen.color = new Color(imagen.color.r, imagen.color.g, imagen.color.b, 0.5f); //Item del plato StartCoroutine(ExecuteAfterTime(3)); } UpdateBackgroundState(); }
/// <summary> /// Put item into this cell. /// </summary> /// <param name="item">Item.</param> private void PlaceItem(DragAndDropItem item) { if (item != null) { DestroyItem(); // Remove current item from this cell myDadItem = null; DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>(); if (cell != null) { if (cell.unlimitedSource == true) { string itemName = item.name; item = Instantiate(item); // Clone item from source cell item.name = itemName; } } item.transform.SetParent(transform, false); item.transform.localPosition = Vector3.zero; item.MakeRaycast(true); myDadItem = item; } }
/// <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(); } }
private bool DraggedItemWasntDrop(DragAndDropItem item) => DragAndDropItem.sourceCell.Equals(item.GetComponentInParent <DragAndDropCell>());
/// <summary> /// Item is dropped in this cell /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { if (DragAndDropItem.icon != null) { if (DragAndDropItem.icon.activeSelf == true) // If icon inactive do not need to drop item in cell { DragAndDropItem item = DragAndDropItem.draggedItem; DragAndDropCell sourceCell = DragAndDropItem.sourceCell; DropDescriptor desc = new DropDescriptor(); if ((item != null) && (sourceCell != this)) { switch (sourceCell.cellType) // Check source cell's type { case CellType.UnlimitedSource: string itemName = item.name; item = Instantiate(item); // Clone item from source cell item.name = itemName; break; default: // Nothing to do break; } switch (cellType) // Check this cell's type { case CellType.Swap: DragAndDropItem currentItem = GetComponentInChildren <DragAndDropItem>(); switch (sourceCell.cellType) { case CellType.Swap: SwapItems(sourceCell, this); // Swap items between cells // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; desc.destinationCell = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); if (currentItem != null) { // Fill event descriptor desc.item = currentItem; desc.sourceCell = this; desc.destinationCell = sourceCell; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); } break; default: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; desc.destinationCell = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); break; } break; case CellType.DropOnly: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; desc.destinationCell = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); break; default: // Nothing to do break; } } if (item.GetComponentInParent <DragAndDropCell>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } } } }
/// <summary> /// Item is dropped in this cell /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { DragAndDropCell sourceCell = DragAndDropItem.sourceCell; if (DragAndDropItem.icon != null) { if (DragAndDropItem.icon.activeSelf == true) // If icon inactive do not need to drop item in cell { DragAndDropItem item = DragAndDropItem.draggedItem; try { UInt16 selectedItem = Convert.ToUInt16(item.GetComponent <Image>().sprite.name.ToString()); UInt16 sourceItem = Convert.ToUInt16(gameObject.GetComponent <Image>().sprite.name.ToString()); Debug.Log("childCount: " + gameObject.transform.childCount.ToString()); if (selectedItem != sourceItem || gameObject.transform.childCount >= 1) { sourceCell.GetComponent <AudioSource>().clip = item.GetComponent <number>().FalseSound; sourceCell.GetComponent <AudioSource>().enabled = true; sourceCell.GetComponent <AudioSource>().Play(); score -= 10; GameObject.Find("cark").GetComponent <gamePlayManager>().printToText(score); //( StartCoroutine(); return; } } catch (System.Exception e) { Debug.Log("Hata : " + e.Message); } DropDescriptor desc = new DropDescriptor(); if ((item != null) && (sourceCell != this)) { switch (sourceCell.cellType) // Check source cell's type { /* * case CellType.UnlimitedSource: * string itemName = item.name; * item = Instantiate(item); // Clone item from source cell * item.name = itemName; * break; */ default: // Nothing to do break; } switch (cellType) // Check this cell's type { case CellType.Swap: DragAndDropItem currentItem = GetComponentInChildren <DragAndDropItem>(); switch (sourceCell.cellType) { case CellType.Swap: SwapItems(sourceCell, this); // Swap items between cells // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; desc.destinationCell = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); if (currentItem != null) { // Fill event descriptor desc.item = currentItem; desc.sourceCell = this; desc.destinationCell = sourceCell; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); } break; default: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; desc.destinationCell = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); break; } break; case CellType.DropOnly: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourceCell = sourceCell; sourceCell.GetComponent <AudioSource>().clip = item.GetComponent <number>().TrueSound; sourceCell.GetComponent <AudioSource>().enabled = true; sourceCell.GetComponent <AudioSource>().Play(); Debug.Log("sourceCell: " + sourceCell.GetComponent <Image>().sprite.name.ToString()); //refreshKuyruk(sourceCell, item.gameObject); StartCoroutine(GameObject.Find("cark").GetComponent <gamePlayManager>().reloadKuyruk()); //StartCoroutine(GameObject.Find("GameManager").GetComponent<gamePlayManager>().endOfWheel()); desc.destinationCell = this; dropCount++; score += 10; GameObject.Find("cark").GetComponent <gamePlayManager>().printToText(score); // StartCoroutine(GameObject.Find("cark").GetComponent<gamePlayManager>().printToText(score)); if (dropCount == 8) { StartCoroutine(GameObject.Find("cark").GetComponent <gamePlayManager>().successMethod()); dropCount = 0; } Debug.Log("Drop Count: " + dropCount.ToString()); // Send message with DragAndDrop info to parents GameObjects /// StartCoroutine(NotifyOnDragEnd(desc)); break; default: // Nothing to do break; } } if (item.GetComponentInParent <DragAndDropCell>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } } } }
/// <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(); } }
void PlaceItemSync(int _item) { DragAndDropItem item = null; foreach (PhotonView dg in FindObjectsOfType <PhotonView>()) { if (dg.ViewID == _item) { item = dg.GetComponent <DragAndDropItem>(); break; } } if (item != null) { // Remove current item from this cell //DestroyItem(); myDadItem = null; DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>(); if (cell != null) { if (cell.unlimitedSource == true) { string itemName = item.name; // Clone item from source cell item = Instantiate(item); item.name = itemName; } //Debug.LogWarning("parent 2: " + cell.name); // Debug.LogWarning("evo ga ovde drag"); //set source cell type and sprite if (cell.transform.parent.gameObject.CompareTag("Sheet")) { cell.cellType = DragAndDropCell.CellType.DropOnly; cell.GetComponent <Image>().sprite = cell.empty; } else { cell.cellType = DragAndDropCell.CellType.Swap; } } item.transform.SetParent(transform, false); item.transform.localPosition = Vector3.zero; item.MakeRaycast(true); //set destination cell type item.GetComponentInParent <DragAndDropCell>().cellType = CellType.DragOnly; myDadItem = item; //enable playerName on image if (myDadItem.GetComponentInParent <DragAndDropCell>().transform.parent.gameObject.CompareTag("Sheet")) { myDadItem.gameObject.transform.GetChild(1).gameObject.SetActive(true); myDadItem.gameObject.transform.GetChild(1).GetComponent <TextMeshProUGUI>().color = Color.black; } else { //disable myDadItem.gameObject.transform.GetChild(1).gameObject.SetActive(false); } } UpdateBackgroundState(); }