Book
A class in Root.Township, Alta.Pages.
A networked book item that holds pages (recipe books, journals) from a PageCollection. The server keeps the page list and turns pages; clients see the spawned page objects and the page count it sends.
- Listed in Items, inventory and logic
- Inherits or implements
NetworkEntityBehaviour,ISavable<BookSaveData>,ISavableSave<BookSaveData>,ISavableSaveBase,IBuildRendererBakeable,IBuildBakeable - Derived types
BookSaveData - Nested types
FlairPositions,LODRenderers - Documented in Pages and books
Constructors
| Member | What it is |
|---|---|
Book() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
68 private and internal fields
| Member | What it is |
|---|---|
private static int _IsFromMiddle | Animator hash for IsFromMiddle. |
private static int _IsFront | Animator hash for IsFront. |
private static int _IsInteracting | Animator hash for IsInteracting. |
private static int _IsOpen | Animator hash for IsOpen. |
private static int _MainTex | Shader property ID for _MainTex. |
private static int _Open | Animator hash for Open. |
private GameObject addHighlight | Object shown when a page can be dropped in. |
private MethodSyncClass<NewPageArguments> addPage | Method sync for the add-page message. |
private Transform backCover | Back cover transform. |
private GameObject backObject | Back cover object. |
private Animator bookAnimator | The book's animator. |
private LODGroup bookLodGroup | LOD group that flairs are added to. |
private AnimatedBool bookOpenAnimation | Networked Open animator bool. |
private List<PageData> bookPages | Server: the pages in the book, in order. |
private bool btDuplicate | Editor button for DuplicatePage. |
private bool btnClose | Editor button for Close. |
private bool btnFill | Editor button for Fill. |
private bool btnLeft | Editor button for TurnLeftDebug. |
private bool btnOpen | Editor button for Open. |
private bool btnRight | Editor button for TurnRightDebug. |
private uint clientPageCount | Page count as last synced; PageCount returns it on clients. |
private float closedCoverRotation | Cover rotation when closed, set to match the art. |
private float closeDuration | Seconds the close animation takes. |
private float closeUpwardsDotLimit | The book closes when its forward vector's upward part drops below this. |
private float closeVelocityLimit | The book closes when moved faster than this. |
private PageCollection collection | The PageCollection this book holds. It is the only thing the book saves. |
private Image coverGlyph | Image for the cover glyph. |
private int displayedSpawnIndex | Which spawned page is the one shown, or -1. |
private int firstPageIndex | Index in bookPages of the first spawned page. |
private Book.FlairPositions flairPositions | Cover attach points for flairs, plus the book renderers and letter text. |
private Transform frontCover | Front cover transform. |
private GameObject frontObject | Front cover object. |
private Renderer glyphAndroidRenderer | Android glyph renderer, removed at build time. |
private Canvas glyphCanvas | Canvas the cover glyph is drawn on. |
private Coroutine heldCoroutine | Server: the running Held coroutine. |
private List<Pickup> hovering | Loose pages in the drop area being watched. |
private Queue<PageData> inserting | Pages waiting to be inserted while the book is open. |
private int lastOpenedPage | Page the book was on when last closed; it reopens there. |
private MethodSync locationChange | Method sync for the page-location-changed message. |
private LOD[] lods | Cached LOD array of the book. |
private static Logger logger | NLog logger for this class. |
private float openDuration | Seconds the open animation takes. |
private float openUpwardsDotLimit | The book opens when its forward vector's upward part is above this. |
private float openVelocityLimit | The book only opens when moving slower than this. |
private Transform pageAxis | Parent transform spawned pages hang from. |
private TextRenderer pageCount | Text showing pages found out of the total. |
private AltaEvent pageLocationChanged | Event played when a newly added page opens the book somewhere else. |
private TextRenderer pageNumber | Text showing the current page number. |
private NetworkPrefab pagePrefab | Prefab spawned for each page shown in the book. |
private SoundEffect pageTurningSound | Sound played on a page turn. |
private NetworkPrefab paperPrefab | Prefab of a loose paper page, spawned by DuplicatePage. |
private Pickup pickup | The book's pickup. |
private PickupArea pickupArea | Area that detects loose pages to add. |
private MethodSyncStruct<int> removePage | Method sync for the remove-page message. |
private Book.LODRenderers[] renderers | Cached base renderers per LOD level, used when rebuilding flairs. |
private MethodSyncStruct<bool> serverFlipPage | Method sync for client turn-page requests. |
private MethodSyncClass<DisplayArguments> setDisplay | Method sync for the page count and number text. |
private MethodSyncStruct<bool> setHighlight | Method sync for the add-page highlight. |
private MethodSyncStruct<bool> setOpen | Method sync for open and close. |
private List<BookPageInstance> spawnedPages | Page entities spawned in the open book, in order. |
private GameObject spineObject | Spine object. |
private MethodSync sync | Method sync for the initial book sync. |
private int turnDirection | Direction of the turn in progress: -1, 0 or 1. |
private List<PageInstance> turning | Pages in the middle of turning. |
private MethodSyncClass<TurnPageArguments> turnPage | Method sync for page turns. |
private float turnRate | Seconds between repeated page turns while input is held. |
private float turnSkipProgress | Where a skipped turn starts in its animation, 0 to 1. |
private float turnTime | Seconds a page turn takes. |
Properties
| Member | What it is |
|---|---|
PageCollection Collection { get; } | The PageCollection that defines which pages this book can hold and their order. A book spawned without one destroys itself. |
bool IsAtBack { get; private set; } | True when the open book shows its last page. |
bool IsAtFront { get; private set; } | True when the open book shows its first page. |
bool IsChangingOpenState { get; private set; } | True while the open or close animation runs. Page turns are refused then. |
bool IsInserting { get; } | True while pages are queued to be animated into the open book. |
bool IsOpen { get; private set; } | Whether the book is open. The server opens it while held facing up and slow, and closes it otherwise. |
int PageCount { get; } | Number of pages in the book. On clients this is the count last sent by the server. |
Pickup Pickup { get; } | The book's Pickup. Holding it blocks locomotion and lets the holder turn pages. |
1 private and internal property
Methods
| Member | What it is |
|---|---|
bool AddNewPage(PageData page) | Server: adds a page in collection order and animates it in if the book is open. False on clients or if the collection lacks the page. |
void BookRemovePage(PageData pageData) | Removes a page from the book's list and refreshes the open spread and page display. Called when a page is pulled out. |
void Close() | Closes the book if it is open and not already opening or closing. The server closes it when it is dropped or tilted away. |
PaperPageInstance DuplicatePage(PageData pageData, ref bool isDuplicate) | Server: spawns a loose paper copy of a page at the book. Always a duplicate if the collection forbids removal. Null on clients. |
override void Initialize() | Sets up the network messages for sync, adding, removing and turning pages, opening, highlighting and flipping. |
override void InitializeAsServer(SpawnData spawnData) | Server: destroys the book if it has no collection, otherwise adds every collection page already unlocked globally and listens for new ones. |
override void OnConnected(Player player) | Server: sends a joining player the book's state, its spawned pages, page display and open state. |
void Open() | Opens the book if it is closed and not already changing state. |
void SetCollection(PageCollection collection) | Server: sets the page collection. Ignored on clients. |
bool TurnLeft(bool isSkipping = false) | Server: turns forward one page if the book is open and not at the back. Returns whether a turn started. |
bool TurnRight(bool isSkipping = false) | Server: turns back one page if the book is open and not at the front. Returns whether a turn started. |
46 private and internal methods
| Member | What it is |
|---|---|
private void AddFlair(BookFlair baseFlair, BookFlair overrideFlair, Transform parent, Material material, List<Renderer>[] renderers) | Adds the override flair, or the base one if none, at a cover position with the flair material. |
private void AddPage(BookPageInstance newPage, int spawnedIndex, bool isFromMiddle = false) | Puts a spawned page into the book at a slot and sets its animator; overload is the add-page message handler on clients. |
private void AddPage(IPlayer player, Stream stream, NewPageArguments newPage) | Puts a spawned page into the book at a slot and sets its animator; overload is the add-page message handler on clients. |
private void ApplyFlairs() | Rebuilds the cover decoration (emblem, glyph or letter, spine and edge flairs, book material) from the collection's flair settings. |
private void Awake() | Hooks pickup grab, drop and interaction filter, and hides the page drop area. |
private void IBuildRendererBakeable.Bake(bool isSaving) | Build step that removes the Android glyph renderer. |
private bool CacheLods() | Editor setup that caches the renderers of each LOD level, so flairs can be added later. |
private IEnumerator ChangeOpen(bool isOpening) (iterator) | Coroutine that opens or closes the book, spawning pages at the last opened page on open and removing them on close. |
private void CheckGlobalPage(ValueTuple<int, uint> data) | Server: when a page is unlocked globally, adds it to this book if it belongs to the collection. |
private void CheckInsert(Interactable pickup, Interactor interactor) | When a loose page is let go over the book, adds it, records it globally and destroys the loose page. |
private void IBuildRendererBakeable.Clean() | Build clean step; does nothing. |
private void ClientMoveLeft(PlayerInput input) | Client: asks the server to turn left when the move-left action starts. |
private void ClientMoveRight(PlayerInput input) | Client: asks the server to turn right when the move-right action starts. |
private void ClientSwiped(PlayerInput playerInput) | Client: asks the server to turn a page from a left or right swipe. |
private IEnumerator DelayToInteract(BookPageInstance newPage, bool isFromMiddle) (iterator) | Keeps a new page non-interactable for the open duration. |
private void DestroyPage(int spawnedIndex) | Removes a spawned page from the open book; on the server it also destroys the entity and tells clients. |
private void Dropped(Interactable interactable, Interactor interactor) | Unblocks locomotion, stops the held check and closes the book when nobody holds it. |
private void Fill() | Debug: on an empty server book, adds every page of the collection and unlocks them globally. |
private IEnumerator FinishTurning(BookPageInstance page, int direction, bool isSkipping) (iterator) | Coroutine that finishes a page turn, then on the server removes pages that went out of view. |
private int GetCurrentPage() | Index in bookPages of the page shown, or -1. |
private int GetPageNumber() | Page number to display: the shown page's index in the collection, or -1. |
private IEnumerator Held(Interactor interactor) (iterator) | Server coroutine while held: opens the book when it faces up and is still, closes it otherwise, and turns pages from input. |
private IEnumerator InsertPage(PageData page) (iterator) | Coroutine that waits for turns to stop, then reopens the book at a newly added page. |
private void InteractionFilter(Interactor interactor, Interactable interactable, ref bool result) | Stops a player grabbing the book with a second hand while already holding it. |
private void ListenForPageDrop(Pickup pickup) | When a loose page from this collection enters the drop area, shows the highlight and waits for it to be let go. |
private void LocationChange(IPlayer player, Stream stream) | Client handler that plays the page-location-changed event. |
private void OnDestroy() | Unhooks the global page-added event. |
private void PickedUp(Interactable interactable, Interactor interactor) | Blocks locomotion for the holder, starts the server held check and hooks the local player's page-turn input. |
private void RemovePage(IPlayer player, Stream stream, int oldPage) | Client handler for the remove-page message. |
private void SerializeBook(Stream stream, bool isIncludingPages) | Writes or reads the collection and page count (and the pages themselves, if asked). |
private void ServerFlipPage(IPlayer player, Stream stream, bool flipRight) | Server handler for a client's turn-page request. |
private void SetDisplay(IPlayer player, Stream stream, DisplayArguments arguments) | Message handler that updates the page count and page number text. |
private void SetHighlight(IPlayer player, Stream stream, bool isHighlighted) | Client handler that shows or hides the add-page highlight. |
private void SetOpen(IPlayer player, Stream stream, bool isOpen) | Client handler that opens or closes the book. |
private void ShowHighlight(bool isShowing) | Shows or hides the add-page highlight; the server also sends it to clients. |
private PageInstance SpawnPage(int index, int spawnedIndex, bool isFromMiddle = false) | Server: spawns a page entity for a book page and adds it at a slot on every side. |
private void Start() | Gets the networked Open animator bool and starts closed. |
private void StartListeningForDrops() | Turns on the drop area for adding loose pages. |
private void StopListenForPageDrop(Pickup pickup) | Stops watching a loose page that left the drop area. |
private void StopListeningForDrops() | Turns off the drop area and stops watching every hovering page. |
private void Sync(IPlayer player, Stream stream) | Initial sync handler: sends the collection and page count, and clients apply the flairs. |
private void TurnLeftDebug() | Editor button for TurnLeft. |
private void TurnPage(int spawnedIndex, int direction, bool isSkipping) | Plays a page turn locally; overload is the client handler for the turn message. |
private void TurnPage(IPlayer player, Stream stream, TurnPageArguments turnPage) | Plays a page turn locally; overload is the client handler for the turn message. |
private void TurnPageAsServer(int spawnedIndex, int direction, bool isSkipping) | Server: turns a spawned page, tells clients and spawns the next page in that direction. |
private void TurnRightDebug() | Editor button for TurnRight. |
Used in
Members of other types that take, return or hold a Book: