private void refreshKuyruk(DragAndDropCell cell, GameObject item) { Debug.Log("refresKuyruk soruce cell: " + cell.GetComponent <Image>().sprite.name.ToString()); string name = item.name; item = Instantiate(item); item.name = name; PlaceItemForCell(cell, item); //StartCoroutine(GameObject.Find("GameManager").GetComponent<wheelManager>().refKuyruk(item)); }
void InstantiateSlotsCheckSize(int num) { if (num <= 104) { slot_widht_height = 100; slots_area.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(100, 100); cell.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(100, 100); InstantiateSlots(num + 1); } else if (num <= 143) { slot_widht_height = 80; slots_area.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(80, 80); cell.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(80, 80); InstantiateSlots(num + 1); } else if (num <= 263 && slot_widht_height > 60) { slots_area.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(60, 60); cell.GetComponent <UnityEngine.UI.GridLayoutGroup>().cellSize = new Vector2(60, 60); slot_widht_height = 60; InstantiateSlots(num + 1); } }
/// <summary> /// Swap items between to 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 ItemSlot slot1 = firstCell.GetComponent <ItemSlot>(); ItemSlot slot2 = secondCell.GetComponent <ItemSlot>(); Item item1 = slot1.item; Image image1 = slot1.image; Text text1 = slot1.counterText; Item item2 = slot2.item; Image image2 = slot2.image; Text text2 = slot2.counterText; if (firstItem != null) { slot1.item = item2; slot1.image = image2; slot1.counterText = text2; // Place first item into second cell firstItem.transform.SetParent(secondCell.transform, false); firstItem.transform.localPosition = Vector3.zero; secondCell.SetBackgroundState(true); } if (secondItem != null) { slot2.item = item1; slot2.image = image1; slot2.counterText = text1; // Place second item into first cell secondItem.transform.SetParent(firstCell.transform, false); secondItem.transform.localPosition = Vector3.zero; firstCell.SetBackgroundState(true); } } }
void AddItemToCell(InventoryItem item, DragAndDropCell cell) { if (cell == null) { return; } if (item == null) { DragAndDropItem itemController = cell.GetComponentInChildren <DragAndDropItem>(); if (itemController != null) { Destroy(itemController.gameObject); } return; } GameObject newItem = Instantiate(inventoryItemPrefab); newItem.GetComponent <DragAndDropItem>().item = item; newItem.GetComponent <Image>().sprite = item.icon ?? defaultSprite; newItem.GetComponent <Transform>().SetParent(cell.GetComponent <Transform>()); }
private bool CellIsTankSlot(DragAndDropCell cell) => cell.GetComponent <TankSlotView>() != null;
/// <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 } } } }
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(); }