/// <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 Update() { Ray ray = renderCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxRayDistance, draggableLayerMask)) { draggingObject = hit.transform.GetComponent <IDraggable>(); if (draggingObject != null && draggingObject.CanDrag()) { draggingObject.HightlightAvailableForDrag(); } } if (Input.GetMouseButtonDown(0)) { CheckIfCanDrag(ray); } if (Input.GetMouseButtonUp(0)) { if (isMouseDragging) { ReleaseDraggingItem(); } else { ReleaseBagUI(); } } if (isMouseDragging && draggingObject != null) { DragItem(ray); } }