I built a script that will show different aspect ratios. Found some help on StackOverflow for orthographic calculation, after that it was simple.
As normal, place script where-ever and editor script inside "Editor" folder.
To use it place the CameraAspectRatioGizmos on the NGUI Camera.
You will get the options to show/hide different aspect ratios.
Please share if any improvements are made
CameraAspectRatioGizmos.csusing UnityEngine;
using System.Collections.Generic;
public class CameraAspectRatioGizmos : MonoBehaviour {
/**
* Display gizmo for different camera aspect ratios
* @CreatedBy: Fredrick Bäcker
* @Use: As you wish! ;)
*/
// 3:2 4:3 16:10 5:3 17:10 16:9
public bool layoutPortrait = true;
public bool layoutLandscape = true;
[SerializeField]
public List
<bool> portrait
= new List
<bool>(); [SerializeField]
public List
<bool> landscape
= new List
<bool>();
void OnDrawGizmos () {
Gizmos.color = Color.blue;
Matrix4x4 tmp = Gizmos.matrix;
Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
float spread = camera.farClipPlane - camera.nearClipPlane;
float center = (camera.farClipPlane + camera.nearClipPlane)*0.5f;
float size = camera.orthographicSize*2;
if(layoutPortrait) {
for(int i = 0; i < portrait.Count; i++) {
if( portrait[i] ) {
// Show aspect ratio
float aspect = aspectPortrait(i);
Gizmos
.DrawWireCube(new Vector3
(0,
0,center
),
new Vector3
(size
*aspect, size, spread
)); }
}
}
if(layoutLandscape) {
for(int i = 0; i < landscape.Count; i++) {
if( landscape[i] ) {
// Show aspect ratio
float aspect = aspectLandscape(i);
Gizmos
.DrawWireCube(new Vector3
(0,
0,center
),
new Vector3
(size
*aspect, size, spread
)); }
}
}
Gizmos.matrix = tmp;
}
private float aspectPortrait(int index) {
switch(index){
case 0 :
return 0.6666667f;
case 1 :
return 0.75f;
case 2 :
return 0.625f;
case 3 :
return 0.6f;
case 4 :
return 0.588235294f;
case 5 :
return 0.5625f;
}
return 1;
}
private float aspectLandscape(int index) {
switch(index){
case 0 :
return 1.5f;
case 1 :
return 1.333333333f;
case 2 :
return 1.6f;
case 3 :
return 1.666666667f;
case 4 :
return 1.7f;
case 5 :
return 1.777777778f;
}
return 1;
}
}
CameraAspectRatioGizmosEditor.csusing UnityEngine;
using UnityEditor;
[CustomEditor
(typeof(CameraAspectRatioGizmos
))] public class CameraAspectRatioGizmosEditor : Editor
{
private CameraAspectRatioGizmos t;
void OnEnable()
{
t = target as CameraAspectRatioGizmos;
}
override public void OnInspectorGUI()
{
if( t.portrait.Count == 0 ) { for(int i = 0; i < 6; i++){ t.portrait.Add(false); } }
if( t.landscape.Count == 0 ) { for(int i = 0; i < 6; i++){ t.landscape.Add(false); } }
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Camera Aspect Ratio Gizmos");
EditorGUILayout.EndHorizontal();
t.layoutPortrait = EditorGUILayout.BeginToggleGroup("Portrait", t.layoutPortrait);
t.portrait[0] = EditorGUILayout.Toggle("3:2", t.portrait[0]);
t.portrait[1] = EditorGUILayout.Toggle("4:3", t.portrait[1]);
t.portrait[2] = EditorGUILayout.Toggle("16:10", t.portrait[2]);
t.portrait[3] = EditorGUILayout.Toggle("5:3", t.portrait[3]);
t.portrait[4] = EditorGUILayout.Toggle("17:10", t.portrait[4]);
t.portrait[5] = EditorGUILayout.Toggle("16:9", t.portrait[5]);
EditorGUILayout.EndToggleGroup();
t.layoutLandscape = EditorGUILayout.BeginToggleGroup("Landscape", t.layoutLandscape);
t.landscape[0] = EditorGUILayout.Toggle("3:2", t.landscape[0]);
t.landscape[1] = EditorGUILayout.Toggle("4:3", t.landscape[1]);
t.landscape[2] = EditorGUILayout.Toggle("16:10", t.landscape[2]);
t.landscape[3] = EditorGUILayout.Toggle("5:3", t.landscape[3]);
t.landscape[4] = EditorGUILayout.Toggle("17:10", t.landscape[4]);
t.landscape[5] = EditorGUILayout.Toggle("16:9", t.landscape[5]);
EditorGUILayout.EndToggleGroup();
if (GUI.changed) {
EditorUtility.SetDirty (t);
}
}
}