纳金网
标题:
NGUI自适应的代码
[打印本页]
作者:
王者再临
时间:
2014-8-28 23:30
标题:
NGUI自适应的代码
这是我觉得比较简单容易理解的自适应,记录一下
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class UIRootEx : MonoBehaviour
{
public bool m_IsLandscape = true;//是否是横屏
const int WindowScreenWidth = 960;//标准宽度
const int WindowScreenHeight = 640;//标准高度
void Awake()
{
float scale = (float)UnityEngine.Screen.width / (float)UnityEngine.Screen.height;//现有手机的宽高比
if (m_IsLandscape)
{
if (scale < 1.5f)
GetComponent<UIRoot>().manualHeight = (int)(WindowScreenWidth / scale);
else
GetComponent<UIRoot>().manualHeight = WindowScreenHeight;
}
else
{
scale = 1.0f / scale;
if (scale < 1.5f)
GetComponent<UIRoot>().manualHeight = WindowScreenWidth;
else
GetComponent<UIRoot>().manualHeight = (int)(WindowScreenHeight * scale);
}
}
// Use this for initialization
void Start()
{
//设置手机屏幕为横屏
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
}
// Update is called once per frame
void Update()
{
}
}
这个脚本是挂在UIRoot上的
作者:
kakaaka
时间:
2014-8-29 00:04
试试~~
作者:
tangqizuse
时间:
2014-8-29 00:31
新人学习了
作者:
hyui
时间:
2014-8-29 03:10
Thanks for sharing !
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5