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.
44 lines
1.3 KiB
44 lines
1.3 KiB
using UnityEngine; |
|
using System.Collections; |
|
|
|
namespace Fungus |
|
{ |
|
/** |
|
* Defines a screen aligned rectangular area for setting Page bounds |
|
*/ |
|
public class PageBounds : MonoBehaviour |
|
{ |
|
/// Rectangular bounds used to display page text. |
|
public Bounds bounds = new Bounds(Vector3.zero, new Vector3(0.25f, 0.25f, 0f)); |
|
|
|
/// Layout style to use for Page |
|
public Page.Layout layout = Page.Layout.FullSize; |
|
|
|
/** |
|
* Modifies the active Page to use a rect defined by the bounds and the current camera transform |
|
*/ |
|
public void UpdatePageRect() |
|
{ |
|
// Y increases down the screen in GUI space, so top left is rect origin |
|
Vector3 topLeft = transform.position + bounds.center; |
|
topLeft.x -= bounds.extents.x; |
|
topLeft.y += bounds.extents.y; |
|
|
|
Vector3 bottomRight = transform.position + bounds.center; |
|
bottomRight.x += bounds.extents.x; |
|
bottomRight.y -= bounds.extents.y; |
|
|
|
Vector2 tl = Camera.main.WorldToScreenPoint(topLeft); |
|
Vector2 br = Camera.main.WorldToScreenPoint(bottomRight); |
|
|
|
float x1 = (tl.x / Screen.width); |
|
float y1 = 1f - (tl.y / Screen.height); |
|
float x2 = (br.x / Screen.width); |
|
float y2 = 1f - (br.y / Screen.height); |
|
|
|
Page page = Game.GetInstance().activePage; |
|
page.SetPageRect(x1, y1, x2, y2); |
|
page.layout = layout; |
|
} |
|
} |
|
} |