unity 手机分辨率适配
2017-06-06 18:40
155 查看
摄像机 的适配
public class UICameraAdjustor : MonoBehaviour
{
// the design size
public float standard_width = 576f;
public float standard_height = 1024f;
// the screen size
float device_width = 0f;
float device_height = 0f;
void Awake ()
{
device_width = Screen.width;
device_height = Screen.height;
SetCameraSize ();
}
private void SetCameraSize ()
{
float adjustor = 0f;
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
if (device_aspect < standard_aspect) {
adjustor = standard_aspect / device_aspect;
camera.orthographicSize = adjustor;
}
}
}
ui适配
public class UIBackgroundAdjustor : MonoBehaviour
{
// the design size
public float standard_width = 576f;
public float standard_height = 1024f;
void Awake ()
{
SetBackgroundSize ();
}
private void SetBackgroundSize ()
{
float device_width = Screen.width;
float device_height = Screen.height;
if (transform != null) {
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
float scale = 0f;
if (device_aspect > standard_aspect) { //按宽度适配
scale = device_aspect / standard_aspect;
transform.localScale = new Vector3 (scale, 1, 1);
} else { //按高度适配
scale = standard_aspect / device_aspect;
transform.localScale = new Vector3 (1, scale, 1);
}
}
}
} //
摄像机与 ui配合 使用 即可达到适配效果
public class UICameraAdjustor : MonoBehaviour
{
// the design size
public float standard_width = 576f;
public float standard_height = 1024f;
// the screen size
float device_width = 0f;
float device_height = 0f;
void Awake ()
{
device_width = Screen.width;
device_height = Screen.height;
SetCameraSize ();
}
private void SetCameraSize ()
{
float adjustor = 0f;
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
if (device_aspect < standard_aspect) {
adjustor = standard_aspect / device_aspect;
camera.orthographicSize = adjustor;
}
}
}
ui适配
public class UIBackgroundAdjustor : MonoBehaviour
{
// the design size
public float standard_width = 576f;
public float standard_height = 1024f;
void Awake ()
{
SetBackgroundSize ();
}
private void SetBackgroundSize ()
{
float device_width = Screen.width;
float device_height = Screen.height;
if (transform != null) {
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
float scale = 0f;
if (device_aspect > standard_aspect) { //按宽度适配
scale = device_aspect / standard_aspect;
transform.localScale = new Vector3 (scale, 1, 1);
} else { //按高度适配
scale = standard_aspect / device_aspect;
transform.localScale = new Vector3 (1, scale, 1);
}
}
}
} //
摄像机与 ui配合 使用 即可达到适配效果
相关文章推荐
- unity 做手机开发的简单适配
- android应用如何适配于多个分辨率的手机
- 如何实现大分辨率的图片等比例缩放,使其适配不同的手机
- 根据手机屏幕分辨率设置组件或控件的大小,利用像素更好的适配不同尺寸的机型的动态布局
- Android应用如何适配不同分辨率的手机
- android适配不同分辨率的手机
- android中不同手机分辨率适配问题
- android中不同手机分辨率适配问题
- 适配不同分辨率的Android手机的简单处理方法
- unity5.4 UGUI 手机屏幕自适应分辨率
- 适配不同分辨率的Android手机的处理方法
- Android应用如何适配不同分辨率的手机
- Android应用如何适配不同分辨率的手机
- android中不同手机分辨率适配问题
- 【最新】Android 手机分辨率整理(做屏幕适配的拿走)
- 手机h5适配不同分辨率的问题
- Android 不同手机分辨率适配(xml方式)
- android&nbsp;不同手机分辨率适配问题
- 实战开发问题总结(界面设计)----android应用如何适配于多个分辨率的手机
- Unity3d NGUI 拉伸适配各种手机分辨率