pub trait AddScriptHostHandler {
    // Required methods
    fn add_script_handler<T: ScriptHost, const MAX: u32, const MIN: u32>(
        &mut self,
        schedule: impl ScheduleLabel
    ) -> &mut Self;
    fn add_script_handler_to_set<T: ScriptHost, const MAX: u32, const MIN: u32>(
        &mut self,
        schedule: impl ScheduleLabel,
        set: impl SystemSet
    ) -> &mut Self;
}

Required Methods§

source

fn add_script_handler<T: ScriptHost, const MAX: u32, const MIN: u32>( &mut self, schedule: impl ScheduleLabel ) -> &mut Self

Enables this script host to handle events with priorities in the range [0,min_prio] (inclusive), during from within the given set.

Note: this is identical to adding the script_event_handler system manually, so if you require more complex setup, you can use the following:

self.add_systems(
    MySchedule,
    script_event_handler::<T, MAX, MIN>
);

Think of event handler systems as event sinks, which collect and “unpack” the instructions in each event every frame. Because events are also prioritised, you can enforce a particular order of execution for your events (within each frame) regardless of where they were fired from.

A good example of this is Unity game loop’s onUpdate and onFixedUpdate. FixedUpdate runs before any physics while Update runs after physics and input events.

In this crate you can achieve this by using a separate system set before and after your physics, then assigning event priorities such that your events are forced to run at the points you want them to, for example:

PrePhysics priority range [0,1] PostPhysics priority range [2,4]

PriorityHandlerEvent
0PrePhysicsStart 0
1PrePhysicsFixedUpdate 1
2PostPhysicsOnCollision 2
3PostPhysicsOnMouse 3
4PostPhysicsUpdate 4

Note: in this example, if your FixedUpdate event is fired after the handler system set has run, it will be discarded (since other handlers discard events of higher priority).

source

fn add_script_handler_to_set<T: ScriptHost, const MAX: u32, const MIN: u32>( &mut self, schedule: impl ScheduleLabel, set: impl SystemSet ) -> &mut Self

The same as add_script_handler but allows you to specify a system set to add the handler to.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl AddScriptHostHandler for App

source§

fn add_script_handler_to_set<T: ScriptHost, const MAX: u32, const MIN: u32>( &mut self, schedule: impl ScheduleLabel, set: impl SystemSet ) -> &mut Self

source§

fn add_script_handler<T: ScriptHost, const MAX: u32, const MIN: u32>( &mut self, schedule: impl ScheduleLabel ) -> &mut Self

Implementors§