/// <summary> /// On any item drag start need to disable all items raycast for correct drop operation /// </summary> /// <param name="item"> dragged item </param> private void OnAnyItemDragStart(DragAndDropItem item) { UpdateMyItem(); if (myDadItem != null) { myDadItem.MakeRaycast(false); // Disable item's raycast for correct drop handling } }
/// <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(); } }
/// <summary> /// On any item drag start need to disable all items raycast for correct drop operation /// </summary> /// <param name="item"> dragged item </param> private void OnAnyItemDragStart(DragAndDropItem item) { DragAndDropItem myItem = GetComponentInChildren <DragAndDropItem>(); // Get item from current cell if (myItem != null) { myItem.MakeRaycast(false); // Disable item's raycast for correct drop handling if (myItem == item) // If item dragged from this cell { // Check cell's type switch (cellType) { case CellType.DropOnly: DragAndDropItem.icon.SetActive(false); // Item will not be dropped break; case CellType.UnlimitedSource: // Nothing to do break; default: item.MakeVisible(false); // Hide item in cell till dragging SetBackgroundState(false); break; } } } }
/// <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> /// On any item drag start need to disable all items raycast for correct drop operation /// </summary> /// <param name="item"> dragged item </param> private void OnAnyItemDragStart(DragAndDropItem item) { UpdateMyItem(); if (myDadItem != null) { myDadItem.MakeRaycast(false); // Disable item's raycast for correct drop handling if (myDadItem == item) // If item dragged from this cell { // Check cell's type switch (cellType) { case CellType.DropOnly: DragAndDropItem.icon.SetActive(false); // Item can not be dragged. Hide icon break; } } } }
/// <summary> /// Put new item in this cell /// </summary> /// <param name="itemObj"> New item's object with DragAndDropItem script </param> public void PlaceItem(GameObject itemObj) { RemoveItem(); // Remove current item from this cell if (itemObj != null) { itemObj.transform.SetParent(transform, false); itemObj.transform.localPosition = Vector3.zero; DragAndDropItem item = itemObj.GetComponent <DragAndDropItem>(); if (item != null) { item.MakeRaycast(true); } SetBackgroundState(true); } }
/// <summary> /// On any item drag end enable all items raycast /// </summary> /// <param name="item"> dragged item </param> private void OnAnyItemDragEnd(DragAndDropItem item) { DragAndDropItem myItem = GetComponentInChildren <DragAndDropItem>(); // Get item from current cell if (myItem != null) { if (myItem == item) { SetBackgroundState(true); } myItem.MakeRaycast(true); // Enable item's raycast } else { SetBackgroundState(false); } }
/// <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 new item in this cell /// </summary> /// <param name="itemObj"> New item's object with DragAndDropItem script </param> public void PlaceItem(GameObject itemObj) { //RemoveItem(); // Remove current item from this cell if (itemObj != null) { itemObj.transform.SetParent(transform, false); itemObj.transform.localPosition = Vector3.zero; DragAndDropItem item = itemObj.GetComponent <DragAndDropItem>(); if (item != null) { item.MakeRaycast(true); } SetBackgroundState(true); } foreach (Transform child in transform) { print("Foreach loop: " + child); }//foreach print("Done"); }
/// <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(); } }
/// <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; * } * }*/ if (item.transform.parent != null) { item.transform.parent.DetachChildren(); DragAndDropItem tempItem = Instantiate(item); tempItem.GetComponent <PorteScript>().SetEntree1(false); tempItem.GetComponent <PorteScript>().SetEntree2(false); tempItem.GetComponent <PorteScript>().SetSortie(false); Destroy(item.gameObject); item = null; item = tempItem; } item.transform.SetParent(this.transform, false); item.transform.localPosition = Vector3.zero; item.MakeRaycast(true); /*item.transform.SetParent(transform, false); * item.transform.localPosition = Vector3.zero; * item.MakeRaycast(true); * myDadItem = item;*/ } 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> /// 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); }
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(); }