Пример #1
0
        /// <summary>
        /// Fires on mouse drag
        /// </summary>
        /// <param name="data">Event data</param>
        public void OnDrag(PointerEventData data)
        {
            //Move window
            Vector2 mousePos;

            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.parentTransform, data.position, data.pressEventCamera, out 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 = CSUtils.ClampVector2(pos, minPos, maxPos);
        }
Пример #2
0
        /// <summary>
        /// Fires on mouse drag
        /// </summary>
        /// <param name="data">Event data</param>
        public void OnDrag(PointerEventData data)
        {
            //Resize
            Vector2 localMousePos;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(this.panelTransform, data.position, data.pressEventCamera, out localMousePos);
            Vector2 offset    = localMousePos - this.originalMousePos;
            Vector2 sizeDelta = this.originalSizeDelta + new Vector2(offset.x, -offset.y);

            sizeDelta = CSUtils.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);
        }