Exemple #1
0
        /// <summary>
        /// Creates the dragging image.
        /// </summary>
        /// <returns>The dragging image.</returns>
        /// <param name="eventData">Pointer data.</param>
        public IEnumerator CreateDraggingImage(PointerEventData eventData)
        {
            DebugEx.VerboseFormat("DockingTabButton.CreateDraggingImage(eventData = {0})", eventData);

            yield return(new WaitForEndOfFrame());

            Vector3[] corners = Utils.GetWindowCorners(mDockWidget.parent.transform as RectTransform);

            float screenWidth  = Screen.width;
            float screenHeight = Screen.height;

            float left   = corners[0].x * Utils.canvasScale;
            float top    = corners[0].y * Utils.canvasScale;
            float right  = corners[3].x * Utils.canvasScale;
            float bottom = corners[3].y * Utils.canvasScale;

            if (left < 0f)
            {
                left = 0f;
            }

            if (top < 0f)
            {
                top = 0f;
            }

            if (right > screenWidth - 1)
            {
                right = screenWidth - 1;
            }

            if (bottom > screenHeight - 1)
            {
                bottom = screenHeight - 1;
            }

            int widgetX      = Mathf.CeilToInt(left);
            int widgetY      = Mathf.CeilToInt(top);
            int widgetWidth  = Mathf.FloorToInt(right - left);
            int widgetHeight = Mathf.FloorToInt(bottom - top);

            float dragPosX = (eventData.pressPosition.x - widgetX) / Utils.canvasScale;
            float dragPosY = (screenHeight - eventData.pressPosition.y - widgetY) / Utils.canvasScale;

            DragData.BeginDrag(
                DraggingType.DockWidget
                , gameObject
                , Sprite.Create(
                    Utils.TakeScreenshot(widgetX, widgetY, widgetWidth, widgetHeight)
                    , new Rect(0, 0, widgetWidth, widgetHeight)
                    , new Vector2(0.5f, 0.5f)
                    )
                , widgetWidth / Utils.canvasScale
                , widgetHeight / Utils.canvasScale
                , dragPosX
                , dragPosY
                );
        }