static public int get_IsDraggable(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         pushValue(l, self.IsDraggable);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_IsDraggable(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         System.Boolean v;
         checkType(l, 2, out v);
         self.IsDraggable = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int TestReOrderableListTarget(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         UnityEngine.UI.Extensions.ReorderableList.ReorderableListEventStruct a1;
         checkValueType(l, 2, out a1);
         self.TestReOrderableListTarget(a1);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_ContentLayout(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         UnityEngine.UI.LayoutGroup v;
         checkType(l, 2, out v);
         self.ContentLayout = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_DraggableArea(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         UnityEngine.RectTransform v;
         checkType(l, 2, out v);
         self.DraggableArea = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_OnElementRemoved(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.ReorderableList self = (UnityEngine.UI.Extensions.ReorderableList)checkSelf(l);
         UnityEngine.UI.Extensions.ReorderableList.ReorderableListHandler v;
         checkType(l, 2, out v);
         self.OnElementRemoved = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #7
0
 public void Init(ReorderableList reorderableList)
 {
     _reorderableList = reorderableList;
     _rect            = GetComponent <RectTransform>();
 }
Пример #8
0
        public void OnDrag(PointerEventData eventData)
        {
            if (!_isDragging)
            {
                return;
            }
            if (!isValid)
            {
                CancelDrag();
                return;
            }
            //Set dragging object on cursor
            var     canvas = _draggingObject.GetComponentInParent <Canvas>();
            Vector3 worldPoint;

            RectTransformUtility.ScreenPointToWorldPointInRectangle(canvas.GetComponent <RectTransform>(), eventData.position,
                                                                    canvas.worldCamera, out worldPoint);
            _draggingObject.position = worldPoint;

            //Check everything under the cursor to find a ReorderableList
            EventSystem.current.RaycastAll(eventData, _raycastResults);
            for (int i = 0; i < _raycastResults.Count; i++)
            {
                _currentReorderableListRaycasted = _raycastResults[i].gameObject.GetComponent <ReorderableList>();
                if (_currentReorderableListRaycasted != null)
                {
                    break;
                }
            }

            //If nothing found or the list is not dropable, put the fake element outsite
            if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false)
            {
                RefreshSizes();
                _fakeElement.transform.SetParent(_reorderableList.DraggableArea, false);
            }
            //Else find the best position on the list and put fake element on the right index
            else
            {
                if (_fakeElement.parent != _currentReorderableListRaycasted)
                {
                    _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false);
                }

                float minDistance = float.PositiveInfinity;
                int   targetIndex = 0;
                float dist        = 0;
                for (int j = 0; j < _currentReorderableListRaycasted.Content.childCount; j++)
                {
                    var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent <RectTransform>();

                    if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.y - worldPoint.y);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.x - worldPoint.x);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup)
                    {
                        dist = (Mathf.Abs(c.position.x - worldPoint.x) + Mathf.Abs(c.position.y - worldPoint.y));
                    }

                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        targetIndex = j;
                    }
                }

                RefreshSizes();
                _fakeElement.SetSiblingIndex(targetIndex);
                _fakeElement.gameObject.SetActive(true);
            }
        }
 public void Init(ReorderableList reorderableList)
 {
     _reorderableList = reorderableList;
     _rect            = GetComponent <RectTransform>();
     _canvasGroup     = gameObject.GetOrAddComponent <CanvasGroup>();
 }
        public void OnDrag(PointerEventData eventData)
        {
            if (!_isDragging)
            {
                return;
            }
            if (!isValid)
            {
                CancelDrag();
                return;
            }
            //Set dragging object on cursor
            var     canvas = _draggingObject.GetComponentInParent <Canvas>();
            Vector3 worldPoint;

            RectTransformUtility.ScreenPointToWorldPointInRectangle(canvas.GetComponent <RectTransform>(), eventData.position,
                                                                    canvas.renderMode != RenderMode.ScreenSpaceOverlay ? canvas.worldCamera : null, out worldPoint);
            _draggingObject.position = worldPoint;

            ReorderableList _oldReorderableListRaycasted = _currentReorderableListRaycasted;

            //Check everything under the cursor to find a ReorderableList
            EventSystem.current.RaycastAll(eventData, _raycastResults);
            for (int i = 0; i < _raycastResults.Count; i++)
            {
                _currentReorderableListRaycasted = _raycastResults[i].gameObject.GetComponent <ReorderableList>();
                if (_currentReorderableListRaycasted != null)
                {
                    break;
                }
            }

            //If nothing found or the list is not dropable, put the fake element outside
            if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false ||
                (_oldReorderableListRaycasted != _reorderableList && !IsTransferable) ||
                ((_fakeElement.parent == _currentReorderableListRaycasted.Content
                    ? _currentReorderableListRaycasted.Content.childCount - 1
                    : _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable) ||
                _currentReorderableListRaycasted.maxItems <= 0)
            {
                RefreshSizes();
                _fakeElement.transform.SetParent(_reorderableList.DraggableArea, false);
                // revert the displaced element when not hovering over its list
                if (_displacedObject != null)
                {
                    revertDisplacedElement();
                }
            }
            //Else find the best position on the list and put fake element on the right index
            else
            {
                if (_currentReorderableListRaycasted.Content.childCount < _currentReorderableListRaycasted.maxItems && _fakeElement.parent != _currentReorderableListRaycasted.Content)
                {
                    _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false);
                }

                float minDistance = float.PositiveInfinity;
                int   targetIndex = 0;
                float dist        = 0;
                for (int j = 0; j < _currentReorderableListRaycasted.Content.childCount; j++)
                {
                    var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent <RectTransform>();

                    if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.y - worldPoint.y);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.x - worldPoint.x);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup)
                    {
                        dist = (Mathf.Abs(c.position.x - worldPoint.x) + Mathf.Abs(c.position.y - worldPoint.y));
                    }

                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        targetIndex = j;
                    }
                }
                if ((_currentReorderableListRaycasted != _oldReorderableListRaycasted || targetIndex != _displacedFromIndex) &&
                    _currentReorderableListRaycasted.Content.childCount == _currentReorderableListRaycasted.maxItems)
                {
                    Transform toDisplace = _currentReorderableListRaycasted.Content.GetChild(targetIndex);
                    if (_displacedObject != null)
                    {
                        revertDisplacedElement();
                        if (_currentReorderableListRaycasted.Content.childCount > _currentReorderableListRaycasted.maxItems)
                        {
                            displaceElement(targetIndex, toDisplace);
                        }
                    }
                    else if (_fakeElement.parent != _currentReorderableListRaycasted.Content)
                    {
                        _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false);
                        displaceElement(targetIndex, toDisplace);
                    }
                }
                RefreshSizes();
                _fakeElement.SetSiblingIndex(targetIndex);
                _fakeElement.gameObject.SetActive(true);
            }
        }