Browse Source

View now supports arbitrary aspect ratios, improved visualization.

master
chrisgregan 11 years ago
parent
commit
5ad78612be
  1. 48
      Assets/Fungus/Editor/ViewEditor.cs
  2. BIN
      Assets/Fungus/Prefabs/Room.prefab
  3. BIN
      Assets/Fungus/Prefabs/View.prefab
  4. 27
      Assets/Fungus/Scripts/View.cs
  5. BIN
      Assets/FungusExample/Scenes/Example.unity

48
Assets/Fungus/Editor/ViewEditor.cs

@ -58,33 +58,43 @@ public class ViewEditor : Editor
{
Vector3 pos = view.transform.position;
float viewSize = view.viewSize;
// Draw 2:1 aspect ratio box
float height = viewSize;
float widthA = height * view.primaryAspectRatio;
float widthB = height * view.secondaryAspectRatio;
// Draw left box
{
float height = viewSize;
float width = height * (2f / 1f);
Vector3[] verts = new Vector3[4];
verts[0] = pos + new Vector3(-width, -height, 0);
verts[1] = pos + new Vector3(-width, height, 0);
verts[2] = pos + new Vector3(width, height, 0);
verts[3] = pos + new Vector3(width, -height, 0);
verts[0] = pos + new Vector3(-widthB, -height, 0);
verts[1] = pos + new Vector3(-widthB, height, 0);
verts[2] = pos + new Vector3(-widthA, height, 0);
verts[3] = pos + new Vector3(-widthA, -height, 0);
Handles.DrawSolidRectangleWithOutline(verts, new Color(1,1,1,0f), new Color(0,1,0,0.25f) );
Handles.DrawSolidRectangleWithOutline(verts, view.secondaryColor, view.primaryColor );
}
// Draw 4:3 aspect ratio box
// Draw right box
{
float height = viewSize;
float width = height * (4f / 3f);
Vector3[] verts = new Vector3[4];
verts[0] = pos + new Vector3(widthA, -height, 0);
verts[1] = pos + new Vector3(widthA, height, 0);
verts[2] = pos + new Vector3(widthB, height, 0);
verts[3] = pos + new Vector3(widthB, -height, 0);
Handles.DrawSolidRectangleWithOutline(verts, view.secondaryColor, view.primaryColor );
}
// Draw center box
{
Vector3[] verts = new Vector3[4];
verts[0] = pos + new Vector3(-width, -height, 0);
verts[1] = pos + new Vector3(-width, height, 0);
verts[2] = pos + new Vector3(width, height, 0);
verts[3] = pos + new Vector3(width, -height, 0);
verts[0] = pos + new Vector3(-widthA, -height, 0);
verts[1] = pos + new Vector3(-widthA, height, 0);
verts[2] = pos + new Vector3(widthA, height, 0);
verts[3] = pos + new Vector3(widthA, -height, 0);
Handles.DrawSolidRectangleWithOutline(verts, new Color(1,1,1,0f), new Color(0,1,0,1) );
Handles.DrawSolidRectangleWithOutline(verts, new Color(1,1,1,0f), view.primaryColor );
}
}
}

BIN
Assets/Fungus/Prefabs/Room.prefab

Binary file not shown.

BIN
Assets/Fungus/Prefabs/View.prefab

Binary file not shown.

27
Assets/Fungus/Scripts/View.cs

@ -11,10 +11,31 @@ namespace Fungus
[ExecuteInEditMode]
public class View : MonoBehaviour
{
/**
* Orthographic size of the camera view.
*/
public float viewSize = 0.5f;
// An empty Start() method is needed to display enable checkbox in editor
void Start()
{}
/**
* Aspect ratio of the primary view rectangle.
* e.g. a 4:3 aspect ratio = 1.333
*/
public float primaryAspectRatio = (4f / 3f);
/**
* Color of the primary view rectangle.
*/
public Color primaryColor = Color.green;
/**
* Aspect ratio of the secondary view rectangle.
* e.g. a 2:1 aspect ratio = 2/1 = 2.0
*/
public float secondaryAspectRatio = (2f / 1f);
/**
* Color of the secondary view rectangle.
*/
public Color secondaryColor = Color.grey;
}
}

BIN
Assets/FungusExample/Scenes/Example.unity

Binary file not shown.
Loading…
Cancel
Save