-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity Inspector | First Iteration #81
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Open
Could use bevyengine/bevy#13563. Likely not in its current state as it uses a http server but I could build off of it or recreate something similar but for JS export values. |
Useful playground code use bevy::prelude::*;
use bevy::log::LogPlugin;
fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins.set(LogPlugin {
filter: "info,wgpu_core=warn,wgpu_hal=warn,mygame=debug,extra_app_code=info".into(),
..default()
}))
.add_systems(Startup, setup)
.add_systems(Update, change_clear_color)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), Name::new("Cool Camera")));
info!("Here is some info");
warn!("Here is a warning");
error!("Here is an error");
}
fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>, mut state: Local<bool>) {
if input.just_pressed(KeyCode::Space) {
info!("Changing color");
*state = !*state;
if *state {
clear_color.0 = Color::srgb(0.0, 1.0, 0.0);
} else {
clear_color.0 = Color::srgb(0.0, 0.0, 1.0);
}
}
} |
Another code snippet for testing use bevy::prelude::*;
fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, change_clear_color)
.register_type::<MyComp>()
.register_type::<MyObj>()
.run();
}
#[derive(Component, Reflect)]
#[reflect(Component)]
struct MyComp {
string: String,
number: i32,
boolean: bool,
obj: MyObj,
arr: Vec<i32>,
}
#[derive(Reflect)]
struct MyObj {
str2: String,
num2: f32,
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(MyComp {
string: "Hello".to_string(),
number: 123,
boolean: true,
obj: MyObj {
str2: "World".to_string(),
num2: 321.0,
},
arr: vec![5, 10, 20, 40, 80, 160],
});
info!("Here is some info");
warn!("Here is a warning");
error!("Here is an error");
}
fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>, mut state: Local<bool>) {
if input.just_pressed(KeyCode::Space) {
info!("Changing color");
*state = !*state;
if *state {
clear_color.0 = Color::srgb(0.0, 1.0, 0.0);
} else {
clear_color.0 = Color::srgb(0.0, 0.0, 1.0);
}
}
} |
Anotha one //! A Bevy app that you can connect to with the BRP and edit.
use bevy::{
input::common_conditions::input_just_pressed,
prelude::*,
time::common_conditions::on_timer,
};
use std::time::Duration;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, remove.run_if(input_just_pressed(KeyCode::Space)))
.add_systems(Update, move_cube.run_if(on_timer(Duration::from_secs(1))))
.register_type::<Cube>()
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// circular base
commands.spawn((
Mesh3d(meshes.add(Circle::new(4.0))),
MeshMaterial3d(materials.add(Color::WHITE)),
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
));
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(0.0, 0.5, 0.0),
Cube(1.0),
));
// light
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
fn move_cube(mut query: Query<&mut Transform, With<Cube>>) {
for mut transform in &mut query {
if transform.translation.y < 1.0 {
transform.translation.y = 1.5;
} else {
transform.translation.y = 0.5;
};
}
}
fn remove(mut commands: Commands, query: Query<Entity, With<Cube>>) {
commands.entity(query.single()).remove::<Cube>();
}
#[derive(Component, Reflect)]
#[reflect(Component)]
struct Cube(f32); |
For testing perf use bevy::{
input::common_conditions::input_just_pressed,
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, remove.run_if(input_just_pressed(KeyCode::Space)))
.add_systems(Update, move_cube)
.register_type::<Cube>()
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// circular base
commands.spawn((
Mesh3d(meshes.add(Circle::new(4.0))),
MeshMaterial3d(materials.add(Color::WHITE)),
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
));
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(0.0, 0.5, 0.0),
Cube(1.0),
));
// light
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
fn move_cube(mut query: Query<&mut Transform, With<Cube>>, time: Res<Time>) {
for mut transform in &mut query {
transform.translation.y = -time.elapsed_seconds().cos() + 1.5;
}
}
fn remove(mut commands: Commands, query: Query<Entity, With<Cube>>) {
commands.entity(query.single()).remove::<Cube>();
}
#[derive(Component, Reflect)]
#[reflect(Component)]
struct Cube(f32); |
Going to split this out in to multiple PRs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Things to keep in mind
Entity (3v1)
or similar