This page describes how to set up the Dialogue System with Opsive's UFPS. (UFPS is required.)
UFPS copyright © Opsive.
This package adds functionality to start conversations using UFPS's interaction framework, suspend UFPS gameplay during conversations, synchronize UFPS data between UFPS and the Dialogue System, and load and save games containing UFPS and Dialogue System data.
Follow these steps to set up the Dialogue System with UFPS.
In your project, navigate to the folder Assets / Dialogue System / Third Party Support
. Then import the package UFPS Support
. This will unpack files into the subfolder Third Party Support / UFPS
.
If you want to use the Dialogue System Menu Template with UFPS, see Set Up the Dialogue System Menu Framework.
Set up the Dialogue Manager GameObject normally as described in How to Set Up the Dialogue Manager. Then add these components:
The FPSync Lua Player On Load Level component allows you to have a different UFPS player GameObject in each level so you can test a level simply by playing it in the editor. When playing a game, before changing levels you can save the player's current UFPS data, such as health and inventory, into the Dialogue System's Lua environment. (An easy way to save the data is to use a Change Level Trigger, which is described further down on this page.) When the new level is loaded, FP Sync Lua Player On Load Level applies the saved data from the previous level to the player GameObject in the new level.
To set up the UFPS player in your scene, select menu item Component > Dialogue System > Third Party > UFPS > Add All Player Scripts. This will automatically configure your player with all of the scripts described below in the manual steps. If you use this menu item, you can skip all of the manual steps below.
(Some versions of Unity may not show this menu item. Its alternate location is Window > Dialogue System > Tools > UFPS.)
Use these instructions if you want to pick and choose which scripts are added to your player.
This documentation assumes your player is a UFPS AdvancedPlayer GameObject. Similar steps apply if you're using any of the other UFPS player prefabs such as Camera&Controller or Hero.
Add these scripts:
Actor[]
table. If your actor is named differently in the Lua Actor[]
table (e.g., the actor has a different name in Chat Mapper or the Dialogue Database), then set this property to the Lua name.true
or the player will receive his old stats, such as zero health. This checkbox clears itself after loading the level. If you want the scene after to also apply this rule, add FP Don't Apply Lua Next Load Level to any active GameObject in your scene. This will re-tick the checkbox to make it take effect for the next load level also.Freeze()
and Unfreeze()
methods are also used by the example scene's main menu, and you can use them in your own scripts if you want. The options on this component are:vp_FPInteractManager for UFPS Interaction Some UFPS player prefabs, such as Camera&Controller, don't start with a vp_FPInteractManager component. This component is required to use UFPS interaction, such as with FPInteractable Dialogue. If you want to use UFPS interaction, make sure your player has a vp_FPInteractManager.
GUILayer for Fade()
If you want to use the Fade() sequencer command, add a GUILayer to the player's FPSCamera. The Fade() command uses a GUITexture, so it relies on a GUILayer on the main camera.
Players with Bodies
Players with bodies, such as HeroHDWeapons, need an additional component. Add a Set Component Enabled On Dialogue Event and assign three components:
On NPCs, add these components:
If you want to use the Dialogue System's Selector functionality instead of UFPS's interaction framework, don't add FPInteractable Dialogue, and instead add a Usable component.
You can also set up barks and other Dialogue System features as normal, without having to configure any special UFPS versions.
On destructible objects such as crates, or killables such as enemies, add this component:
To set up a level transition trigger, create a GameObject with a trigger collider. Then add this component:
To use the Dialogue System Menu Framework (available on the Dialogue System extras page at www.pixelcrushers.com/dialogue-system-extras/), follow these steps:
These instructions will get the Menu Framework running with UFPS with the least work.
Dialogue System / Third Party Support / UFPS / Example / Menu Framework Example / Start UFPS
Dialogue System Extras / Dialogue System Menu Framework / Example / Loading
Dialogue System Extras / Dialogue System Menu Framework / Example / Credits
Dialogue System / Third Party Support / UFPS / Example / Menu Framework Example / Gameplay UFPS
Gameplay UFPS
, update the scene numbers/names on the Menu System's scripts and the Dialogue Manager's Level Manager script.)Start UFPS
scene.Play the Start UFPS
scene to test it out. After you've confirmed that it's working, you can assign your own dialogue database, dialogue UI, etc. You can save the Start UFPS
scene's Menu System and Dialogue Manager as prefabs and add them to your gameplay scenes for easy playtesting. In your gameplay scenes' copy of the Menu System prefab, deactivate the TitleMenuPanel child GameObject, as was done in Gameplay UFPS
. When using the Menu Framework, in your gameplay scenes add the script FPLockCursorOnStart
to your player.
These instructions explain how to set up the Menu Framework from scratch to work with UFPS.
Dialogue System Extras / Dialogue System Menu Framework / Example
or create your own scenes with the same prefabs in them. The rest of these instructions use the scenes in the Example
folder.Dialogue System Extras / Dialogue System Menu Framework / Example / Start
Dialogue System Extras / Dialogue System Menu Framework / Example / Loading
Dialogue System Extras / Dialogue System Menu Framework / Example / Credits
Dialogue System Extras / Dialogue System Menu Framework / Example / Gameplay
Start
scene.Dialogue System / Third Party Support / UFPS / Scripts / FPSyncLuaPlayerOnLoadLevel
to the Dialogue Manager.Dialogue System / Third Party Support / UFPS / Scripts / PauseUFPS
to Menu System.Dialogue System / Third Party Support / UFPS / Scripts / ForceCursorVisible
if you want the mouse cursor to be visible when returning to the title menu scene. (UFPS hides it by default.)FPLockCursorOnStart
to your player.The example scene uses UFPS features to suspend UFPS gameplay and interact with an NPC to start a conversation, synchronizing UFPS data between UFPS and the Dialogue System.
In this example:
The example scene uses a script ExampleMainMenu.cs to provide a rudimentary main menu. For a more robust menu system, you can use the Dialogue System Menu Template with UFPS. See Set Up the Dialogue System Menu Framework.
The FPPlayer Lua Bridge component makes the following information available in the Lua environment during conversations:
Lua | Description |
---|---|
Actor["Player"].Health | The player's current health. |
Actor["Player"].TotalSpace | The total capacity of the player's inventory. (read-only) |
Actor["Player"].UsedSpace | The current used space in the player's inventory. (read-only) |
Actor["Player"].RemainingSpace | The current remaining space in the player's inventory. (read-only) |
Actor["Player"].CurrentWeaponIndex | The index of the player's currently-equipped weapon. |
Variable["Pistol"], , etc. | (For all weapons defined in the player's vp_Inventory. If the value is 0 or nonexistent, the player does not have the item. If the value is 1 or higher, the player has the item, and the number indicates the amount of ammo. If you set a value during a conversation, the change will be reflected in the UFPS player at the end of the conversation. |
Variable["Pistol_Units"], , etc. | The amount of ammo loaded into each weapon. |
Variable["Bullet"], , etc. | The amount of ammo held by the player (outside of weapons). |
You may want to share additional data between UFPS and the Dialogue System. One way to do this is to put that information in the Dialogue System's Lua environment using the Lua.Run()
method. If you set a user variable using PixelCrushers.DialogueSystem.Lua.Run(), then dialogue entries can check and/or change the value.
For example, NPC conversations can branch based on whom the player has killed, or what UFPS items the player has in his inventory (as is done in FPSync Lua Player On Conversation).
See the example menu script (ExampleMainMenu.cs) for a simple example of how to save and load. In brief, call PersistentDataManager.GetSaveData() to get the saved game data (including UFPS data). Call PersistentDataManager.ApplySaveData() to load a game by feeding previously-saved game data back into the Dialogue System and UFPS state.
If the player can switch between levels in your game, you may want to use the LevelManager script's methods as shown in the example menu script.
If the first scene of your game does not have a UFPS player object and a Dialogue Manager object, you'll have to take an extra step. This is the process:
Whenever a new level is loaded, the FPPlayer Lua Bridge applies the Lua data to UFPS data.
When switching between gameplay levels, the FPPlayer Lua Bridge in the old level saves the UFPS data to Lua. Then the new level applies the Lua data to UFPS.
If your level selection scene does not have an FPPlayer Lua Bridge, it will not save UFPS-->Lua.
To address this, you'll need to add some starting values to the dialogue database. These Lua environment will be initialized with these values.
On the Actors tab, add a field named "Health" to the Player. Change its Type to Number. Set the Value to the player's starting health. In the example below, the player starts with 42% health.
To set the player's current weapon, add a field named "CurrentWeaponIndex". Change its Type to Number. Set it to the weapon index (e.g., 1=Pistol, 2=Revolver, etc.). In the example below, the player's current weapon is 1 (Pistol).
To set the player's inventory, add variables on the Variables tab. In the example below, the player has a Pistol with 11 units loaded, and 38 extra bullets.
The names of the variables are defined above in the Lua Bridge Data section.
Support for the UFPS Mobile-Addon is in the package UFPS Mobile Addon Support
. When you import this package, it will add a Scripts folder and an example folder containing a two-level mobile demo.
IMPORTANT: To be able to switch between levels, you must add 'Mobile Level 1' and 'Mobile Level 2' to the build settings. For the example main menu's Restart Game button to work, you must make 'Mobile Level 1' the first scene in the build settings.
The example uses Unity GUI for the example menu and dialogue UI, but you could implement a dialogue UI using Unity UI, UFPS Mobile's vp_UI, or even NGUI.
The example menu is accessed through the mobile demo's menu. The Dialogue System Menu object (which contains the example menu script) is a child of the Dialogue Manager object.
Follow these steps to set up up the Dialogue System with the UFPS Mobile Addon:
The FPPersistentPlayerData and FPSyncPlayerOnLoadLevel components are only necessary if your player will be switching levels or saving and loading games.
If you're using the Dialogue System's Menu Framework, add this script (ConnectPauseMenu.cs) to the RootUI GameObject, create a menu button, and configure it to call the script's OpenPausePanel method and the RootUI menu's Toggle method.