Add Settings to Layer
Setting Requirements
Properties within your layers, which you would like to define as setting, must have a public getter and setter. Only the following setting types are currently supported.
int
float
bool
SKColor
enum
Value Setting
You can define manual settings by adding the LayerSettingAttribute
to the corresponding property within the layer. Let's
say, we would like to create a color fill effect layer, which fills the canvas with a configurable color.
[EffectLayer(Name = "Color Fill")]
public class FillBasicColorLayer : PixelEffectLayerBase
{
[LayerSetting]
public SKColor Color { get; set; } = DefaultValues.PrimaryColor;
public FillBasicColorLayer(IExtensionApi api, int canvasWidth, int canvasHeight)
: base(api, canvasWidth, canvasHeight)
{
}
protected override SKColor RenderPixel() => Color;
}
Info
Remember to initialize node setting properties with a reasonable default value.
Bindable Setting
If you want to allow a user to bind a node network to your layer setting, then you can make it bindable by using the
BindableLayerSettingAttribute
. Currently, the following types are supported for bindings.
float
bool
SKColor
Here is the same example as above, but this time, the user can bind a node network to the color setting.
[EffectLayer(Name = "Color Fill")]
public class FillBasicColorLayer : PixelEffectLayerBase
{
[BindableLayerSetting]
public SKColor Color { get; set; } = DefaultValues.PrimaryColor;
public FillBasicColorLayer(IExtensionApi api, int canvasWidth, int canvasHeight)
: base(api, canvasWidth, canvasHeight)
{
}
protected override SKColor RenderPixel() => Color;
}
Trigger Setting
A trigger setting is a bindable boolean layer setting, however, in contrast to a simple boolean flag, the purpose of this setting is the ability to be triggered. The user can achieve this manually by clicking on the trigger button in the UI, or based on a node network that has been bound to this setting.
Here is an example effect layer, which changes the canvas color on every trigger input.
[EffectLayer(Name = "Random Color Fill")]
public class RandomBasicColorLayer : PixelEffectLayerBase
{
private readonly Random _random = new();
private SKColor _color = SKColors.Black;
[TriggerLayerSetting(nameof(OnTriggered))]
public bool Trigger { get; set; }
public RandomBasicColorLayer(IExtensionApi api, int canvasWidth, int canvasHeight)
: base(api, canvasWidth, canvasHeight)
{
}
protected override SKColor RenderPixel() => _color;
private void OnTriggered(bool value)
{
if (value)
_color = SKColor.FromHsv(_random.Next(360), 255, 255);
}
}
Enumeration Setting
If your node setting property is an enumeration type, Audectra will automatically create a list of available options from the enumeration from which the user can choose one.