Пример #1
0
    public static AABBox CalculateRelativeWidgetBounds(Transform root, Transform child)
    {
        Vector2 vector2;
        Vector2 vector21;
        Vector3 vector3  = new Vector3();
        Vector3 vector31 = new Vector3();
        AABBox  aABBox;
        AABBox  aABBox1;

        using (NGUIMath.WidgetList widgetsInChildren = NGUIMath.GetWidgetsInChildren(child))
        {
            if (!widgetsInChildren.empty)
            {
                bool      flag      = true;
                AABBox    aABBox2   = new AABBox();
                Matrix4x4 matrix4x4 = root.worldToLocalMatrix;
                foreach (UIWidget widgetsInChild in widgetsInChildren)
                {
                    widgetsInChild.GetPivotOffsetAndRelativeSize(out vector21, out vector2);
                    vector3.x  = (vector21.x + 0.5f) * vector2.x;
                    vector3.y  = (vector21.x - 0.5f) * vector2.y;
                    vector3.z  = 0f;
                    vector31.x = vector3.x + vector2.x * 0.5f;
                    vector31.y = vector3.y + vector2.y * 0.5f;
                    vector31.z = 0f;
                    vector3.x  = vector3.x - vector2.x * 0.5f;
                    vector3.y  = vector3.y - vector2.y * 0.5f;
                    Matrix4x4 matrix4x41 = matrix4x4 * widgetsInChild.cachedTransform.localToWorldMatrix;
                    AABBox    aABBox3    = new AABBox(ref vector3, ref vector31);
                    aABBox3.TransformedAABB3x4(ref matrix4x41, out aABBox);
                    if (!flag)
                    {
                        aABBox2.Encapsulate(ref aABBox);
                    }
                    else
                    {
                        aABBox2 = aABBox;
                        flag    = false;
                    }
                }
                aABBox1 = aABBox2;
            }
            else
            {
                aABBox1 = new AABBox();
            }
        }
        return(aABBox1);
    }
Пример #2
0
    public static AABBox CalculateAbsoluteWidgetBounds(Transform trans)
    {
        Vector2 vector2;
        Vector2 vector21;
        AABBox  aABBox;
        Vector3 vector3  = new Vector3();
        Vector3 vector31 = new Vector3();
        AABBox  aABBox1;

        using (NGUIMath.WidgetList widgetsInChildren = NGUIMath.GetWidgetsInChildren(trans))
        {
            if (!widgetsInChildren.empty)
            {
                AABBox aABBox2 = new AABBox();
                bool   flag    = true;
                foreach (UIWidget widgetsInChild in widgetsInChildren)
                {
                    widgetsInChild.GetPivotOffsetAndRelativeSize(out vector21, out vector2);
                    vector3.x  = (vector21.x + 0.5f) * vector2.x;
                    vector3.y  = (vector21.y - 0.5f) * vector2.y;
                    vector31.x = vector3.x + vector2.x * 0.5f;
                    vector31.y = vector3.y + vector2.y * 0.5f;
                    vector3.x  = vector3.x - vector2.x * 0.5f;
                    vector3.y  = vector3.y - vector2.y * 0.5f;
                    vector3.z  = 0f;
                    vector31.z = 0f;
                    AABBox    aABBox3   = new AABBox(ref vector3, ref vector31);
                    Matrix4x4 matrix4x4 = widgetsInChild.cachedTransform.localToWorldMatrix;
                    aABBox3.TransformedAABB3x4(ref matrix4x4, out aABBox);
                    if (!flag)
                    {
                        aABBox2.Encapsulate(ref aABBox);
                    }
                    else
                    {
                        aABBox2 = aABBox;
                        flag    = false;
                    }
                }
                aABBox1 = (!flag ? aABBox2 : new AABBox(trans.position));
            }
            else
            {
                aABBox1 = new AABBox();
            }
        }
        return(aABBox1);
    }
Пример #3
0
 public static AABBox CalculateAbsoluteWidgetBounds(Transform trans)
 {
     using (WidgetList list = GetWidgetsInChildren(trans))
     {
         if (list.empty)
         {
             return(new AABBox());
         }
         AABBox box  = new AABBox();
         bool   flag = true;
         foreach (UIWidget widget in list)
         {
             Vector2 vector;
             Vector2 vector2;
             AABBox  box2;
             Vector3 vector3;
             Vector3 vector4;
             widget.GetPivotOffsetAndRelativeSize(out vector2, out vector);
             vector3.x  = (vector2.x + 0.5f) * vector.x;
             vector3.y  = (vector2.y - 0.5f) * vector.y;
             vector4.x  = vector3.x + (vector.x * 0.5f);
             vector4.y  = vector3.y + (vector.y * 0.5f);
             vector3.x -= vector.x * 0.5f;
             vector3.y -= vector.y * 0.5f;
             vector3.z  = 0f;
             vector4.z  = 0f;
             AABBox    box3 = new AABBox(ref vector3, ref vector4);
             Matrix4x4 localToWorldMatrix = widget.cachedTransform.localToWorldMatrix;
             box3.TransformedAABB3x4(ref localToWorldMatrix, out box2);
             if (flag)
             {
                 box  = box2;
                 flag = false;
             }
             else
             {
                 box.Encapsulate(ref box2);
             }
         }
         if (flag)
         {
             return(new AABBox(trans.position));
         }
         return(box);
     }
 }
Пример #4
0
    public static AABBox CalculateRelativeInnerBounds(Transform root, UISlicedSprite sprite)
    {
        Vector2   vector2;
        Vector2   vector21;
        Vector3   vector3  = new Vector3();
        Vector3   vector31 = new Vector3();
        AABBox    aABBox;
        Transform transforms = sprite.cachedTransform;
        Matrix4x4 matrix4x4  = root.worldToLocalMatrix * transforms.localToWorldMatrix;

        sprite.GetPivotOffsetAndRelativeSize(out vector21, out vector2);
        float single  = (vector21.x + 0.5f) * vector2.x;
        float single1 = (vector21.y - 0.5f) * vector2.y;

        vector2 = vector2 * 0.5f;
        Vector3 vector32 = transforms.localScale;
        float   single2  = vector32.x;
        float   single3  = vector32.y;
        Vector4 vector4  = sprite.border;

        if (single2 != 0f)
        {
            vector4.x = vector4.x / single2;
            vector4.z = vector4.z / single2;
        }
        if (single3 != 0f)
        {
            vector4.y = vector4.y / single3;
            vector4.w = vector4.w / single3;
        }
        vector3.x  = single - vector2.x + vector4.x;
        vector31.x = single + vector2.x - vector4.z;
        vector3.y  = single1 - vector2.y + vector4.y;
        vector31.y = single1 + vector2.y - vector4.w;
        float single4 = 0f;
        float single5 = single4;

        vector31.z = single4;
        vector3.z  = single5;
        AABBox aABBox1 = new AABBox(ref vector3, ref vector31);

        aABBox1.TransformedAABB3x4(ref matrix4x4, out aABBox);
        return(aABBox);
    }