/// <summary> /// Operate all drag and drop requests and events from children cells /// </summary> /// <param name="desc"> request or event descriptor </param> void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { return; //// Get control unit of source cell //DummyControlUnit sourceSheet = desc.sourceCell.GetComponentInParent<DummyControlUnit>(); //// Get control unit of destination cell //DummyControlUnit destinationSheet = desc.destinationCell.GetComponentInParent<DummyControlUnit>(); //switch (desc.triggerType) // What type event is? //{ // case DragAndDropCell.TriggerType.DropRequest: // Request for item drag (note: do not destroy item on request) // Debug.Log("Request " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); // break; // case DragAndDropCell.TriggerType.DropEventEnd: // Drop event completed (successful or not) // if (desc.permission == true) // If drop successful (was permitted before) // { // Debug.Log("Successful drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); // } // else // If drop unsuccessful (was denied before) // { // Debug.Log("Denied drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); // } // break; // case DragAndDropCell.TriggerType.ItemAdded: // New item is added from application // Debug.Log("Item " + desc.item.name + " added into " + destinationSheet.name); // break; // case DragAndDropCell.TriggerType.ItemWillBeDestroyed: // Called before item be destructed (can not be canceled) // Debug.Log("Item " + desc.item.name + " will be destroyed from " + sourceSheet.name); // break; // default: // Debug.Log("Unknown drag and drop event"); // break; //} }
public bool Add(Item item, bool tryStacking = true) { if (tryStacking) { //Check for any available stack for this item SlotItemBehaviour stackableSlotItem = CheckHasStackableItem(item); if (stackableSlotItem) { stackableSlotItem.Stack(item); return(true); } } //check empty slot for this item var emptySlot = FindEmptySlot(); if (emptySlot == null) { return(false); } var addetSlotItem = emptySlot.AddItem(item); var desc = new DragAndDropCell.DropEventDescriptor(); // Fill event descriptor desc.triggerType = DragAndDropCell.TriggerType.ItemAdded; desc.item = addetSlotItem.GetComponent <DragAndDropItem>(); desc.sourceCell = addetSlotItem.GetComponentInParent <DragAndDropCell>(); desc.destinationCell = addetSlotItem.GetComponentInParent <DragAndDropCell>();; SendNotification(desc); return(true); }
/// <summary> /// Send drag and drop information to application /// </summary> /// <param name="desc"> drag and drop event descriptor </param> private void SendNotification(DragAndDropCell.DropEventDescriptor desc) { if (desc != null) { // Send message with DragAndDrop info to parents GameObjects gameObject.SendMessageUpwards("OnSimpleDragAndDropEvent", desc, SendMessageOptions.DontRequireReceiver); } }
/// <summary> /// Operate all drag and drop requests and events from children cells /// </summary> /// <param name="desc"> request or event descriptor </param> void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { // Get control unit of source cell DummyControlUnit sourceSheet = desc.sourceCell.GetComponentInParent <DummyControlUnit>(); // Get control unit of destination cell DummyControlUnit destinationSheet = desc.destinationCell.GetComponentInParent <DummyControlUnit>(); switch (desc.triggerType) // What type event is? { case DragAndDropCell.TriggerType.DropRequest: // Request for item drag (note: do not destroy item on request) Debug.Log("Request " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); SelectedDrop = desc.item.transform.GetComponent <DragAndDropItem>().type.ToString(); break; case DragAndDropCell.TriggerType.DropEventEnd: // Drop event completed (successful or not) if (desc.permission == true) // If drop successful (was permitted before) { Debug.Log("Successful drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); } else // If drop unsuccessful (was denied before) { Debug.Log("Denied drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name); } break; case DragAndDropCell.TriggerType.ItemAdded: // New item is added from application Debug.Log("Item " + desc.item.name + " added into " + destinationSheet.name); break; case DragAndDropCell.TriggerType.ItemWillBeDestroyed: // Called before item be destructed (can not be canceled) Debug.Log("Item " + desc.item.name + " will be destroyed from " + sourceSheet.name); SelectedDrag = desc.item.transform.GetComponent <DragAndDropItem>().type.ToString(); Selected = desc.item.transform.gameObject; if (SelectedDrag == SelectedDrop) { GameObject parent = desc.item.gameObject.transform.parent.gameObject; Debug.Log(desc.item.gameObject.transform.parent.gameObject.name); for (int i = 0; i < desc.item.gameObject.transform.parent.transform.childCount; i++) { Destroy(desc.item.gameObject.transform.parent.GetChild(i).gameObject); } StartCoroutine(IntiateEffect(parent)); } else { Destroy = true; } break; default: Debug.Log("Unknown drag and drop event"); break; } }
internal virtual void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { //Debug.Log("updating slots:"+gameObject.name +" evenetName:"+desc.triggerType.ToString()); UpdateSlots(); DisableButtons(); if (desc.triggerType == DragAndDropCell.TriggerType.DropEventEnd && gameObject.name == "PlayerInventory") { var craftMenuObj = GameObject.Find("CraftMenu"); var craftingTable = craftMenuObj.GetComponent <CraftingTable>(); craftingTable.UpdateUI(); } return; // // Get control unit of source cell // var sourceSheet = desc.sourceCell.GetComponentInParent<InventoryBehavior>(); // // Get control unit of destination cell // var destinationSheet = desc.destinationCell.GetComponentInParent<InventoryBehavior>(); // var actualItem = desc.item.GetComponent<SlotItemBehaviour>(); // var icon = desc.item.GetComponent<Image>(); // icon.sprite = actualItem.Item.Icon; // switch (desc.triggerType) // What type event is? // { // case DragAndDropCell.TriggerType.DropRequest: // Request for item drag (note: do not destroy item on request) // Debug.Log("Request " + actualItem.Item.Name + " from " + sourceSheet.name + " to " + destinationSheet.name); // break; // case DragAndDropCell.TriggerType.DropEventEnd: // Drop event completed (successful or not) // if (desc.permission == true) // If drop successful (was permitted before) // { // Debug.Log("Successful drop " + actualItem.Item.Name + " from " + sourceSheet.name + " to " + destinationSheet.name); // UpdateSlots(); // } // else // If drop unsuccessful (was denied before) // { // Debug.Log("Denied drop " + actualItem.Item.Name + " from " + sourceSheet.name + " to " + destinationSheet.name); // } // break; // case DragAndDropCell.TriggerType.ItemAdded: // New item is added from application // Debug.Log("Item " + actualItem.Item.Name + " added into " + destinationSheet.name); // break; // case DragAndDropCell.TriggerType.ItemWillBeDestroyed: // Called before item be destructed (can not be canceled) // Debug.Log("Item " + actualItem.Item.Name + " will be destroyed from " + sourceSheet.name); // break; // default: // Debug.Log("Unknown drag and drop event"); // break; // } }
void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { if (desc.triggerType == DragAndDropCell.TriggerType.DropRequest && desc.sourceCell.CompareTag("HandSlot")) { // beletette a kártyát a deckbe a kezéből GameManager.instance.player.hand.Remove(desc.item.GetComponent <CardDisplay>().card); GameManager.instance.player.deck.Add(desc.item.GetComponent <CardDisplay>().card); if (desc.destinationCell.GetItem()) { GameManager.instance.player.deck.Remove(desc.destinationCell.GetItem().GetComponent <CardDisplay>().card); GameManager.instance.player.hand.Add(desc.destinationCell.GetItem().GetComponent <CardDisplay>().card); } } }
void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { Debug.Log("a"); if (desc.triggerType != DragAndDropCell.TriggerType.DropEventEnd) { return; } CardDisplay droppedCard = desc.item.GetComponent <CardDisplay> (); if (GameManager.instance.playerAction.canPlayCard(droppedCard.card)) { GameManager.instance.playerAction.useCard(droppedCard.card); GameManager.instance.player.hand.Remove(droppedCard.card); StartCoroutine(WaitAndDestroy(0.3f, droppedCard)); GameManager.instance.playerHand.Draw(); } else { List <GameObject> handSlots = GameManager.instance.playerHand.handSlots; Destroy(droppedCard.gameObject); GameObject.Find("ErrorSound").GetComponent <AudioSource>().Play(); for (int i = 0; i < handSlots.Count; i++) { CardDisplay[] cardsInSlot = handSlots[i].GetComponentsInChildren <CardDisplay>(); if (cardsInSlot.Length == 0) { CardDisplay cardDisplay = GameObject.Instantiate(GameManager.instance.playerHand.cardDisplayPrefab, handSlots[i].transform); cardDisplay.transform.localPosition = Vector3.zero; cardDisplay.card = droppedCard.card; cardDisplay.RenderCard(); return; } } } }
internal override void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { base.OnSimpleDragAndDropEvent(desc); if (desc != null && desc.triggerType == DragAndDropCell.TriggerType.DropEventEnd && desc.sourceCell != null) { var inventoryBehaviour = desc.sourceCell.GetComponentInParent <InventoryBehavior>(); inventoryBehaviour.UpdateSlots(); inventoryBehaviour.DisableButtons(); } if (desc.triggerType == DragAndDropCell.TriggerType.DropEventEnd) { //Debug.Log("check recipe database if crafting table has item."); tempRecipe = TryCraft(); SetCraftUI(tempRecipe); } }
/// <summary> /// Operate all drag and drop requests and events from children cells /// </summary> /// <param name="desc"> request or event descriptor </param> void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { // Get control unit of source cell DummyControlUnit sourceSheet = desc.sourceCell.GetComponentInParent <DummyControlUnit> (); // Get control unit of destination cell DummyControlUnit destinationSheet = desc.destinationCell.GetComponentInParent <DummyControlUnit> (); if (desc.triggerType == DragAndDropCell.TriggerType.DropEventEnd) { string destinationCellName = desc.destinationCell.ToString().Split(' ') [0]; string sourceCellName = desc.sourceCell.ToString().Split(' ') [0]; if (topicsToTilesMapping.ContainsKey(destinationCellName)) { if (topicsToTilesMapping[destinationCellName].Contains(sourceCellName)) { ScoreScript.scoreValue += int.Parse(bucketToScoreMapping[destinationCellName]); } else { ScoreScript.scoreValue -= 1; } } var destBucket = desc.destinationCell.gameObject; var gameObjectToDestroy = destBucket.transform.Find("img_" + sourceCellName); Destroy(gameObjectToDestroy.gameObject); if (bucketToOccupancyMapping[destinationCellName] < 5) { bucketToOccupancyMapping[destinationCellName] += 1; //increase the level fill of the bucket object[] sprites = Resources.LoadAll("bucket/incremental", typeof(Sprite)); Image imageComponent = destBucket.transform.GetChild(0).GetComponent <Image> (); imageComponent.sprite = (Sprite)sprites[bucketToOccupancyMapping[destinationCellName]]; } } }
void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc) { }