|
|
- public void OnEndDrag(PointerEventData eventData)
- {
- inventoryUI.dragItem.enabled = false;
- if (eventData.pointerCurrentRaycast.gameObject != null)
- {
- // 原有 UI 交换逻辑
- SlotUI targetSlot = eventData.pointerCurrentRaycast.gameObject.GetComponent<SlotUI>();
- if (targetSlot == null) return;
- int targetIndex = targetSlot.slotIndex;
- if (slotType == SlotType.Bag && targetSlot.slotType == SlotType.Bag)
- {
- InventoryManager.Instance.SwapItem(slotIndex, targetIndex);
- }
- inventoryUI.UpdateSlotHighLight(targetIndex);
- }
- else
- {
- // ----- 丢弃到场景逻辑 -----
- if (!itemDetails.canDropped)
- {
- Debug.Log("该物品无法丢弃");
- return;
- }
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- // 只检测 Ground 层(可换成你定义的地面层)
- int layerMask = 1 << LayerMask.NameToLayer("Ground");
- if (Physics.Raycast(ray, out hit, 100f, layerMask))
- {
- // 检查是否为禁止丢弃区域
- if (hit.collider.CompareTag("NoDrop"))
- {
- Debug.Log("此区域禁止丢弃");
- return;
- }
- // 生成物品
- Vector3 spawnPos = hit.point + Vector3.up * 0.5f;
- EventHandler.CallInstantiateItemInScene(itemDetails.itemID, spawnPos);
- }
- else
- {
- Debug.Log("没有地面可以放置物品");
- }
- }
- }
复制代码
|
|