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.
- Listed in Items, inventory and logic
- Inherits or implements
GeneratedNetworkEntityBehaviour,ISavable<PageInstanceSaveData>,ISavableSave<PageInstanceSaveData>,ISavableSaveBase - Derived types
BookPageInstance,PageInstanceSaveData,PaperPageInstance - Documented in Pages and books
Constructors
| Member | What it is |
|---|---|
PageInstance() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
11 private and internal fields
| Member | What it is |
|---|---|
private Animator animator | Backing field for Animator. |
private Collider[] colliders | Colliders turned off while the page is in a book. |
private PageData data | Backing field for Data: the glyphs and provider of the page. |
private bool isLoaded | Whether the page is currently rendered. |
private bool loadIsDuplicate | Set from the save so InitializeAsServer can mark the page a duplicate. |
private static Logger logger | NLog logger for this class. |
private Object predefinedPage | A page object shown read-only in the inspector. Not used by this class. |
private PageData renderedData | The page data the current render was made from, released on unload. |
private Renderer renderer | Renderer that shows the rendered page material. |
private MethodSync sync | Method sync for Sync, sent on connect and by ForceSync. |
private VisibilityDetector visibilityDetector | Tells the page when it becomes visible or invisible so it loads and unloads its render. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action<PageInstance> OnChangedPage | Raised when page data is read from the network. |
Methods
| Member | What 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
| Member | What 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: