Events and Callbacks
The QuantumConsole
component provides various event callbacks that can be subscribed to, allowing you to add your own behaviour into the console without modifying it.
Name | Signature | Description |
---|---|---|
OnStateChange |
Action |
Executed when the QC state changes. |
OnInvoke |
Action<string> |
Executed when the QC invokes a command. |
OnClear |
Action |
Executed when the QC is cleared. |
OnLog |
Action<ILog> |
Executed when text has been logged to the QC. |
OnActivate |
Action |
Executed when the QC is activated. |
OnDeactivate |
Action |
Executed when the QC is deactivated. |
Examples
The following example demonstrates how to perform some desired behaviour when QC is activated and deactivated.
using QFSW.QC;
using UnityEngine;
// This script will attempt to find the QuantumConsole component to subscribe to in the following order
// 1. The assigned _qc value
// 2. An instance of QuantumConsole on the same object
// 3. A singleton QuantumConsole instance in the scene
public class QCEventHooks : MonoBehaviour
{
[SerializeField] QuantumConsole _qc;
void Start()
{
_qc = _qc
?? GetComponent<QuantumConsole>()
?? QuantumConsole.Instance;
if (_qc)
{
_qc.OnActivate += OnActivate;
_qc.OnDeactivate += OnDeactivate;
}
}
void OnActivate()
{
Debug.Log("QC Activated");
}
void OnDeactivate()
{
Debug.Log("QC Deactivated");
}
}