當前位置: 首頁>>代碼示例>>C#>>正文


C# RectTransform.GetWorldRect方法代碼示例

本文整理匯總了C#中UnityEngine.RectTransform.GetWorldRect方法的典型用法代碼示例。如果您正苦於以下問題:C# RectTransform.GetWorldRect方法的具體用法?C# RectTransform.GetWorldRect怎麽用?C# RectTransform.GetWorldRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.RectTransform的用法示例。


在下文中一共展示了RectTransform.GetWorldRect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BoundRectTransform

    public static void BoundRectTransform(RectTransform bounded,
        RectTransform bounds,
        RectTransform extent=null)
    {
        extent = extent ?? bounded; // allow you to bound less than the whole assembly

        // work in world space because it's easier
        var extentRect = extent.GetWorldRect();
        var boundsRect = bounds.GetWorldRect();

        // push the tooltip rect into the division
        float pushR = Mathf.Max(0f, boundsRect.xMin - extentRect.xMin);
        float pushU = Mathf.Max(0f, boundsRect.yMin - extentRect.yMin);

        float pushL = Mathf.Min(0f, boundsRect.xMax - extentRect.xMax);
        float pushD = Mathf.Min(0f, boundsRect.yMax - extentRect.yMax);

        var push = new Vector2(pushL + pushR, pushU + pushD);

        bounded.position += (Vector3) push;
    }
開發者ID:Ragzouken,項目名稱:kooltool-rekindle,代碼行數:21,代碼來源:UIExtensions.cs

示例2: RepositionTooltip

    /// <summary>
    /// Reposition the tooltip so that it is within the bounds but not within
    /// the source
    /// </summary>
    public static void RepositionTooltip(RectTransform tooltip,
        RectTransform source,
        RectTransform bounds,
        RectTransform extent=null,
        TooltipBias bias=TooltipBias.Down)
    {
        Vector3 position = source.GetWorldRect().center;
        position.z = tooltip.position.z;

        tooltip.position = position;

        extent = extent ?? tooltip; // allow you to bound less than the whole assembly

        // work in world space because it's easier
        var extentRect = extent.GetWorldRect();
        var sourceRect = source.GetWorldRect();
        var boundsRect = bounds.GetWorldRect();

        // divide the bounds into four overlapping rectangles on each side of
        // the source rect
        var xMinRect = Rect.MinMaxRect(boundsRect.xMin, boundsRect.yMin,
                                       sourceRect.xMin, boundsRect.yMax);
        var yMinRect = Rect.MinMaxRect(boundsRect.xMin, boundsRect.yMin,
                                       boundsRect.xMax, sourceRect.yMin);
        var xMaxRect = Rect.MinMaxRect(sourceRect.xMax, boundsRect.yMin,
                                       boundsRect.xMax, boundsRect.yMax);
        var yMaxRect = Rect.MinMaxRect(boundsRect.xMin, sourceRect.yMax,
                                       boundsRect.xMax, boundsRect.yMax);

        Rect[] rects;

        if (bias == TooltipBias.Down)
        {
            rects = new[] { yMinRect, yMaxRect, xMinRect, xMaxRect };
        }
        else if (bias == TooltipBias.Up)
        {
            rects = new[] { yMaxRect, yMinRect, xMinRect, xMaxRect };
        }
        else if (bias == TooltipBias.Left)
        {
            rects = new[] { xMinRect, xMaxRect, yMinRect, yMaxRect };
        }
        else
        {
            rects = new[] { xMaxRect, xMinRect, yMinRect, yMaxRect };
        }

        //  bounds                     bounds
        //+------------------------+ +--------+--------+------+
        //|                        | |        |        |      |
        //|                        | |        |        |      |
        //|          yMax          | |  xMin  |        | xMax |
        //|                        | |        |        |      |
        //|                        | |        |        |      |
        //+--------+--------+------+ |        +--------+      |
        //|        |        |      | |        |        |      |
        //|        | source |      | |        | source |      |
        //|        |        |      | |        |        |      |
        //+--------+--------+------+ |        +--------+      |
        //|          yMin          | |        |        |      |
        //|                        | |        |        |      |
        //+------------------------+ +--------+--------+------+

        // find the first division in which the tooltip rect will fit
        for (int i = 0; i < rects.Length; ++i)
        {
            Rect rect = rects[i];

            if (extentRect.width  <= rect.width
             && extentRect.height <= rect.height)
            {
                // push the tooltip rect into the division
                float pushR = Mathf.Max(0f, rect.xMin - extentRect.xMin);
                float pushU = Mathf.Max(0f, rect.yMin - extentRect.yMin);

                float pushL = Mathf.Min(0f, rect.xMax - extentRect.xMax);
                float pushD = Mathf.Min(0f, rect.yMax - extentRect.yMax);

                var push = new Vector2(pushL + pushR, pushU + pushD);

                tooltip.position += (Vector3) push;

                break;
            }
        }
    }
開發者ID:Ragzouken,項目名稱:kooltool-rekindle,代碼行數:91,代碼來源:UIExtensions.cs


注:本文中的UnityEngine.RectTransform.GetWorldRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。