Custom Debug Components
Custom Debug components inherit from BaseDebugComponent.
BaseDebugComponent handles the details of interfacing with the PlayMakerDebug system:
- The component has the standard editor UI for anchoring etc.
- The component respects global PlayMaker Debug settings.
- The editor automaticaly handles editing of debug settings.
A minimal debug component looks like this:
using UnityEngine.UIElements;
using HutongGames.PlayMaker;
namespace MyNamespace
{
public class CustomDebug : BaseDebugComponent
{
protected override void UpdateDebugPanel()
{
Panel.Clear();
Panel.Add(new Label("HELLO WORLD!"));
}
}
}
Building the Debug Panel
If you need to update the panel frequently, it's more efficient to build the UI once in BuildDebugPanel and update it in UpdateDebugPanel:
using UnityEngine.UIElements;
using HutongGames.PlayMaker;
namespace MyNamespace
{
public class CustomDebug : BaseDebugComponent
{
private Label _label;
protected override void BuildDebugPanel()
{
_label = new Label();
Panel.Add(_label);
}
protected override void UpdateDebugPanel()
{
_label.text = "HELLO!";
}
}
}
Updating the Debug Panel
You can use any MonoBehaviour event to update the debug panel.
For example, use LateUpdate to update a continously changing value:
using UnityEngine.UIElements;
using HutongGames.PlayMaker;
namespace MyNamespace
{
public class CustomDebug : BaseDebugComponent
{
private Label _label;
protected override void BuildDebugPanel()
{
_label = new Label();
Panel.Add(_label);
}
protected override void UpdateDebugPanel()
{
_label.text = UnityEngine.Time.realtimeSinceStartup.ToString("0.00");
}
private void LateUpdate()
{
UpdateDebugPanel();
}
}
}
Custom Editors
Custom editors for your component should inherit from BaseDebugComponentEditor.
BaseDebugComponentEditor handles the core setup, and you can add the controls you need.
For example, the DebugFsmEditor looks like this:
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace HutongGames.PlayMaker.Editor
{
/// <summary>
/// Add DebugFsm controls to the base inspector.
/// </summary>
[CustomEditor(typeof(DebugFsm))]
public class DebugFsmEditor : BaseDebugComponentEditor
{
public override VisualElement CreateInspectorGUI()
{
var root = base.CreateInspectorGUI();
// Insert the FsmComponent field at the top
root.Insert(0, new PropertyField(serializedObject.FindProperty(DebugFsm.FsmComponentProp)));
// Add toggles next to the anchor grid
AddDebugToggle(DebugFsm.ShowTitleProp);
AddDebugToggle(DebugFsm.ShowActiveStateProp);
AddDebugToggle(DebugFsm.ShowWatchedVariablesProp);
return root;
}
}
}