示例#1
0
        private void DetectDragStart()
        {
            if (!Input.GetKeyDown(KeyCode.Mouse0))
            {
                return;
            }

            //in case drag end wasn't called properly
            if (m_pointerTarget != null)
            {
                m_pointerTarget?.OnEndDrag(m_eventData);
                m_pointerTarget = null;
            }

            m_previousPointerPosition = Input.mousePosition;
            foreach (var hit in m_raycastResults)
            {
                if (hit.gameObject.TryGetComponent <DragArea>(out var target))
                {
                    if (target == null)
                    {
                        continue;
                    }

                    UpdateEventData(target.gameObject);
                    m_eventData.PointerBegin = Input.mousePosition;

                    m_pointerTarget = target.TargetWindow;
                    m_pointerTarget.OnBeginDrag(m_eventData);
                    m_pointerTarget.transform.SetAsLastSibling();

                    break;
                }
            }

            OnDrag?.Invoke();
        }
示例#2
0
 public void CollideWith(DragWindow window)
 {
     RectTransform.position = m_previousPosition;
 }