protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); if (surface != null) { if (surface.tag == Tags.Inventory_item_grid) //当拖放到了一个空的格子里面 { if (surface == this.transform.parent.gameObject) //拖放到了自己的格子里面 { } else { InventoryItemGrid oldParent = this.transform.parent.GetComponent <InventoryItemGrid> (); this.transform.parent = surface.transform; ResetPosition(); InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid> (); newParent.SetId(oldParent.id, oldParent.num); oldParent.ClearInfo(); } } else if (surface.tag == Tags.Inventory_item) //当拖放到了一个有物品的格子里面 { InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid> (); InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid> (); int id = grid1.id; int num = grid1.num; grid1.SetId(grid2.id, grid2.num); grid2.SetId(id, num); } } ResetPosition(); }
protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); if (surface != null) { if (surface.tag == Tags.inventoryItemGrid) { if (surface != this.transform.parent.gameObject) // 拖拽到空格子 { InventoryItemGrid oldGrid = this.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid newGrid = surface.GetComponent <InventoryItemGrid>(); newGrid.SetId(oldGrid.GetId(), oldGrid.GetNum()); oldGrid.ClearInfo(); } } else if (surface.tag == Tags.inventoryItem) // 拖拽到有物体的格子 { InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>(); int id = grid1.GetId(); int num = grid1.GetNum(); grid1.SetId(grid2.GetId(), grid2.GetNum()); grid2.SetId(id, num); } } ResetPos(); }
protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); Debug.Log(surface.tag); if (surface != null) { if (surface.tag == Tags.inventoryItemGrid) //当拖放到空格子里 { if (surface == transform.parent.gameObject) //当拖动到自己的格子里 { } else { InventoryItemGrid oldParent = transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>(); transform.parent = surface.transform; newParent.SetId(oldParent.id, oldParent.num); oldParent.ClearInfo(); //清空信息 } } else if (surface.tag == Tags.inventoryItem) //当拖放到有物品的格子里 { InventoryItemGrid grid1 = transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>(); int id = grid1.id; int num = grid1.num; grid1.SetId(grid2.id, grid2.num); grid2.SetId(id, num); } else if (surface.tag == Tags.shortCut) //当拖放到快捷栏时 { surface.GetComponent <ShortCutGrid>().SetInventory(id); } else //当拖放到空白的地方时 { } ResetPosition(); } else { ResetPosition(); } }
public void OnEndDrag(PointerEventData eventData) { transform.SetParent(originalParent); if (eventData.pointerCurrentRaycast.gameObject != null) { if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.Inventory_item_grid.ToString()) //当拖放到空格子中 { if (eventData.pointerCurrentRaycast.gameObject == originalParent.gameObject) //拖放到自己原本的格子中 { } else { InventoryItemGrid oldParent = originalParent.GetComponent <InventoryItemGrid>(); this.transform.parent = eventData.pointerCurrentRaycast.gameObject.transform; InventoryItemGrid newParent = eventData.pointerCurrentRaycast.gameObject.GetComponent <InventoryItemGrid>(); newParent.SetId(oldParent.id, oldParent.num); transform.localPosition = Vector3.zero; oldParent.ClearInfo(); } } else if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.Inventory_item.ToString())//拖放到一个有物品的格子里 { InventoryItemGrid gird1 = originalParent.GetComponent <InventoryItemGrid>(); InventoryItemGrid gird2 = eventData.pointerCurrentRaycast.gameObject.transform.parent.GetComponent <InventoryItemGrid>(); int id = gird1.id, num = gird1.num; gird1.SetId(gird2.id, gird2.num); gird2.SetId(id, num); } else if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.ShortCut.ToString()) { eventData.pointerCurrentRaycast.gameObject.GetComponent <ShortCutGird>().SetInventory(id); } } ResetPosition(); GetComponent <CanvasGroup>().blocksRaycasts = true; }
protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); if (surface != null) { if (surface.tag == Tags.inventory_item_grid) { InventoryItemGrid oldItemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid newItemGrid = surface.GetComponent <InventoryItemGrid>(); if (newItemGrid != oldItemGrid) { this.transform.parent = surface.transform; newItemGrid.SetId(oldItemGrid.id, oldItemGrid.currentNumb); oldItemGrid.ClearInfo(); } } else if (surface.tag == Tags.inventory_item) { InventoryItemGrid oldItemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid newItemGrid = surface.transform.parent.GetComponent <InventoryItemGrid>(); int tempId = newItemGrid.id; int tempNum = newItemGrid.currentNumb; newItemGrid.ClearInfo(); this.transform.parent = newItemGrid.gameObject.transform; newItemGrid.SetId(oldItemGrid.id, oldItemGrid.currentNumb); oldItemGrid.ClearInfo(); InventoryItem newItem = newItemGrid.GetComponentInChildren <InventoryItem>(); newItem.gameObject.transform.parent = oldItemGrid.gameObject.transform; oldItemGrid.SetId(tempId, tempNum); newItem.ResetPosition(); } else if (surface.tag == Tags.shortcut) { ShortcutGrid shortcutGrid = surface.GetComponent <ShortcutGrid>(); shortcutGrid.SetInventory(itemId); } isHover = false; } ResetPosition(); }
/// <summary> /// 添加到装备 /// </summary> void AddEquipment() { if (isPointEnter) { if (inventoryItemGrid.num > 0) { bool isAddEquip = equipment.SetId(id); if (isAddEquip) { inventoryItemGrid.AddNum(-1); if (inventoryItemGrid.num == 0) { Destroy(inventoryItemGo); inventoryItemGrid.ClearInfo(); labelUI.HideLabel(); isPointEnter = false; } } } } }
protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); if (surface != null) { // 拖放到空格子 if (surface.tag == Tags.inventory_item_grid) { // 拖放到自己的格子 if (surface == this.transform.parent.gameObject) { } else { InventoryItemGrid oldParent = transform.parent.GetComponent <InventoryItemGrid>(); this.transform.parent = surface.transform; InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>(); newParent.SetId(oldParent.id, oldParent.num); oldParent.ClearInfo(); } } else if (surface.tag == Tags.inventory_item) { InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>(); int id = grid1.id; int num = grid1.num; grid1.SetId(grid2.id, grid2.num); grid2.SetId(id, num); } else if (surface.tag == Tags.shortcut) { surface.GetComponent <ShortCutGrid>().SetInventory(id); } } ResetPosition(); }
//拖拽结束时调用 protected override void OnDragDropRelease(GameObject surface) { base.OnDragDropRelease(surface); if (surface != null) { //拖放到了空的格子里 if (surface.tag == Tags.inventory_item_grid) { //拖放到了自己的格子里 if (surface == this.transform.parent.gameObject) { } //拖放到了其它空的格子里 else { InventoryItemGrid oldParent = this.transform.parent.GetComponent <InventoryItemGrid>(); this.transform.parent = surface.transform; InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>(); newParent.SetId(oldParent.id, oldParent.num); oldParent.ClearInfo(); } } //拖放到了有物品的格子里 else if (surface.tag == Tags.inventory_item) { InventoryItemGrid thisParent = this.transform.parent.GetComponent <InventoryItemGrid>(); InventoryItemGrid surgaceParent = surface.transform.parent.GetComponent <InventoryItemGrid>(); int id = thisParent.id; int num = thisParent.num; thisParent.SetId(surgaceParent.id, surgaceParent.num); surgaceParent.SetId(id, num); } } ResetPosition(); }