Creating Contexts
Adjustments are separated into contexts, each context gets it's own tab in the UI.
Contexts can be registered or unregistered on demand, so you can keep your options "context-aware", for example, you might have one context that is only active in your main menu, and another one during gameplay. This way you can keep your adjustments organized and not clutter the UI with options that are not relevant.
You can create a context either at development time, by using attributes, or at runtime, by using the provided builder to create it dynamically.
Method 1: Attribute-Based
Mark fields, properties, or methods with [Adjust] attributes:
using UnityEngine;
using DBY.Modules.Adjust.Attributes;
public class PlayerController : MonoBehaviour
{
// Basic attribute - works with any supported type
[Adjust]
public float moveSpeed = 5f;
// Integer with slider
[AdjustInt(Name = "Player Health", Min = 0, Max = 100, IsSlider = true)]
public int health = 100;
// Float with bounds and custom page size
[AdjustFloat(Min = 0f, Max = 10f, PageSize = 0.5f)]
public float jumpForce = 7f;
// Method as a button
[AdjustAction("Reset Player", DebbyIcon.Trash)]
public void ResetToStart()
{
transform.position = Vector3.zero;
health = 100;
}
}TIP
For a full list of supported attributes and their options, see the Attributes documentation.
And register the context when it's needed. You can also tie the lifetime of a context to a GameObject, so it will be automatically unregistered when the GameObject is destroyed.
// Register this instance with Debby
Debby.Adjust.RegisterContext(this, "Player", gameObject);
// Register by type (instance is created automatically)
Debby.Adjust.RegisterContext<PlayerController>("Player");
// Unregister (if needed)
Debby.Adjust.UnregisterContext(this);
Debby.Adjust.UnregisterContext<PlayerController>();Method 2: Builder Pattern
You can also create contexts dynamically using the provided builder, and the AdjustableValue wrapper class.
private AdjustableValue<int> _score;
Debby.Adjust.NewContext("Game Settings", gameObject)
.AddValue("Score", _score, new(min: 0, max: 100))
.AddValue("Time Scale", new AdjustableValue<float>(
() => timeScale,
v => Time.timeScale = timeScale = v))
.AddAction("Add 100 Score", () => score += 100)
.Build();