Exemplo n.º 1
0
 /// <summary>
 /// Updates the cursor.
 /// </summary>
 protected virtual void UpdateCursor()
 {
     if ((regions.NW && ResizeDirections.TopLeft) || (regions.SE && ResizeDirections.BottomRight))
     {
         globalCursorSetted = true;
         cursorChanged      = true;
         Cursor.SetCursor(CursorNWSETexture, CursorNWSEHotSpot, Compatibility.GetCursorMode());
     }
     else if ((regions.NE && ResizeDirections.TopRight) || (regions.SW && ResizeDirections.BottomLeft))
     {
         globalCursorSetted = true;
         cursorChanged      = true;
         Cursor.SetCursor(CursorNESWTexture, CursorNESWHotSpot, Compatibility.GetCursorMode());
     }
     else if ((regions.Top && ResizeDirections.Top) || (regions.Bottom && ResizeDirections.Bottom))
     {
         globalCursorSetted = true;
         cursorChanged      = true;
         Cursor.SetCursor(CursorNSTexture, CursorNSHotSpot, Compatibility.GetCursorMode());
     }
     else if ((regions.Left && ResizeDirections.Left) || (regions.Right && ResizeDirections.Right))
     {
         globalCursorSetted = true;
         cursorChanged      = true;
         Cursor.SetCursor(CursorEWTexture, CursorEWHotSpot, Compatibility.GetCursorMode());
     }
     else if (cursorChanged)
     {
         ResetCursor();
     }
 }
Exemplo n.º 2
0
        void ResetCursor()
        {
            globalCursorSetted = false;
            cursorChanged      = false;

            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called by a BaseInputModule when an OnPointerExit event occurs.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnPointerExit(PointerEventData eventData)
        {
            IsCursorOver = false;

            cursorChanged = false;
            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
        }
Exemplo n.º 4
0
        /// <summary>
        /// When dragging is occurring this will be called every time the cursor is moved.
        /// </summary>
        /// <param name="eventData">Current event data.</param>
        public virtual void OnDrag(PointerEventData eventData)
        {
            if (!IsDragged)
            {
                return;
            }

            oldTarget = currentTarget;

            currentTarget = FindTarget(eventData);
            if ((oldTarget != null) && (currentTarget != oldTarget))
            {
                oldTarget.DropCanceled(Data, eventData);
            }

            if (currentTarget != null)
            {
                // set cursor can drop
                Cursor.SetCursor(AllowDropCursor, AllowDropCursorHotSpot, Compatibility.GetCursorMode());
            }
            else
            {
                // set cursor fail drop
                Cursor.SetCursor(DeniedDropCursor, DeniedDropCursorHotSpot, Compatibility.GetCursorMode());
            }

            Vector2 point;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(CanvasTransform as RectTransform, Input.mousePosition, eventData.pressEventCamera, out point))
            {
                return;
            }

            DragPoint.localPosition = point;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update cursors.
        /// </summary>
        protected virtual void LateUpdate()
        {
            if (!AllowResize)
            {
                return;
            }

            if (!IsCursorOver)
            {
                return;
            }

            if (processDrag || ProcessCellReorder)
            {
                return;
            }

            if ((CursorTexture == null) || (!Input.mousePresent))
            {
                return;
            }

            if (InActiveRegion)
            {
                Cursor.SetCursor(CursorTexture, CursorHotSpot, Compatibility.GetCursorMode());
                cursorChanged = true;
            }
            else if (cursorChanged)
            {
                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
                cursorChanged = false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Process OnEndDrag event.
        /// </summary>
        /// <param name="eventData">Current event data.</param>
        protected virtual void OnEndDrag(PointerEventData eventData)
        {
            if (!IsDragged)
            {
                return;
            }

            FindCurrentTarget(eventData);

            if (CurrentTarget != null)
            {
                CurrentTarget.Drop(Data, eventData);

                Dropped(true);
            }
            else
            {
                Dropped(false);
            }

            IsDragged = false;

            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());

            EndDragEvent.Invoke();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find current target.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        protected virtual void FindCurrentTarget(PointerEventData eventData)
        {
            var new_target = FindTarget(eventData);

            if (new_target != CurrentTarget)
            {
                if (CurrentTarget != null)
                {
                    CurrentTarget.DropCanceled(Data, eventData);
                }

                OnTargetChanged(CurrentTarget, new_target);
            }

            if (new_target != null)
            {
                // set cursor can drop
                Cursor.SetCursor(AllowDropCursor, AllowDropCursorHotSpot, Compatibility.GetCursorMode());
            }
            else
            {
                // set cursor fail drop
                Cursor.SetCursor(DeniedDropCursor, DeniedDropCursorHotSpot, Compatibility.GetCursorMode());
            }

            CurrentTarget = new_target;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Raises the end drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnEndDrag(PointerEventData eventData)
        {
            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
            cursorChanged = false;

            processDrag = false;

            OnEndResize.Invoke(this);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Process OnDisable event.
        /// </summary>
        protected virtual void OnDisable()
        {
            if (IsDragged)
            {
                if (Owner != null)
                {
                    Owner.StopAutoScroll();
                }

                Dropped(false);

                IsDragged = false;

                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Raises the end drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnEndDrag(PointerEventData eventData)
        {
            if (!processDrag)
            {
                return;
            }

            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());

            ResetChildren();
            if (!OnDragUpdate)
            {
                Resize();
            }

            processDrag = false;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Process the cancel event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnCancel(BaseEventData eventData)
        {
            if (!IsDragged)
            {
                return;
            }

            if (currentTarget != null)
            {
                currentTarget.DropCanceled(Data, null);
            }

            Dropped(false);

            IsDragged = false;
            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
        }
Exemplo n.º 12
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, Compatibility.GetCursorMode());
            }
            else if (cursorChanged)
            {
                cursorChanged = false;
                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Compatibility.GetCursorMode());
            }
        }
Exemplo n.º 13
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, Compatibility.GetCursorMode());

            Vector2 p1;

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

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position - eventData.delta, GetCamera(), 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();
            }
        }
Exemplo n.º 14
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, Compatibility.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);
        }
Exemplo n.º 15
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, Compatibility.GetCursorMode());
        }