from pybevy.prelude import *
@plugin
class PrintMessagePlugin(Plugin):
def __init__(self, wait_duration: float, message: str):
super().__init__()
self.wait_duration = wait_duration
self.message = message
def build(self, app: App) -> None:
state = PrintMessageState(
message=self.message,
timer=Timer(self.wait_duration, TimerMode.REPEATING)
)
app.insert_resource(state)
app.add_systems(Update, print_message_system)
@resource
class PrintMessageState(Resource):
def __init__(self, message: str, timer: Timer):
self.message = message
self.timer = timer
def print_message_system(state: ResMut[PrintMessageState], time: Res[Time]) -> None:
state.timer.tick(time.delta_secs())
if state.timer.is_finished():
print(state.message)
@entrypoint
def main(app: App) -> App:
return (
app.add_plugins(DefaultPlugins)
.add_plugins(PrintMessagePlugin(
wait_duration=1.0,
message="This is an example plugin"
))
)
if __name__ == "__main__":
main().run()