查看: 890|回复: 0
打印 上一主题 下一主题

[NGUI]NGUI宽度适应

[复制链接]

3795

主题

2

听众

5万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
53202
精华
32

活跃会员 优秀版主 推广达人 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-3-2 10:04:24 |只看该作者 |倒序浏览
using UnityEngine;
using System.Collections;

public class UIRootExtend : MonoBehaviour {
   
    public int manualWidth = 640;
   
    private UIRoot _UIRoot;
    void Awake()
    {
        _UIRoot = this.GetComponent<UIRoot>();
    }
   
    void Start ()
    {
        if(Screen.width < Screen.height)
            _UIRoot.manualHeight = System.Convert.ToInt32( System.Convert.ToSingle( Screen.height) / System.Convert.ToSingle( Screen.width) * System.Convert.ToSingle( manualWidth) );
    }
}

只需要把这个插件Add到UIRoot就可以了
当屏幕宽度小于屏幕高度的时候,根据manualWidth调整UIRoot的manualHeight
原作者:vinson 转载于unity3d圣典
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-27 13:32 , Processed in 0.195831 second(s), 31 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部