自适应分辨率

摘要:
3.xx以上绑定到UIRootusingUnityEngine;namespaceCom.Xyz.UI{[ExecuteInEditMode][RequireComponent(typeof(UIRoot))]publicclassUIScreenAdaptive:MonoBehaviour{publicintaspectRatioWidth=1280;publicintaspectRatioHe

3.xx 以上 绑定到UIRoot

usingUnityEngine;
namespaceCom.Xyz.UI
{
    [ExecuteInEditMode]
    [RequireComponent(typeof(UIRoot))]
    public classUIScreenAdaptive : MonoBehaviour
    {
        public int aspectRatioWidth = 1280;
        public int aspectRatioHeight = 720;
        public bool runOnlyOnce = false;
        privateUIRoot mRoot;
        private bool mStarted = false;
        private voidAwake()
        {
            UICamera.onScreenResize +=OnScreenResize;
        }
        private voidOnDestroy()
        {
            UICamera.onScreenResize -=OnScreenResize;
        }
        private voidStart()
        {
            mRoot = NGUITools.FindInParents<UIRoot>(this.gameObject);
            mRoot.scalingStyle =UIRoot.Scaling.FixedSize;
            this.Update();
            mStarted = true;
        }
        private voidOnScreenResize()
        {
            if (mStarted &&runOnlyOnce)
            {
                this.Update();
            }
        }
        private voidUpdate()
        {
            float defaultAspectRatio = aspectRatioWidth * 1f /aspectRatioHeight;
            float currentAspectRatio = Screen.width * 1f /Screen.height;
            if (defaultAspectRatio >currentAspectRatio)
            {
                int horizontalManualHeight = Mathf.FloorToInt(aspectRatioWidth /currentAspectRatio);
                mRoot.manualHeight =horizontalManualHeight;
            }
            else
            {
                mRoot.manualHeight =aspectRatioHeight;
            }
            if (runOnlyOnce &&Application.isPlaying)
            {
                this.enabled = false;
            }
        }
    }
}

免责声明:文章转载自《自适应分辨率》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇springJpa 自定义参数查询springboot @Value 类中读取配置文件 .properties null 原因和解决方案下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Java 读取ANSI文件中文乱码问题解决方式[转]

Filefile=newFile(路径);InputStreamin=newjava.io.FileInputStream(文件);BufferedReader读取器=新的BufferedReader(读取);FileInputStreamin=newFileInputStream(文件);byte[]b=新字节[3];内容如下(b);...

汇编指令MOV

格式:MOVDST,SRC例如:MOVEAX,#050aH;将十六进制050a传送到通用寄存器eax中MOVDI,BXMOVES,AXMOVAX,DSMOVAL,23HMOV[2000H],02HMOV[2061H],BX...

winform窗体(六)——DataGridView控件及通过此控件中实现增删改查

“,”Delete Data“,btn)==DialogResult.Yes){}V.多条件查询。如果用户没有输入任何内容或文本框为空,则查询所有内容。//设置两个常量条件stringtj1=”1=1“;stringtj2=”1=1”;//根据用户的输入更改条件。//如果用户输入名称If(name!=”“){tj1=“Namelike@name“;}//如果...

js学习-es6实现枚举

最近,我大部分时间都在写dart,突然使用了js。我发现js不能直接声明枚举。目录枚举功能对象冻结()符号实现反映了不可更改值的唯一性。请注意,枚举特性枚举值不能重复,也不能修改。Switchcase可以直接判断对象。冻结()对象。方法可以冻结对象。无法更改实现constEnumSex=Object。冷冻枚举性别。人=1;安慰日志;//符号(男性)表示值co...

[Oracle]

MyOralceLinux6.5isrunningonVirtualBox.Basicsettingsis4Gmemory,50Ghard-disk,autopartitionwheninstallOL6.5.**Followingseriesofoperationsneedrootprivilege.1.Edit/etc/hostsAddyourhostn...

uni.showModal,uni.showToast使用

uni.showModal({title:'提示',content:'您已参加并通过本次考试,是否再次进行考试?...