示例#1
0
        /// <summary>
        /// Raises the begin drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnBeginDrag(PointerEventData eventData)
        {
            Vector2 point;

            processDrag = false;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.pressPosition, eventData.pressEventCamera, out point))
            {
                return;
            }

            var index = transform.GetSiblingIndex();

            if (index == 0 || transform.parent.childCount == (index + 1))
            {
                return;
            }

            Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());
            cursorChanged = true;

            processDrag = true;

            if (mode == SplitterMode.Auto)
            {
                leftTarget  = transform.parent.GetChild(index - 1) as RectTransform;
                rightTarget = transform.parent.GetChild(index + 1) as RectTransform;
            }

            LeftTargetElement.preferredWidth  = leftTarget.rect.width;
            LeftTargetElement.preferredHeight = leftTarget.rect.height;

            RightTargetElement.preferredWidth  = rightTarget.rect.width;
            RightTargetElement.preferredHeight = rightTarget.rect.height;

            summarySize = new Vector2(leftTarget.rect.width + rightTarget.rect.width, leftTarget.rect.height + rightTarget.rect.height);

            OnStartResize.Invoke(this);
        }
示例#2
0
        /// <summary>
        /// Called by a BaseInputModule when a drag is ended.
        /// </summary>
        /// <param name="eventData">Current event data.</param>
        public virtual void OnEndDrag(PointerEventData eventData)
        {
            if (!IsDragged)
            {
                return;
            }

            var target = FindTarget(eventData);

            if (target != null)
            {
                target.Drop(Data, eventData);
                Dropped(true);
            }
            else
            {
                Dropped(false);
            }

            IsDragged = false;
            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Utilites.GetCursorMode());
        }
示例#3
0
        /// <summary>
        /// Update cursor.
        /// </summary>
        protected virtual void LateUpdate()
        {
            if (!IsCursorOver)
            {
                return;
            }
            if (processDrag)
            {
                return;
            }
            if (CursorTexture == null)
            {
                return;
            }
            if (!Input.mousePresent)
            {
                return;
            }

            Vector2 point;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, Input.mousePosition, CurrentCamera, out point))
            {
                return;
            }

            var rect = RectTransform.rect;

            if (rect.Contains(point))
            {
                cursorChanged = true;
                Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());
            }
            else if (cursorChanged)
            {
                cursorChanged = false;
                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Utilites.GetCursorMode());
            }
        }
示例#4
0
        /// <summary>
        /// Raises the drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnDrag(PointerEventData eventData)
        {
            if (!processDrag)
            {
                return;
            }
            if (canvas == null)
            {
                throw new MissingComponentException(gameObject.name + " not in Canvas hierarchy.");
            }
            Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());

            Vector2 p1;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position, CurrentCamera, out p1);
            Vector2 p2;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position - eventData.delta, CurrentCamera, out p2);
            var delta = p1 - p2;

            if (delta.x > 0)
            {
                leftTarget.preferredWidth  = Mathf.Min(leftTarget.preferredWidth + delta.x, widthLimit - rightTarget.minWidth);
                rightTarget.preferredWidth = widthLimit - leftTarget.preferredWidth;
            }
            else
            {
                rightTarget.preferredWidth = Mathf.Min(rightTarget.preferredWidth - delta.x, widthLimit - leftTarget.minWidth);
                leftTarget.preferredWidth  = widthLimit - rightTarget.preferredWidth;
            }

            LayoutUtilites.UpdateLayout(layout);

            if (OnDragUpdate)
            {
                Resize();
            }
        }
示例#5
0
        void LateUpdate()
        {
            if (processDrag)
            {
                return;
            }
            if (CursorTexture == null)
            {
                return;
            }
            if (!Input.mousePresent)
            {
                return;
            }

            Vector2 point;
            bool    in_draggable_region = false;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, Input.mousePosition, CurrentCamera, out point))
            {
                return;
            }
            var rect = RectTransform.rect;

            if (!rect.Contains(point))
            {
                return;
            }

            point += new Vector2(rect.width * RectTransform.pivot.x, 0);

            int i = 0;

            foreach (var child in children)
            {
                var is_first = i == 0;
                if (!is_first)
                {
                    in_draggable_region = CheckLeft(child, point);
                    if (in_draggable_region)
                    {
                        break;
                    }
                }
                var is_last = i == (children.Count - 1);
                if (!is_last)
                {
                    in_draggable_region = CheckRight(child, point);
                    if (in_draggable_region)
                    {
                        break;
                    }
                }

                i++;
            }

            if (in_draggable_region)
            {
                Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());
            }
            else
            {
                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Utilites.GetCursorMode());
            }
        }