Skip to main content

PageInstance

A class in Root.Township, Alta.Pages.

A page or sheet of paper entity showing PageData (a recipe or glyphs). It renders only while visible, syncs its data from the server and is saved; freshly generated pages get a random page.

Constructors​

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

Fields​

11 private and internal fields
MemberWhat it is
private Animator animatorBacking field for Animator.
private Collider[] collidersColliders turned off while the page is in a book.
private PageData dataBacking field for Data: the glyphs and provider of the page.
private bool isLoadedWhether the page is currently rendered.
private bool loadIsDuplicateSet from the save so InitializeAsServer can mark the page a duplicate.
private static Logger loggerNLog logger for this class.
private Object predefinedPageA page object shown read-only in the inspector. Not used by this class.
private PageData renderedDataThe page data the current render was made from, released on unload.
private Renderer rendererRenderer that shows the rendered page material.
private MethodSync syncMethod sync for Sync, sent on connect and by ForceSync.
private VisibilityDetector visibilityDetectorTells the page when it becomes visible or invisible so it loads and unloads its render.

Properties​

MemberWhat it is
Animator Animator { get; }The page's animator.
Book Book { get; private set; }The book this page is in, or null when loose.
PageData Data { get; }The page's contents.
protected virtual bool IsDuplicate { get; set; }Whether this page is a copy; saved with the page. Subclasses decide what it means.

Events​

MemberWhat it is
event Action<PageInstance> OnChangedPageRaised when page data is read from the network.

Methods​

MemberWhat it is
void ForceSync()Sends the page data to everyone in the chunks.
override void Initialize()Sets up the synced data message and hooks rendering to visibility.
override void InitializeAsServer(SpawnData spawnData)Server: restores the duplicate flag loaded from the save.
override void OnConnected(Player player)Server: sends the page data to a new player.
void Reload()Re-renders the page if it is visible.
void Set(PageData data)Sets the page data and syncs it.
void SetInBook(Book book)Puts the page in a book (turning off its physics and colliders) or takes it out with null.
protected override void Generate(SpawnData spawnData)Server: gives a newly generated page a random spawnable page, or destroys it if there is none.
protected virtual void Serialize(Stream stream)Writes or reads the page data and raises OnChangedPage when reading.
7 private and internal methods
MemberWhat it is
private IEnumerator DelayRender(PageData data) (iterator)Client: renders the page data onto the page material a frame after it becomes visible. The overload with no arguments is empty.
private void DelayRender()Client: renders the page data onto the page material a frame after it becomes visible. The overload with no arguments is empty.
private void Load()Starts rendering the page when it becomes visible. The explicit ISavable overload restores the page data and duplicate flag from a save.
private void OnDisable()Releases the rendered page.
private void OnValidate()Empty.
private void Sync(IPlayer player, Stream stream)Syncs the page data; clients re-render it if visible.
private void Unload()Releases the rendered page material when the page goes out of view.

Used in​

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