Skip to main content

GhostBook

A class in Root.Township, the global namespace.

Client: pooled ghost book that fades in, opens, pulls nearby auto-added pages into it, then closes and fades out. PageAutoAddEffect reuses an open one nearby or gets a new one.

Constructors​

MemberWhat it is
GhostBook()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

29 private and internal fields
MemberWhat it is
private readonly int _ProgressShader property ID for the fade progress.
private float accelerationPage acceleration toward the target.
private int animatingPagesPages still to land. The book closes when this reaches 0.
private Material animationMaterialMaterial copy whose _Progress drives the fade.
private Animator animatorAnimator for opening and closing.
private TransformEvent bookAppearsAfterRotatingEffectEvent raised after the fade in, before opening.
private TransformEvent bookAppearsBeforeRotatingEffectEvent raised when the book is positioned.
private TransformEvent bookCloseEffectEvent raised once the book has closed.
private TransformEvent bookDisappearAfterRotatingEffectEvent raised when the fade out ends.
private float closeDurationTime the close animation is given (default 0.25s).
private static List<GhostBook> currentlyOpenBooksStatic list of books that are open or opening, for reuse by nearby pages.
private float fadeDurationFade in and fade out time.
private bool isOpenWhether the open animation has finished.
private float maxDistanceToReuseSquaredSquared distance within which a new page reuses this book.
private float movementLerpSpeedNot used in this file.
private float moveSpeedPage move speed toward the target.
private readonly int OpenAnimator hash for the Open bool.
private float openDurationTime the open animation is given (default 0.25s).
private TransformEvent pageAddedEffectEvent raised for each page that lands.
private List<PageAutoAddEffect> pagesToAddPages queued for this book, released when it closes.
private Transform pageTargetTransform pages fly to.
private Vector3 placedRotationRotation offset applied on top of the placed rotation.
private float rotationLerpSpeedPage rotation lerp speed, faster as the page gets close.
private float scaleLerpSpeedPage scale lerp speed.
private float snapDistanceSquaredSquared distance at which a page snaps to the target.
private float snapDurationNot used in this file.
private Vector3 targetPagePositionPage target position stored in Position.
private Quaternion targetPageRotationPage target rotation stored in Position.
private Vector3 targetPageScalePage target scale stored in Position.

Methods​

MemberWhat it is
static bool GetCloserBook(Vector3 position, ref GhostBook bestBook)Finds the nearest open book within its reuse distance of the position. Returns false if none.
void Position(Vector3 position, Quaternion rotation)Places the book at a position and rotation and stores the page target pose.
void RegisterPage()Counts one more page that will animate into the book.
void StartPageAnimation(PageAutoAddEffect page)Queues a page and, if the book is already open, starts animating it.
7 private and internal methods
MemberWhat it is
private void Awake()Hooks the pool request and gives all renderers one shared copy of the fade material.
private IEnumerator CloseAndFadeOut() (iterator)Coroutine: closes the book, releases its pages, fades out and returns it to the pool.
private IEnumerator FadeInAndOpen() (iterator)Coroutine: fades the book in, plays the open animation, then starts page animations.
private void FinishAnimation()Called when the last page lands: removes the book from the open list and closes it.
private void FinishedOpening()Marks the book open and starts the animation for every queued page.
private void OnRequest(PooledObject pooledObject)Pool request handler: resets state, adds the book to the open list and starts fading in.
private IEnumerator PageAnimation(PageAutoAddEffect page) (iterator)Coroutine: steers a page's rigidbody to the page target, lerping rotation and scale, then snaps it.

Used in​

Members of other types that take, return or hold a GhostBook: