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.
5.3 KiB
5.3 KiB
Writing Story Text With Pages
The [Page](@ref Fungus.Page) component defines an area where the story textbox will appear on screen.
- A Page can display title text, say text and a list of options.
- Only one page is ever active at a time.
- The active Page automatically hides when there is no remaining story text or options to display.
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 will be used for text rendering.
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");
}
}
Notes
- If there is only one Page in a Room, Fungus will automatically make this the active Page when entering the Room.
- If a View has a child Page object, Fungus will automatically make this the active Page after transitioning to that View (e.g. via [SetView](@ref Fungus.GameController.SetView))).
- If you find that text is not rendering on the Page you expect, you probably need to set the active Page explicitly using the method shown above.
How do I write story text to the active Page?
- Use the [Title](@ref Fungus.GameController.Title) command to set the title text to be displayed at the top 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 press the continue button.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
void OnEnter()
{
Title("The Title"); // Sets the title text
Say("Hello"); // Writes the story text and waits for player to continue
}
}
Notes
- The [Page](@ref Fungus.Page) component defines the area where the story textbox will appear on screen.
- A Page can display title text, say text and a list of options.
- Only one Page is ever active at a time.
- The active Page automatically hides when there is no remaining story text or options to display.
- The appearance of the title and say text in the Page is controlled via the active [PageStyle](@ref Fungus.PageStyle) object.
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.