/// <summary> /// Item is dropped into this cell. /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { if (DadItem.icon != null) { DadCell sourceCell = DadItem.sourceCell; if (sourceCell != this) { DadEventDescriptor desc = new DadEventDescriptor(); desc.sourceCell = sourceCell; desc.destinationCell = this; if (SendGroupRequest(desc) == true) // Send group request { SendCellRequest(desc); // Send cell request } StartCoroutine(NotifyOnDragEnd(desc)); // Send notification after drop will be finished if (desc.cellPermission == true && desc.groupPermission == true) // If drop permitted { SwapItems(sourceCell, this); // Swap items between cells } } UpdateMyItem(); UpdateBackgroundState(); sourceCell.UpdateMyItem(); sourceCell.UpdateBackgroundState(); } }
/// <summary> /// Send drag and drop information to cell /// </summary> /// <param name="desc"> drag and drop event descriptor </param> private void SendCellNotification(GameObject source, DadEventDescriptor desc) { if (source != null && desc != null) { // Send message with DragAndDrop info to GameObject source.SendMessage("OnDadCellEvent", desc, SendMessageOptions.DontRequireReceiver); } }
/// <summary> /// Send drag and drop information to group /// </summary> /// <param name="desc"> drag and drop event descriptor </param> private void SendGroupNotification(GameObject source, DadEventDescriptor desc) { if (source != null && desc != null) { // Send message with DragAndDrop info to parents GameObjects source.SendMessageUpwards("OnDadGroupEvent", 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(DadEventDescriptor desc) { // Wait end of drag operation while (DadItem.draggedItem != null) { yield return(new WaitForEndOfFrame()); } desc.triggerType = TriggerType.DragEnd; SendGroupNotification(desc.sourceCell.gameObject, desc); desc.triggerType = TriggerType.DropEnd; SendGroupNotification(desc.destinationCell.gameObject, desc); }
/// <summary> /// Manualy add item into this cell. /// </summary> /// <param name="item"> New item </param> public void AddItem(GameObject item) { if (item != null) { PlaceItem(item, true); DadEventDescriptor desc = new DadEventDescriptor(); // Fill event descriptor desc.triggerType = TriggerType.ItemAdded; desc.sourceCell = this; desc.destinationCell = this; // Send notification about item adding SendGroupNotification(desc.destinationCell.gameObject, desc); } }
/// <summary> /// Send drag and drop cell request to application /// </summary> /// <returns><c>true</c>, if confirm is successfull, <c>false</c> otherwise.</returns> /// <param name="desc">Desc.</param> private bool SendCellRequest(DadEventDescriptor desc) { bool result = false; if (desc != null) { // To source cell desc.triggerType = TriggerType.DragCellRequest; SendCellNotification(desc.sourceCell.gameObject, desc); // To destination cell desc.triggerType = TriggerType.DropCellRequest; SendCellNotification(desc.destinationCell.gameObject, desc); result = desc.cellPermission; } return(result); }
/// <summary> /// Send drag and drop group request to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> /// <returns> result from desc.permission </returns> private bool SendGroupRequest(DadEventDescriptor desc) { //print(17); bool result = false; if (desc != null) { desc.cellPermission = true; desc.groupPermission = true; // To source cell desc.triggerType = TriggerType.DragGroupRequest; SendGroupNotification(desc.sourceCell.gameObject, desc); // To destination cell desc.triggerType = TriggerType.DropGroupRequest; SendGroupNotification(desc.destinationCell.gameObject, desc); result = desc.groupPermission; } return(result); }
/// <summary> /// Destroy item in this cell /// </summary> private void DestroyItem() { UpdateMyItem(); GameObject item = GetItem(); if (item != null) { DadEventDescriptor desc = new DadEventDescriptor(); // Fill event descriptor desc.triggerType = TriggerType.ItemWillBeDestroyed; desc.sourceCell = this; desc.destinationCell = this; // Send notification about item destruction SendGroupNotification(desc.destinationCell.gameObject, desc); if (item != null) { Destroy(item); } } myDadItem = null; UpdateBackgroundState(); }