Vixen
02b45cc4
csharp
public sealed class BehaviorBridge

A behaviour, as the component panel's idea of a component.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The seam that makes a Behavior authorable, and it is one class because the panel above it only knows IComponentBridge. The Add Component menu, the foldouts, the drawers, the remove button and the drag-to-reorder all work on a behaviour with nothing added to any of them — which is the whole return on that interface having existed before there was a second kind of thing to put behind it.

⚠ Read hands back a copy, which is what lets everything above stay one code path. A component is a struct, so reading one out of a chunk gives the panel a box it can edit freely and write back as a single SetComponentCommand. A behaviour is a class, and a panel handed the live instance would edit the very object it was about to record as the "before" — so every undo would restore what the edit had already changed, which is to say no undo at all. Copying at the read makes the two kinds indistinguishable from here up, down to sharing the command.

⚠ The consequence is that editing a behaviour replaces the instance on the entity. Nothing in an editor holds a reference to one — the lifecycle is not running, which is SceneDocument.Behaviors' point — so identity is not something anything here can observe. It would be in play mode, which runs against a store of its own.

⚠ The store is the document's, not the world's. IComponentBridge is written in terms of a World because a component lives in one; a behaviour lives in a BehaviorStore beside it, so this closes over the document's. A bridge is therefore per-document rather than per-process, which is the one way behaviours differ from components in how the editor holds them.

Fields and properties (4)

  • public AuthoringKind Kind

    Which of the two kinds of authoring unit this is.

  • public string Name

    What it is called in a file: the serializer's alias, and its identity here.

  • public string DisplayName

    What a person reads: the foldout's title and the Add Component menu's line.

  • public Type ComponentType

    The CLR type, which is what the rows are drawn from.

Methods (6)

  • public BehaviorBridge(ISceneBehaviorBinder binder, Func<BehaviorStore?> store)

    Wraps a registered behaviour.

  • public bool Has(World world, Entity entity)

    Whether an entity carries one.

  • public object Read(World world, Entity entity)

    Reads it off an entity, boxed.

  • public void Write(World world, Entity entity, object value)

    Puts a value on an entity, adding the component if it is not there.

  • public object Create()
  • public bool Remove(World world, Entity entity)

    Takes it off an entity.

Used by (1)

  • RegisteredVixen.Editor.App