@ -19,6 +19,86 @@ public class ViewEditor : Editor
}
}
}
}
Vector2 LookupAspectRatio ( int index )
{
switch ( index )
{
default :
case 1 :
return new Vector2 ( 4 , 3 ) ;
case 2 :
return new Vector2 ( 3 , 2 ) ;
case 3 :
return new Vector2 ( 1 6 , 1 0 ) ;
case 4 :
return new Vector2 ( 1 7 , 1 0 ) ;
case 5 :
return new Vector2 ( 1 6 , 9 ) ;
case 6 :
return new Vector2 ( 2 , 1 ) ;
case 7 :
return new Vector2 ( 3 , 4 ) ;
case 8 :
return new Vector2 ( 2 , 3 ) ;
case 9 :
return new Vector2 ( 1 0 , 1 6 ) ;
case 1 0 :
return new Vector2 ( 1 0 , 1 7 ) ;
case 1 1 :
return new Vector2 ( 9 , 1 6 ) ;
case 1 2 :
return new Vector2 ( 1 , 2 ) ;
}
}
public override void OnInspectorGUI ( )
{
View t = target as View ;
EditorGUI . BeginChangeCheck ( ) ;
string [ ] ratios = { "<None>" , "Landscape / 4:3" , "Landscape / 3:2" , "Landscape / 16:10" , "Landscape / 17:10" , "Landscape / 16:9" , "Landscape / 2:1" , "Portrait / 3:4" , "Portrait / 2:3" , "Portrait / 10:16" , "Portrait / 10:17" , "Portrait / 9:16" , "Portrait / 1:2" } ;
Vector2 primaryAspectRatio = EditorGUILayout . Vector2Field ( new GUIContent ( "Primary Aspect Ratio" , "Width and height values that define the primary aspect ratio (e.g. 4:3)" ) , t . primaryAspectRatio ) ;
int primaryIndex = EditorGUILayout . Popup ( "Select Aspect Ratio" , 0 , ratios ) ;
if ( primaryIndex > 0 )
{
primaryAspectRatio = LookupAspectRatio ( primaryIndex ) ;
}
EditorGUILayout . Separator ( ) ;
Vector2 secondaryAspectRatio = EditorGUILayout . Vector2Field ( new GUIContent ( "Secondary Aspect Ratio" , "Width and height values that define the primary aspect ratio (e.g. 4:3)" ) , t . secondaryAspectRatio ) ;
int secondaryIndex = EditorGUILayout . Popup ( "Select Aspect Ratio" , 0 , ratios ) ;
if ( secondaryIndex > 0 )
{
secondaryAspectRatio = LookupAspectRatio ( secondaryIndex ) ;
}
EditorGUILayout . Separator ( ) ;
Color primaryColor = EditorGUILayout . ColorField ( new GUIContent ( "Primary Color" , "Color for inner primary aspect ratio rectangle" ) , t . primaryColor ) ;
Color secondaryColor = EditorGUILayout . ColorField ( new GUIContent ( "Secondary Color" , "Color for outer secondary aspect ratio rectangle" ) , t . secondaryColor ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
// Avoid divide by zero errors
if ( primaryAspectRatio . y = = 0 )
{
primaryAspectRatio . y = 1 ;
}
if ( secondaryAspectRatio . y = = 0 )
{
secondaryAspectRatio . y = 1 ;
}
t . primaryAspectRatio = primaryAspectRatio ;
t . secondaryAspectRatio = secondaryAspectRatio ;
t . primaryColor = primaryColor ;
t . secondaryColor = secondaryColor ;
SceneView . RepaintAll ( ) ;
}
}
void OnSceneGUI ( )
void OnSceneGUI ( )
{
{
View t = target as View ;
View t = target as View ;
@ -68,8 +148,8 @@ public class ViewEditor : Editor
public static void DrawView ( View view )
public static void DrawView ( View view )
{
{
float height = CalculateLocalViewSize ( view ) ;
float height = CalculateLocalViewSize ( view ) ;
float widthA = height * view . primaryAspectRatio ;
float widthA = height * ( view . primaryAspectRatio . x / view . primaryAspectRatio . y ) ;
float widthB = height * view . secondaryAspectRatio ;
float widthB = height * ( view . secondaryAspectRatio . x / view . secondaryAspectRatio . y ) ;
// Draw left box
// Draw left box
{
{