You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
11 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
11 years ago
|
/**
|
||
11 years ago
|
* Defines a user editable screen aligned rect for setting Page bounds.
|
||
11 years ago
|
*/
|
||
11 years ago
|
public class Page : MonoBehaviour
|
||
|
{
|
||
11 years ago
|
/// Rectangular bounds used to display page text.
|
||
|
public Bounds pageBounds = new Bounds(Vector3.zero, new Vector3(0.25f, 0.25f, 0f));
|
||
11 years ago
|
|
||
11 years ago
|
/// Layout style to use for Page
|
||
|
public PageController.Layout layout = PageController.Layout.FullSize;
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
11 years ago
|
* Modifies the PageController to use a rect defined by the bounds and the current camera transform
|
||
11 years ago
|
*/
|
||
11 years ago
|
public void UpdatePageRect()
|
||
11 years ago
|
{
|
||
11 years ago
|
// Y increases down the screen in GUI space, so top left is rect origin
|
||
|
Vector3 topLeft = transform.position + pageBounds.center;
|
||
|
topLeft.x -= pageBounds.extents.x;
|
||
|
topLeft.y += pageBounds.extents.y;
|
||
11 years ago
|
|
||
11 years ago
|
Vector3 bottomRight = transform.position + pageBounds.center;
|
||
|
bottomRight.x += pageBounds.extents.x;
|
||
|
bottomRight.y -= pageBounds.extents.y;
|
||
11 years ago
|
|
||
11 years ago
|
Vector2 tl = Camera.main.WorldToScreenPoint(topLeft);
|
||
|
Vector2 br = Camera.main.WorldToScreenPoint(bottomRight);
|
||
|
|
||
|
PageController.ScreenRect screenRect = new PageController.ScreenRect();
|
||
|
screenRect.x1 = (tl.x / Screen.width);
|
||
|
screenRect.y1 = 1f - (tl.y / Screen.height);
|
||
|
screenRect.x2 = (br.x / Screen.width);
|
||
|
screenRect.y2 = 1f - (br.y / Screen.height);
|
||
|
|
||
|
PageController page = Game.GetInstance().pageController;
|
||
|
page.pageRect = PageController.CalcPageRect(screenRect);
|
||
|
page.layout = layout;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|