Let a behavior run while the editor is open
A behavior object carries a "Run in editor" switch next to Enabled. When it is on, the behavior ticks outside of Play and works on the saved model directly - Unity semantics: what it moves is a real change, autosaved and not undoable. Input stays with the editor, so On key never fires while typing. The editor run never bakes placed containers into the model, since that would silently drop their instanceEdits. syncToModel reports whether it wrote anything, and the dirty flag is only raised on change - otherwise a behavior moving something every frame would trigger ~60 saves a second.
This commit is contained in:
1 parent
c74037b6e1
commit
8f31afac37
21 files changed
+718
-35
No files matched your search
@@ -41,6 +41,11 @@ export class BehaviorSystem implements System {
|
||||
private readonly input: Input,
|
||||
/** Source of this frame's collision events; null = no collision detection. */
|
||||
private readonly collisions: CollisionSystem | null = null,
|
||||
/**
|
||||
* Which behaviors this system is responsible for. Playing runs them all; the editor run
|
||||
* takes only those marked "run in editor" (see `properties/editorRun.ts`).
|
||||
*/
|
||||
private readonly shouldRun: (entity: Entity) => boolean = () => true,
|
||||
) {}
|
||||
|
||||
start(world: World): void {
|
||||
@@ -66,6 +71,7 @@ export class BehaviorSystem implements System {
|
||||
if (
|
||||
entity.type !== 'behavior' ||
|
||||
!isHandleEnabled(entity) ||
|
||||
!this.shouldRun(entity) ||
|
||||
this.instances.some((i) => i.entity === entity)
|
||||
)
|
||||
continue;
|
||||
@@ -89,6 +95,7 @@ export class BehaviorSystem implements System {
|
||||
for (const instance of this.instances) {
|
||||
if (!world.entities.includes(instance.entity)) continue; // destroyed during play
|
||||
if (!isHandleEnabled(instance.entity)) continue; // switched off (itself or a parent)
|
||||
if (!this.shouldRun(instance.entity)) continue; // "run in editor" taken back while running
|
||||
this.run(
|
||||
instance,
|
||||
(i, ctx) => {
|
||||
@@ -141,6 +148,11 @@ export class BehaviorSystem implements System {
|
||||
fire('OnCollisionExit', this.collisions.exits);
|
||||
}
|
||||
|
||||
/** Object ids of the behaviors this system is currently running. */
|
||||
runningIds(): string[] {
|
||||
return this.instances.map((i) => i.entity.objectId);
|
||||
}
|
||||
|
||||
/** Live highlight data for the graph editor: merged over all instances of the asset. */
|
||||
traceFor(assetId: string): Trace {
|
||||
const merged: Trace = { edges: new Map(), nodes: new Map() };
|
||||
|
||||
Reference in new issue
Block a user