starterkit-binder-authoring
Skill65 starsChanged 19 days agoMITView on GitHub
How to write a new Aspid.MVVM StarterKit binder correctly the first time — choosing a base (`ComponentMonoBinder`, `ComponentFloat/Int/ObjectMonoBinder`, `EnumMonoBinder`, `EnumGroupMonoBinder`, `SwitcherMonoBinder`, `CasterMonoBinder`, `*ToSourceMonoBinder`), the serializable twin via `[GenerateSerializableBinder]`, `AddComponentMenu`/`AddBinderContextMenu`, value validation through `BinderMath`/`BinderLogger`, `null` semantics, missing `IBinder<T>` implementations, the standard five-point binder review. Use when creating, reviewing or reworking any binder in `StarterKit/Runtime/Binders`, when the user asks to "add a binder", "make a family for property X", or sends a binder file.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- asp-branchSkill
- asp-commitSkill
- aspid-code-styleSkill
- asp-mvvm-releaseSkill
- asp-prSkill
- docs-siteSkill
- starterkit-converter-authoringSkill
- starterkit-layoutSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
Add IColorBinder, IVectorBinder, IRotationBinder (General/Color, General/Vector, General/Rotation) to color/vector/rotation binders so they …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
StarterKit binder
General style: skill aspid-code-style; placement: starterkit-layout; docs: asp-xmldoc. This skill covers only what is specific to binders.
Binder review (standing routine for any binder the user sends)
- Briefly: what the binder is for.
- Bugs and shortcomings, including missing
IBinder<T>implementations (a value binder may accept one more type). //comments: delete the unnecessary ones entirely, shorten the rest.[Tooltip]: short, on all serialized fields without exception.- XML docs:
<remarks>only where it is needed.
Apply the fixes immediately; do not end with "shall I apply?".
A family for a component property
For Component.property there are usually four Mono classes in one subfolder (Binders/<Component>/<Property>/):
| Class | Base | Purpose |
XxxPropertyMonoBinder | ComponentMonoBinder<TComponent, TValue> or the typed ComponentFloatMonoBinder<T> / ComponentIntMonoBinder<T> / ComponentObjectMonoBinder<T, TObject> | direct binding, [GenerateSerializableBinder] |
XxxPropertySwitcherMonoBinder | SwitcherMonoBinder<TComponent, TValue> | two values chosen by bool |
XxxPropertyEnumMonoBinder | EnumMonoBinder<TComponent, TValue> | value by enum |
XxxPropertyEnumGroupMonoBinder | EnumGroupMonoBinder<TElement, TValue> | group of elements, SetValue(element, value) |
Plus XxxToSourceMonoBinder (ComponentToSourceMonoBinder) at the root of the component folder when the property is read back into the ViewModel.
- A
UnityEngine.Objectvalue (Material,AudioClip,Mesh,Sprite) →ComponentObjectMonoBinder, notComponentMonoBinder<T, Material>: the generator then gives the serializable twin aTargetObjectBinder. float/int→ComponentFloatMonoBinder/ComponentIntMonoBinder: they provideINumberBinderand the whole numeric family. A shared base must never narrow the interfaces of its subclasses.- A Switcher accepts
boolonly: do not derive it fromTargetBinder<TTarget, T>and do not addIBinder<T>. Reuse the selection logic through a closed[SerializeField] BoolToValueConverter<T>. - Add
IColorBinder,IVectorBinder,IRotationBinder(General/Color,General/Vector,General/Rotation) to color/vector/rotation binders so they accept strings,Color32,Vector2/3/4,Quaternion/Euler.
Skeleton
using UnityEngine;
// ReSharper disable once CheckNamespace
namespace Aspid.MVVM.StarterKit
{
/// <summary>
/// <see cref="ComponentFloatMonoBinder{TComponent}"/> that binds <see cref="AudioSource.volume"/>.
/// </summary>
/// <remarks>
/// The value is clamped to 0..1.
/// </remarks>
[GenerateSerializableBinder]
[AddBinderContextMenu(typeof(AudioSource), serializePropertyNames: "m_Volume")]
[AddComponentMenu("Aspid/MVVM/Binders/Audio/AudioSource/AudioSource Binder – Volume")]
public class AudioSourceVolumeMonoBinder : ComponentFloatMonoBinder<AudioSource>
{
/// <inheritdoc/>
protected sealed override float Property
{
get => CachedComponent.volume;
set => CachedComponent.volume = this.SafeClamp01(value);
}
}
}- A
MonoBehaviourfile has no#nullable enableand no?annotations. - Attribute order:
GenerateSerializableBinder→AddBinderContextMenu→AddComponentMenu. Switcher/Enum/EnumGroup variants are not generated and setSubPath = "Switcher"|"Enum"|"EnumGroup"inAddBinderContextMenuinstead. serializePropertyNameslists Unity's serialized property names (m_Volume,m_Color,m_Sprite) so the context menu appears on the right Inspector field.AddComponentMenu:Aspid/MVVM/Binders/<Area>/<Component>/<Component> Binder – <Property>[ <Variant>]. One path per component (Audio/AudioSource/for all of them, includingIsPlaying/PlayOneShot).- A class with
[GenerateSerializableBinder]is notsealedand needs nopartial; a non-generated class that is not a base issealed. - A concrete binder overrides only
Property(orSetValue); checks and logging live inside the setter.
Values and errors
- Validation is never silent:
BinderMath.SafeClamp/SafeClamp01/NonNegative/RequireFinitelog throughBinderLoggerand substitute the nearest valid value. No quietif (!IsFinite(value)) return;. - A helper that sanitizes a value takes the caller (
this IBinderorType binderType) instead of being a free static. - A field with
[Range(0, 1)]in the Inspector gets no duplicate runtime clamp for the same condition. nullfrom the ViewModel means reset the state (clear the list,default, hide), not an earlyreturn. An earlyreturnis acceptable only when there is nothing to reset, and<remarks>says why.- A value outside the target type's range saturates (
NumericSaturation); the reverse channel (*ToSource) raises all numeric events the same way. - Errors are logged on every occurrence, without "already logged" flags. Error texts: one or two short phrases.
- Switcher variants clamp in
SetValue, not inGetConvertedValue.
Converter inside a binder
- The slot is
[SerializeReference] private IConverter<TFrom, TTo> _converter;without[TypeSelector](StarterKitTypePickerDrawersupplies the picker). A required slot:LogErrorand skip when empty; default throughCreateDefaultConverter()inReset/OnValidate(seeCasterMonoBinder). - The type of a serialized factory or converter is not lifted into a class generic parameter: the field is typed by the interface directly (
IViewFactory<TView>). - Casters derive from
CasterMonoBinder<TFrom, TTo>;AnyToStringCasterMonoBinderstays separate (genericSetValue<T>fromIAnyBinder).
Serializable (non-Mono) binders
- Generated from the Mono class via
[GenerateSerializableBinder]; only bases (Binder,TargetBinder,SwitcherBinder,DelegateXxxBinder) and binders without a Mono twin are written by hand. - A hand-written serializable binder:
[Serializable], aprotectedconstructor for deserialization, multi-parameter constructors one parameter per line,Objectparameters rather thanGameObject,CanBindon an empty reference in the Mono version. - Collection bases handle a multi-element
Replacewith a loop, notNotImplementedException; replacing a ViewModel = release + create,DeinitializebeforeRelease.
Serialized fields
[Tooltip]on every one, short; the caveat is repeated in the<param>of the serializable twin's constructor.[Min]/[Range]wherever the value can become invalid; consistent with the constructor exception and the Tooltip.- A field used only in some bind modes:
[UsedInModes(BindMode.…)]. - No
= default!, no[FormerlySerializedAs].
Documentation
Docs/docs/StarterKit/README.mdand the family's*-binders.md(with therutwins inDocs/i18n/ru/docusaurus-plugin-content-docs/current/StarterKit/): one row per binder, the modes column includesOneWayToSource, a ranges/clamps table where applicable.- The binder
<summary>is one line:<see cref="Base{T}"/> that binds <see cref="Component.property"/>.; cref generic bases by their parameter names, never{Graphic, Color}.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

