纳金网
标题:
安卓 iphone 自动设置朝向
[打印本页]
作者:
狂风大尉
时间:
2014-6-30 16:03
标题:
安卓 iphone 自动设置朝向
此脚本主要为了 适应如下情况
设备无非两种情况
横宽竖窄、横窄竖宽
可能你在编译的时候设置了横屏 理想情况下是
横窄竖宽 实际拿到设备发现情况是 横宽竖窄
______ _____________
| ↓ | | ↓ |
| ↓ | | ↓ |
| ↓ | _____________
______
所以有了此脚本的诞生 设置横屏 必然是宽大于高 竖屏 则高大于款
脚本如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
public static class MethodRegister
{
/// <summary>
/// 横屏
/// </summary>
public static const int LANDSCAPE = 0;
/// <summary>
/// 竖屏
/// </summary>
public static const int PORTRAIT = 1;
/// <summary>
/// 自适应朝向
///
/// <param name="type">屏幕朝向类型 0横屏 1纵屏</param>
/// </summary>
public static void ReOrientation(this MonoBehaviour mono,int type)
{
int value1;
int value2;
switch (type) {
case LANDSCAPE:
value1 = Screen.height;
value2 = Screen.width;
break;
case PORTRAIT:
value1 = Screen.width;
value2 = Screen.height;
break;
default:
return;
}
#if UNITY_ANDROID
if (value1 > value2)
{
if (Screen.orientation == ScreenOrientation.Landscape || Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight)
{
Screen.orientation = ScreenOrientation.Portrait;
}
else
{
Screen.orientation = ScreenOrientation.Landscape;
}
}
#endif
#if UNITY_IPHONE
if (value1 > value2) {
if (Screen.orientation == ScreenOrientation.Landscape || Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight)
{
Screen.orientation = ScreenOrientation.Portrait;
}
else {
Screen.orientation = ScreenOrientation.Landscape;
}
}
#endif
}
}
复制代码
作者:
wucnj
时间:
2014-7-1 10:42
感谢分享!!!
作者:
icerein
时间:
2014-7-1 12:45
感谢分享!!!
作者:
hxsdsjr
时间:
2014-7-29 20:31
好东东支持
作者:
xizhenlong
时间:
2014-7-30 08:34
好
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5