|
|
|
@ -7,10 +7,16 @@ impl Plugin for EditorPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.init_state::<EditorState>();
|
|
|
|
app.init_state::<EditorState>();
|
|
|
|
app.add_systems(Startup, init_editor);
|
|
|
|
app.add_systems(Startup, init_editor);
|
|
|
|
app.add_systems(Update, toggle_editor.run_if(input_just_pressed(KeyCode::F3)));
|
|
|
|
app.add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
toggle_editor.run_if(input_just_pressed(KeyCode::F3)),
|
|
|
|
|
|
|
|
);
|
|
|
|
app.add_systems(OnEnter(EditorState::Open), open_editor);
|
|
|
|
app.add_systems(OnEnter(EditorState::Open), open_editor);
|
|
|
|
app.add_systems(OnExit(EditorState::Open), close_editor);
|
|
|
|
app.add_systems(OnExit(EditorState::Open), close_editor);
|
|
|
|
app.add_systems(Update, origin_directions.run_if(in_state(EditorState::Open)));
|
|
|
|
app.add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
origin_directions.run_if(in_state(EditorState::Open)),
|
|
|
|
|
|
|
|
);
|
|
|
|
app.add_systems(Update, world_plane.run_if(in_state(EditorState::Open)));
|
|
|
|
app.add_systems(Update, world_plane.run_if(in_state(EditorState::Open)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -27,14 +33,13 @@ enum EditorState {
|
|
|
|
struct Editor;
|
|
|
|
struct Editor;
|
|
|
|
|
|
|
|
|
|
|
|
/// Spawns all base editor entities including window, camera, and UI elements
|
|
|
|
/// Spawns all base editor entities including window, camera, and UI elements
|
|
|
|
fn init_editor(
|
|
|
|
fn init_editor(mut commands: Commands) {
|
|
|
|
mut commands: Commands
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// Spawn root editor entity hierarchy
|
|
|
|
// Spawn root editor entity hierarchy
|
|
|
|
commands.spawn(SpatialBundle { ..default() })
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn(SpatialBundle { ..default() })
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
|
|
|
let editor_window = parent
|
|
|
|
let editor_window = parent.spawn((
|
|
|
|
.spawn((
|
|
|
|
Editor,
|
|
|
|
Editor,
|
|
|
|
Window {
|
|
|
|
Window {
|
|
|
|
title: "Editor".into(),
|
|
|
|
title: "Editor".into(),
|
|
|
|
@ -42,10 +47,12 @@ fn init_editor(
|
|
|
|
visible: false,
|
|
|
|
visible: false,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)).id();
|
|
|
|
))
|
|
|
|
|
|
|
|
.id();
|
|
|
|
|
|
|
|
|
|
|
|
// Spawn editor camera
|
|
|
|
// Spawn editor camera
|
|
|
|
let _editor_camera = parent.spawn((
|
|
|
|
let _editor_camera = parent
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
Editor,
|
|
|
|
Editor,
|
|
|
|
FlyCamera,
|
|
|
|
FlyCamera,
|
|
|
|
Camera3dBundle {
|
|
|
|
Camera3dBundle {
|
|
|
|
@ -53,24 +60,22 @@ fn init_editor(
|
|
|
|
target: RenderTarget::Window(WindowRef::Entity(editor_window)),
|
|
|
|
target: RenderTarget::Window(WindowRef::Entity(editor_window)),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
transform: Transform::from_xyz(1.0, 1.0, 1.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
transform: Transform::from_xyz(1.0, 1.0, 1.0)
|
|
|
|
|
|
|
|
.looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)).id();
|
|
|
|
))
|
|
|
|
|
|
|
|
.id();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn open_editor(
|
|
|
|
fn open_editor(mut ws: Query<&mut Window, With<Editor>>) {
|
|
|
|
mut ws: Query<&mut Window, With<Editor>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
ws.iter_mut().for_each(|mut w| {
|
|
|
|
ws.iter_mut().for_each(|mut w| {
|
|
|
|
w.visible = true;
|
|
|
|
w.visible = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn close_editor(
|
|
|
|
fn close_editor(mut ws: Query<&mut Window, With<Editor>>) {
|
|
|
|
mut ws: Query<&mut Window, With<Editor>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
ws.iter_mut().for_each(|mut w| {
|
|
|
|
ws.iter_mut().for_each(|mut w| {
|
|
|
|
w.visible = false;
|
|
|
|
w.visible = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -93,17 +98,13 @@ fn toggle_editor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn origin_directions(
|
|
|
|
fn origin_directions(mut gizmos: Gizmos) {
|
|
|
|
mut gizmos: Gizmos
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::X, Color::RED);
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::X, Color::RED);
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::Y, Color::GREEN);
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::Y, Color::GREEN);
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::Z, Color::BLUE);
|
|
|
|
gizmos.arrow(Vec3::ZERO, Vec3::Z, Color::BLUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn world_plane(
|
|
|
|
fn world_plane(mut gizmos: Gizmos) {
|
|
|
|
mut gizmos: Gizmos
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
(-10..=10).into_iter().for_each(|x| {
|
|
|
|
(-10..=10).into_iter().for_each(|x| {
|
|
|
|
(-10..=10).into_iter().for_each(|z| {
|
|
|
|
(-10..=10).into_iter().for_each(|z| {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|