public DragState(WorkspaceUI workspaceUI, Transform rayOrigin, bool resizing) { m_WorkspaceUI = workspaceUI; m_Resizing = resizing; this.rayOrigin = rayOrigin; if (resizing) { var pointerPosition = m_WorkspaceUI.GetPointerPosition(rayOrigin); m_DragStart = pointerPosition; m_PositionStart = workspaceUI.transform.parent.position; m_BoundsSizeStart = workspaceUI.bounds.size; var localPosition = m_WorkspaceUI.transform.InverseTransformPoint(pointerPosition); m_Direction = m_WorkspaceUI.GetResizeDirectionForLocalPosition(localPosition); } else { MathUtilsExt.GetTransformOffset(rayOrigin, m_WorkspaceUI.transform.parent, out m_PositionOffset, out m_RotationOffset); } }
public void OnDragging() { if (m_Resizing) { var viewerScale = m_WorkspaceUI.GetViewerScale(); var pointerPosition = m_WorkspaceUI.GetPointerPosition(rayOrigin); var dragVector = (pointerPosition - m_DragStart) / viewerScale; var bounds = m_WorkspaceUI.bounds; var transform = m_WorkspaceUI.transform; var positionOffsetForward = Vector3.Dot(dragVector, transform.forward) * 0.5f; var positionOffsetRight = Vector3.Dot(dragVector, transform.right) * 0.5f; switch (m_Direction) { default: bounds.size = m_BoundsSizeStart + Vector3.back * Vector3.Dot(dragVector, transform.forward); positionOffsetRight = 0; break; case ResizeDirection.Back: bounds.size = m_BoundsSizeStart + Vector3.forward * Vector3.Dot(dragVector, transform.forward); positionOffsetRight = 0; break; case ResizeDirection.Left: bounds.size = m_BoundsSizeStart + Vector3.left * Vector3.Dot(dragVector, transform.right); positionOffsetForward = 0; break; case ResizeDirection.Right: bounds.size = m_BoundsSizeStart + Vector3.right * Vector3.Dot(dragVector, transform.right); positionOffsetForward = 0; break; case ResizeDirection.Front | ResizeDirection.Left: bounds.size = m_BoundsSizeStart + Vector3.left * Vector3.Dot(dragVector, transform.right) + Vector3.back * Vector3.Dot(dragVector, transform.forward); break; case ResizeDirection.Front | ResizeDirection.Right: bounds.size = m_BoundsSizeStart + Vector3.right * Vector3.Dot(dragVector, transform.right) + Vector3.back * Vector3.Dot(dragVector, transform.forward); break; case ResizeDirection.Back | ResizeDirection.Left: bounds.size = m_BoundsSizeStart + Vector3.left * Vector3.Dot(dragVector, transform.right) + Vector3.forward * Vector3.Dot(dragVector, transform.forward); break; case ResizeDirection.Back | ResizeDirection.Right: bounds.size = m_BoundsSizeStart + Vector3.right * Vector3.Dot(dragVector, transform.right) + Vector3.forward * Vector3.Dot(dragVector, transform.forward); break; } if (m_WorkspaceUI.resize != null) { m_WorkspaceUI.resize(bounds); } var currentExtents = m_WorkspaceUI.bounds.extents; var extents = bounds.extents; var absRight = Mathf.Abs(positionOffsetRight); var absForward = Mathf.Abs(positionOffsetForward); var positionOffset = (absRight - (currentExtents.x - extents.x)) * Mathf.Sign(positionOffsetRight) * transform.right + (absForward - (currentExtents.z - extents.z)) * Mathf.Sign(positionOffsetForward) * transform.forward; m_WorkspaceUI.transform.parent.position = m_PositionStart + positionOffset * viewerScale; m_WorkspaceUI.OnResizing(rayOrigin); } else { MathUtilsExt.SetTransformOffset(rayOrigin, m_WorkspaceUI.transform.parent, m_PositionOffset, m_RotationOffset); m_WorkspaceUI.OnMoving(rayOrigin); } }