Unity 固定高度等比放大宽度

 imgae =transform.GetComponent<Image>();
        imgae.preserveAspect = true;
        float imageH = imgae.transform.parent .GetComponent<RectTransform>().sizeDelta.y;
        float imageW = imageH * imgae.preferredWidth / imgae.preferredHeight;
       
        RectTransform rectFransF = transform.GetComponent<RectTransform>();
        rectFransF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, imageW);

 

posted on 2021-04-27 10:49  zqiang0803  阅读(413)  评论(0编辑  收藏  举报

导航