找回密码
 立即注册
楼主: xiaosong123451

[ugui/ngui] NGUI自适应分辨率,黑边自动填充, 无黑边,等比例缩放

[复制链接]
发表于 2014-4-19 11:36 | 显示全部楼层 |阅读模式
为了优化,不重叠图片 [编辑话题]

1,给背景添加一个UIstretch, .将style选择最后一个FitInternalKeepingRatio,    将Intial Size设置为你当前屏幕的大小


2,再在背景下创建四个边的背景, 然后各自选择他们的Pivot , 上边图选择居下,下边图选择居上,左图边选择居右,右边图选择居左。



                       



3,给这四个添加一个UIstretch, .将style选择为both,





4. 然后把下面这个脚本绑定到背景上,传上参数,



using UnityEngine;
using System.Collections;


public class FillBackGround : MonoBehaviour {


   
    public UISprite backGround;
    public UIStretch upBG;
    public UIStretch downBG;
    public UIStretch leftBG;
    public UIStretch rightBG;
    private float _bgWidth;
    private float _bgHeight;
// Use this for initialization
void Start () {


         //获取背景的宽和高
        _bgWidth = backGround.width;
        _bgHeight = backGround.height;


         //填充背景上边
        upBG.transform.localPosition = new Vector3(0, _bgHeight/2,0);
        upBG.relativeSize.y=0.5f;
        upBG.borderPadding.y = _bgHeight / 2;
         


         //填充背景下边
        downBG.transform.localPosition = new Vector3(0, -_bgHeight / 2, 0);
        downBG.relativeSize.y = 0.5f;
        downBG.borderPadding.y = _bgHeight / 2;


         //填充背景左边
        leftBG.transform.localPosition = new Vector3(-_bgWidth / 2, 0, 0);
        leftBG.relativeSize.x = 0.5F;
        leftBG.borderPadding.x = _bgWidth / 2;
      


         //填充背景右边
        rightBG.transform.localPosition = new Vector3(_bgWidth / 2, 0, 0);
        rightBG.relativeSize.x = 0.5F;
        rightBG.borderPadding.x = _bgWidth / 2;
         
}
   
// Update is called once per frame


}


效果运行效果如下
       图片:1.png


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2014-4-21 12:31 | 显示全部楼层
学习一次,我先试试看
发表于 2017-2-17 19:37 | 显示全部楼层
很不错
发表于 2017-2-17 20:01 | 显示全部楼层
楼主是超人
发表于 2017-2-17 20:17 | 显示全部楼层
好帖就是要顶
发表于 2017-2-17 19:41 | 显示全部楼层
难得一见的好帖
发表于 2017-2-17 20:26 | 显示全部楼层
说的非常好
发表于 2017-2-18 12:52 | 显示全部楼层
很不错
发表于 2017-2-18 12:31 | 显示全部楼层
楼主是超人
发表于 2017-2-18 12:52 | 显示全部楼层
好帖就是要顶
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 23:35 , Processed in 0.104990 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表