当前位置: 首页>>代码示例>>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;未经允许,请勿转载。