/// <summary> /// Checks is can drag any item or if can show UI /// </summary> /// <param name="ray"></param> private void CheckIfCanDrag(Ray ray) { RaycastHit hit; if (Physics.Raycast(ray, out hit, maxRayDistance, draggableLayerMask)) { draggingObject = hit.transform.GetComponent <IDraggable>(); if (draggingObject != null && draggingObject.CanDrag()) { isMouseDragging = true; draggingObject.OnDragEvent(isMouseDragging); draggingTransform = hit.transform; originalPosition = draggingTransform.position; positionOfScreen = renderCamera.WorldToScreenPoint(originalPosition); offsetValue = originalPosition - renderCamera.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionOfScreen.z)); } } if (Physics.Raycast(ray, out hit, maxRayDistance, inventoryLayerMask) && !isMouseDragging) { bagUI = hit.transform.GetComponent <IInventoryUICheckable>(); if (bagUI != null) { bagUI.ShowUI(); isCheckingUI = true; } } }
private void ReleaseDraggingItem() { isMouseDragging = false; draggingObject?.SetOriginalPosition(originalPosition); if (isOverBag) { if (draggingTransform != null) { var bagThrowable = draggingTransform.GetComponent <IBagThrowable>(); bagThrowable?.PutInBag(); } } else { draggingObject?.OnDragEvent(isMouseDragging); } draggingTransform = null; }