Class TextModeTerminalHost
Places a TextModeTerminal in a scene: it builds the terminal from the settings on the component when the scene starts, updates it every frame and destroys it with the component.
Implements
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
[DisallowMultipleComponent]
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("Scylla/TextMode/TextMode Terminal")]
public sealed class TextModeTerminalHost : MonoBehaviour, ITextModeViewHost
Remarks
Add it to a RectTransform under a Canvas. The terminal fills the RectTransform, minus the padding in its settings. With FillPadding on, which is the default, the host fills the padding with the terminal's background color; off, the padding is transparent. The terminal and its view only exist in Play mode; in the editor the component holds the settings. Game code reaches the running terminal through Terminal.
In Log mode with the command line enabled in the settings, the host reads the keyboard into the command line and reports each submitted command through CommandSubmitted and the Command Submitted event in the Inspector. Write the answer with AppendLine(string, Color32).
In FullScreen mode the host does not read the keyboard, because what a key means depends on the program behind the terminal. Feed the program's output with Feed(string), and encode the player's keys with TerminalInputEncoder.
ColorTheme decides where the colors come from. By default the terminal takes its colors, its background included, from the project theme set on the TextMode configuration, and follows it when it changes. A terminal can keep a theme of its own instead, named in its settings, or use the colors in its settings without a theme.
The terminal is built in Awake from the settings on the component, so the start
mode, the color theme and the settings have to be in place before then. To add a host
from code, add it to an inactive GameObject, set it up, and then activate the GameObject.
After the terminal is built, Settings and FontAsset still
apply, while StartMode and ColorTheme do not.
The host updates the terminal from the first frame, also before the TextMode module has started, and stops once the module has started and is disabled. Disabling the component hides the terminal, and enabling it shows the terminal again.
The following example answers every command typed into a log mode terminal.
host.CommandSubmitted += command =>
{
host.Terminal.AppendLine($"You typed {command}.", new Color32(255, 200, 0, 255));
};
Properties
ColorTheme
Gets or sets where the terminal takes its colors from. Changing it after the terminal has started has no effect.
Declaration
public TextModeTerminalColorTheme ColorTheme { get; set; }
Property Value
| Type | Description |
|---|---|
| TextModeTerminalColorTheme |
Remarks
With a theme, the host replaces the background color in the settings with the theme's when it builds the terminal, because the terminal leaves a transparent background transparent, and a terminal with nothing opaque behind it shows whatever the screen held before. With Project it also replaces the theme name with the active project theme's. Own uses the theme named in ThemeName.
FocusCommandLine
Gets or sets whether the command line takes keyboard input as soon as the terminal starts.
Declaration
public bool FocusCommandLine { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
FontAsset
Gets or sets the font. Setting it while the terminal runs switches the terminal's font.
Declaration
public TMP_FontAsset FontAsset { get; set; }
Property Value
| Type | Description |
|---|---|
| TMP_FontAsset |
Settings
Gets or sets the terminal settings. Setting them while the terminal runs applies them to the terminal.
Declaration
public TextModeTerminalSettings Settings { get; set; }
Property Value
| Type | Description |
|---|---|
| TextModeTerminalSettings |
StartMode
Gets or sets the mode the terminal starts in. Changing it after the terminal has started has no effect; use SwitchToFullScreen() and SwitchToLogMode() instead.
Declaration
public TextModeTerminalStartMode StartMode { get; set; }
Property Value
| Type | Description |
|---|---|
| TextModeTerminalStartMode |
Terminal
Gets the running terminal, or null outside Play mode and before the component has started.
Declaration
public TextModeTerminal Terminal { get; }
Property Value
| Type | Description |
|---|---|
| TextModeTerminal |
View
Gets the terminal's view, or null while there is no running terminal.
Declaration
public UITextModeView View { get; }
Property Value
| Type | Description |
|---|---|
| UITextModeView |
Events
CommandSubmitted
Raised with the text of each command submitted on the command line, after the Command Submitted event set up in the Inspector.
Declaration
public event Action<string> CommandSubmitted
Event Type
| Type | Description |
|---|---|
| Action<string> |