Ejemplo n.º 1
0
        /// <summary>
        /// Fires on mouse drag
        /// </summary>
        /// <param name="data">Event data</param>
        public void OnDrag(PointerEventData data)
        {
            //Resize
            RectTransformUtility.ScreenPointToLocalPointInRectangle(this.panelTransform, data.position, data.pressEventCamera, out Vector2 localMousePos);
            Vector2 offset    = localMousePos - this.originalMousePos;
            Vector2 sizeDelta = this.originalSizeDelta + new Vector2(offset.x, -offset.y);

            sizeDelta = DESUtils.ClampVector2(sizeDelta, this.min, this.max);

            //Make sure we're not outside of the draw zone
            Vector2 pos          = this.panelTransform.localPosition;
            Vector2 bounds       = new Vector2(this.parentTransform.rect.max.x - this.panelTransform.rect.max.x, this.parentTransform.rect.min.y - this.panelTransform.rect.min.y) - offset;
            Vector2 currentDelta = this.panelTransform.sizeDelta;

            this.panelTransform.sizeDelta = new Vector2(pos.x > bounds.x ? currentDelta.x : sizeDelta.x, pos.y < bounds.y ? currentDelta.y : sizeDelta.y);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fires on mouse drag
        /// </summary>
        /// <param name="data">Event data</param>
        public void OnDrag(PointerEventData data)
        {
            //Move window
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.parentTransform, data.position, data.pressEventCamera, out Vector2 mousePos))
            {
                Vector2 offset = mousePos - this.originalMousePos;
                this.panelTransform.localPosition = this.originalPanelPos + offset;
            }

            //Clamp window
            Vector2 pos    = this.panelTransform.localPosition;
            Vector2 minPos = this.parentTransform.rect.min - this.panelTransform.rect.min;
            Vector2 maxPos = this.parentTransform.rect.max - this.panelTransform.rect.max;

            this.panelTransform.localPosition = DESUtils.ClampVector2(pos, minPos, maxPos);
        }