public static Action AddDropHandler(int dropDstId, Delegate handler, bool isDefault = false) { var desc = new DropDescriptor() { dropDstId = dropDstId, handler = handler, isDefault = isDefault }; if (HasHandler(dropDstId, handler)) { throw new Exception("Delegate already registered for dropDestinationId:" + dropDstId); } if (isDefault && m_DropDescriptors.Any(d => d.dropDstId == dropDstId && d.isDefault)) { throw new Exception("Default handler already registered for dropDestinationId: " + dropDstId); } var list = new List <DropDescriptor>(m_DropDescriptors); list.Add(desc); list.Sort(); m_DropDescriptors = list.ToArray(); Action off = () => RemoveDropHandler(handler); return(off); }
public void OnItemPointerClick() { DropDescriptor desc = new DropDescriptor(); desc.sourceCell = this; desc.item = GetComponentInChildren <DragAndDropItem>(); // Get item from current cell gameObject.SendMessageUpwards("OnItemSelected", desc, SendMessageOptions.DontRequireReceiver); }
private IEnumerator NotifyOnDragEnd(DropDescriptor desc) { // Wait end of drag operation while (DragAndDropItem.draggedItem != null) { yield return(new WaitForEndOfFrame()); } // Send message with DragAndDrop info to parents GameObjects gameObject.SendMessageUpwards("OnItemPlace", desc, SendMessageOptions.DontRequireReceiver); }
public void OnDrop(DragAndDropCell cellFrom, DragAndDropCell cellTo, DragAndDropItem item) { if ((item != null) && (cellFrom != cellTo)) { DropDescriptor descriptor2 = new DropDescriptor { item = item, sourceCell = cellFrom, destinationCell = cellTo }; DropDescriptor descriptor = descriptor2; if (!this.CellIsTankSlot(cellTo)) { descriptor.destinationCell.PlaceItem(descriptor.item); if (this.onDrop != null) { descriptor2 = new DropDescriptor(); this.onDrop(descriptor, descriptor2); } } else if (this.CellIsTankSlot(cellFrom)) { descriptor2 = new DropDescriptor { destinationCell = descriptor.sourceCell, item = descriptor.destinationCell.GetItem(), sourceCell = descriptor.destinationCell }; DropDescriptor descriptor3 = descriptor2; descriptor.destinationCell.PlaceItem(descriptor.item); if (descriptor3.item != null) { descriptor.sourceCell.PlaceItem(descriptor3.item); } if (this.onDrop != null) { this.onDrop(descriptor, descriptor3); } } else { DragAndDropItem item2 = descriptor.destinationCell.GetItem(); DragAndDropCell component = null; if (item2 != null) { ModuleItem moduleItem = item2.GetComponent <SlotItemView>().ModuleItem; component = CollectionView.slots[moduleItem].GetComponent <DragAndDropCell>(); } descriptor2 = new DropDescriptor { destinationCell = component, item = item2, sourceCell = descriptor.destinationCell }; DropDescriptor descriptor4 = descriptor2; descriptor.destinationCell.PlaceItem(descriptor.item); if (descriptor4.item != null) { descriptor4.destinationCell.PlaceItem(descriptor4.item); } if (this.onDrop != null) { this.onDrop(descriptor, descriptor4); } } } }
/// <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) { 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 } } } }
private IEnumerator NotifyOnDragEnd(DropDescriptor desc) { // Wait end of drag operation while (DragAndDropItem.draggedItem != null) { yield return new WaitForEndOfFrame(); } // Send message with DragAndDrop info to parents GameObjects gameObject.SendMessageUpwards("OnItemPlace", desc, SendMessageOptions.DontRequireReceiver); }
/// <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 } } } }
public void OnDrop(PointerEventData data) { if (Block.icon != null) { if (Block.icon.activeSelf == true) { Block item = Block.draggedBlock; Panel sourcePanel = Block.sourcePanel; DropDescriptor desc = new DropDescriptor(); if ((item != null) && (sourcePanel == this) && (panelType == PanelType.Work)) { PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourcePanel = sourcePanel; desc.destinationPanel = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); //StartCoroutine(PositionBlock(desc)); } if ((item != null) && (sourcePanel != this)) { string itemName = item.name; switch (sourcePanel.panelType) // Check source cell's type { case PanelType.Side: item = Instantiate(item); // Clone item from source cell item.name = itemName; break; case PanelType.Work: break; default: // Nothing to do break; } switch (panelType) { case PanelType.Side: //Transform deadIcon = this.transform.parent.transform.Find("Icon"); //Destroy(deadIcon.gameObject); item.killBlock(); Destroy(item.gameObject); break; case PanelType.Work: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourcePanel = sourcePanel; desc.destinationPanel = this; // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); //StartCoroutine(PositionBlock(desc)); /*int index = 1; * int c = 0; * foreach (Transform child in transform) * { * * if (child.name != "PlaceHolder") * { * if (child.gameObject != desc.item.gameObject) * { * * print("child" + c + " y :" + child.transform.position.y); * print("Item y :" + Block.draggedBlock.getIconDrop()); * * c++; * * * * if (Block.draggedBlock.getIconDrop() < child.transform.position.y) * { * * index++; * * print(index); * * } * * } * * * * } * * } * print("Final: " + index); * desc.item.setItemIndex(index);*/ break; case PanelType.View: PlaceItem(item.gameObject); // Place dropped item in this cell // Fill event descriptor desc.item = item; desc.sourcePanel = sourcePanel; desc.destinationPanel = this.transform.GetChild(0).GetComponent <Panel>(); // Send message with DragAndDrop info to parents GameObjects StartCoroutine(NotifyOnDragEnd(desc)); //print("that darn viewPort!"); break; default: // Nothing to do break; } } if (item.GetComponentInParent <Panel>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } } } }