Browse Source

Custom editor for View object, portrait support.

master
chrisgregan 11 years ago
parent
commit
8f4c54f75b
  1. 84
      Assets/Fungus/Camera/Editor/ViewEditor.cs
  2. 16
      Assets/Fungus/Camera/Scripts/View.cs

84
Assets/Fungus/Camera/Editor/ViewEditor.cs

@ -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(16, 10);
case 4:
return new Vector2(17, 10);
case 5:
return new Vector2(16, 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(10, 16);
case 10:
return new Vector2(10, 17);
case 11:
return new Vector2(9, 16);
case 12:
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 ()
{
View t = target as View;
@ -68,8 +148,8 @@ public class ViewEditor : Editor
public static void DrawView(View view)
{
float height = CalculateLocalViewSize(view);
float widthA = height * view.primaryAspectRatio;
float widthB = height * view.secondaryAspectRatio;
float widthA = height * (view.primaryAspectRatio.x / view.primaryAspectRatio.y);
float widthB = height * (view.secondaryAspectRatio.x / view.secondaryAspectRatio.y);
// Draw left box
{

16
Assets/Fungus/Camera/Scripts/View.cs

@ -22,20 +22,20 @@ namespace Fungus
* e.g. a 4:3 aspect ratio = 1.333
*/
[Tooltip("Aspect ratio of the primary view rectangle. (e.g. 4:3 aspect ratio = 1.333)")]
public float primaryAspectRatio = (4f / 3f);
/**
* Color of the primary view rectangle.
*/
[Tooltip("Color of the primary view rectangle.")]
public Color primaryColor = Color.green;
public Vector2 primaryAspectRatio = new Vector2(4, 3);
/**
* Aspect ratio of the secondary view rectangle.
* e.g. a 2:1 aspect ratio = 2/1 = 2.0
*/
[Tooltip("Aspect ratio of the secondary view rectangle. (e.g. 2:1 aspect ratio = 2.0)")]
public float secondaryAspectRatio = (2f / 1f);
public Vector2 secondaryAspectRatio = new Vector2(2, 1);
/**
* Color of the primary view rectangle.
*/
[Tooltip("Color of the primary view rectangle.")]
public Color primaryColor = Color.green;
/**
* Color of the secondary view rectangle.

Loading…
Cancel
Save