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.
4.7 KiB
4.7 KiB
Writing Story Text With Pages
The [Page](@ref Fungus.Page) component defines an area where the story textbox will appear on screen.
- The Page can display title text, say text and a list of options.
- The Page automatically hides when there is no remaining story text or options to display.
- The appearance of the text in the Page is controlled via the active [PageStyle](@ref Fungus.PageStyle) object.
How do I add a Page to a Room?
- Create an instance of Fungus/Prefabs/Page.prefab and make it a child of the View which it should appear inside.
- Resize and position the Page as desired.
How do I control which Page is used to display text?
- Ensure there are at least two Page objects in your Room.
- Add public Page properties to your Room script and setup references to each Page in the Room.
- Use the [SetPage](@ref Fungus.GameController.SetPage) command to control which Page rect will be used for rendering text.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
public Page leftPage; // A Page on the left hand side of the Room
public Page rightPage; // A Page on the right hand side of the Room
void OnEnter()
{
SetPage(leftPage);
Say("This text will now display on the left page");
SetPage(rightPage);
Say("This text will now display on the right page");
}
}
How do I write story text to the active Page?
- Use the [SetHeader](@ref Fungus.GameController.SetHeader) command to set the header text to be displayed at the top of the active page.
- Use the [SetFooter](@ref Fungus.GameController.SetFooter) command to set the footer text to be displayed at the bottom of the active page.
- Use the [Say](@ref Fungus.GameController.Say) command to display a single line of story text and then wait for the player to click to continue.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
void OnEnter()
{
SetHeader("The Title"); // Sets the header text
Say("Hello"); // Writes the story text and waits for player to continue
}
}
How do I create a multiple choice menu on the active Page?
- Use the [AddOption](@ref Fungus.GameController.AddOption) command to add an option to the current options list.
- Use the [Choose](@ref Fungus.GameController.AddOption) command to display the current list of options and wait for the player to select an option.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
void OnEnter()
{
AddOption("Option 1", DoOption1);
AddOption("Option 2", DoOption2);
Choose("Pick an option");
}
// Delegate method for option 1
void DoOption1()
{
Say("Picked option 1");
}
// Delegate method for option 2
void DoOption2()
{
Say("Picked option 2");
}
}
Notes
- The [AddOption](@ref Fungus.GameController.AddOption) command takes an optional delegate method to call when the player selects the option.
- If no delegate method is provided, the menu is dismissed and the next command in the queue is executed.
- The appearance of the option button is controlled via the active [PageStyle](@ref Fungus.PageStyle) object.
How do I control the appearance of Page text?
- Find Fungus/Prefabs/PageStyle1.prefab in the Fungus library
- Duplicate and rename this file (e.g. MyPageStyle.prefab)
- Modify the style settings in the prefab to adjust the appearance.
- Add a public PageStyle property to your Room script and setup a reference to your PageStyle prefab in the inspector.
- Use the [SetPageStyle](@ref Fungus.GameController.SetPage) command to change the style used to render Pages.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
public PageStyle myPageStyle; // Reference to a custom PageStyle prefab
void OnEnter()
{
Say("This text will display using the default PageStyle");
SetPageStyle(myPageStyle);
Say("This text will now display using the custom PageStyle");
}
}
Notes
- PageStyle uses standard Unity GUIStyle properties to control the appearance of the text and box background.
- You can easily change font, text color, bold, italic, etc. for each type of text.
- Modify the texture and settings in the boxStyle to change the appearance of the background box.
- Fungus overrides the font size properties for text to ensure consistent text scaling across devices with varying resolutions.
- Use the xxxFontScale properties to specify font size as a fraction of screen height.