1、面片自适应屏幕
参加程序:
using UnityEngine;
using System.Collections;
public class SelfAdaption : MonoBehaviour {
private Camera _mainCamra;
void Start ()
{
PlaneSelfAdaption();
}
void PlaneSelfAdaption()
{
_mainCamra = Camera.main;
transform.position = _mainCamra.transform.position + new Vector3(0,0,10);
transform.rotation = Quaternion.Euler(_mainCamra.transform.rotation.eulerAngles + new Vector3(90,-180,0));
float _fov = _mainCamra.fieldOfView *0.5f;
float _scaleZ = Mathf.Tan( _fov/(float)180 * Mathf.PI ) *2;
float _scaleX = Screen.width/(float)Screen.height * _scaleZ;
transform.localScale = new Vector3(_scaleX,1,_scaleZ);
}
}
2、动态设置屏幕分辨率
SetResolution (width : int, height : int, fullscreen : bool)
3、按指定分辨率拉伸全屏显示
void Adaption()
{
float _scaleX = Screen.width/((float)1024/768 * Screen.height);
transform.localScale = new Vector3(_scaleX,1,1);
}
按照1024*768分辨率拉伸