Beispiel #1
0
    static public Rect GetUIObjectScreenRect(Transform uiObjTrans)
    {
        Rect rect = new Rect();

        if (uiObjTrans == null)
        {
            return(rect);
        }
        var     box        = uiObjTrans.GetComponent <BoxCollider>();
        Vector2 pos        = UIToolkits.GetUIObjectScreenPos(uiObjTrans);
        var     tweenScale = uiObjTrans.GetComponent <ShowSimpleUIEffect>();

        if (box != null)
        {
            float scaleX = 1.0f;
            float scaleY = 1.0f;
            //exclude scale effect
            if (tweenScale == null)
            {
                scaleX = uiObjTrans.localScale.x;
                scaleY = uiObjTrans.localScale.y;
            }

            rect.width  = box.size.x * scaleX;
            rect.height = box.size.y * scaleY;

            float offsetX = box.center.x * scaleX;
            float offsetY = box.center.y * scaleY;

            rect.x = pos.x + offsetX - rect.width / 2;
            rect.y = pos.y - offsetY - rect.height / 2;
        }
        else
        {
            rect.x = pos.x;
            rect.y = pos.y - uiObjTrans.localPosition.y;                        //Convert Y
            GetWidgetComponentRect(uiObjTrans, ref rect);
        }
        return(rect);
    }