using UnityEngine;
using System.Collections;
public class CameraScale : MonoBehaviour
{
// Use this for initialization
void Start()
{
// GetComponent<Camera>().fieldOfView *= GetScale(Screen.width, Screen.height);
// return;
int ManualWidth = 800;
int ManualHeight = 450;
int manualHeight;
if (System.Convert.ToSingle(Screen.height) / Screen.width > System.Convert.ToSingle(ManualHeight) / ManualWidth)
manualHeight = Mathf.RoundToInt(System.Convert.ToSingle(ManualWidth) / Screen.width * Screen.height);
else
manualHeight = ManualHeight;
Camera camera = GetComponent<Camera>();
float scale = System.Convert.ToSingle(manualHeight / 450f);
camera.fieldOfView *= scale;
}
// Update is called once per frame
void Update()
{
}
#region 不适用于3d缩放
public float width = 800f;
public float height = 450f;
private float GetScale(float w, float h)
{
float scale = 1f;
if (w / h >= width / height)
{
scale = h / height;
}
else
{
scale = w / width;
}
return scale;
}
#endregion
}