add example
This commit is contained in:
parent
8d583642e9
commit
9438fa62bc
2 changed files with 28 additions and 0 deletions
3
assets/examples/ruby/current_entity.rb
Normal file
3
assets/examples/ruby/current_entity.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
get_name(Bevy::Entity.current).and_then do |name|
|
||||
print(name)
|
||||
end
|
||||
25
examples/ruby/current_entity.rs
Normal file
25
examples/ruby/current_entity.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_scripting::<RubyRuntime>(|runtime| {
|
||||
runtime.add_function(
|
||||
String::from("get_name"),
|
||||
|In((BevyEntity(entity),)): In<(BevyEntity,)>, names: Query<&Name>| {
|
||||
names.get(entity).unwrap().to_string()
|
||||
},
|
||||
);
|
||||
})
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn((
|
||||
Name::from("MyEntityName"),
|
||||
Script::<RubyScript>::new(assets_server.load("examples/ruby/current_entity.rb")),
|
||||
));
|
||||
}
|
||||
Loading…
Reference in a new issue