Exemple #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;
        }
Exemple #2
0
 public void Unregister(SortableList sortableList)
 {
     if (m_sortableLists.Contains(sortableList))
     {
         m_sortableLists.Remove(sortableList);
         sortableList.OnListItemReleased += OnListItemReleased;
     }
 }
Exemple #3
0
 public void Register(SortableList sortableList)
 {
     if (!m_sortableLists.Contains(sortableList))
     {
         m_sortableLists.Add(sortableList);
         sortableList.OnListItemPressed += OnListItemPressed;
     }
 }
Exemple #4
0
 private void OnListItemReleased(SortableList SortableList, SortableListItem sortableListItem)
 {
     m_sourceList     = null;
     m_draggedItem    = null;
     m_dragPrepping   = false;
     m_pressTime0     = 0;
     m_pressPosition0 = Vector3.zero;
 }
Exemple #5
0
 private void OnListItemPressed(SortableList sortableList, SortableListItem sortableListItem)
 {
     m_sourceList      = sortableList;
     m_draggedItem     = sortableListItem;
     m_sourceItemIndex = m_draggedItem.transform.GetSiblingIndex();
     m_dragPrepping    = true;
     m_pressTime0      = Time.time;
     m_pressPosition0  = Input.mousePosition;
 }
Exemple #6
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();
        }