Exemplo n.º 1
0
        private void AttachDraggedItem()
        {
            int          itemIndex    = m_targetItemIndex;
            SortableList sortableList = m_targetList;

            if (!sortableList)
            {
                sortableList = m_sourceList;
            }

            if (m_targetList == null)
            {
                m_targetList = m_sourceList;
                itemIndex    = m_sourceItemIndex;
            }

            m_targetList.DetachItem(m_mockItem, m_targetList.canvas.transform);
            m_mockItem.gameObject.SetActive(false);

            sortableList.AttachItem(m_draggedItem, itemIndex);

            m_draggedItem     = null;
            m_targetList      = null;
            m_targetItemIndex = -1;
            m_sourceList      = null;
            m_sourceItemIndex = -1;
        }
Exemplo n.º 2
0
 private void StartDragging()
 {
     if (!m_sourceList)
     {
         return;
     }
     m_dragActivated = true;
     m_dragPrepping  = false;
     ToggleScrollLock(true);
     m_sourceList.DetachItem(m_draggedItem, m_sourceList.canvas.transform);
 }
Exemplo n.º 3
0
        private void UpdateActiveList()
        {
            if (m_dragActivated == false)
            {
                return;
            }
            if (m_draggedItem == null)
            {
                return;
            }

            bool activeList = false;

            foreach (SortableList sortableList in m_sortableLists)
            {
                if (IsMouseOverRectTransform(sortableList.transform as RectTransform))
                {
                    bool listChanged = m_targetList != sortableList;
                    activeList   = true;
                    m_targetList = sortableList;
                    if (listChanged)
                    {
                        CacheListItemCorners();
                    }
                    break;
                }
            }

            if (m_targetList == null)
            {
                return;
            }

            m_mockItem.gameObject.SetActive(true);
            if (m_mockItem == null || m_mockItem.layoutElement == null)
            {
                return;
            }

            int prevIndex    = m_targetItemIndex;
            int itemNewIndex = 0;

            foreach (Rect rect in m_cornersList)
            {
                if (IsMouseOverRect(rect))
                {
                    break;
                }
                itemNewIndex++;
            }

            m_mockItem.layoutElement.minWidth        = m_draggedItem.layoutElement.minWidth;
            m_mockItem.layoutElement.minHeight       = m_draggedItem.layoutElement.minHeight;
            m_mockItem.layoutElement.preferredWidth  = m_draggedItem.layoutElement.preferredWidth;
            m_mockItem.layoutElement.preferredHeight = m_draggedItem.layoutElement.preferredHeight;

            m_targetItemIndex = itemNewIndex;
            if (!activeList)
            {
                m_targetItemIndex = m_sourceItemIndex;
                m_targetList      = m_sourceList;
                m_targetList.DetachItem(m_mockItem, m_targetList.canvas.transform);
                m_targetList = null;
                return;
            }

            //if (prevIndex == m_targetItemIndex) return;
            m_targetList.AttachItem(m_mockItem, m_targetItemIndex);
            m_sourceList.UpdateContentSize();
        }