rewin123 / space_editor

bevy prefab editor
MIT License
383 stars 47 forks source link

space_editor: The Bevy Prefab Editor

License: MIT codecov

Editor in Edit Mode

Editor in edit mode

Editor in Play Mode

Editor in play mode

space_editor is useful tool for scene/prefab/prototyping with bevy engine. Its allow to create/modify levels/scenes/prefabs in fast gui based way.

Project goal

Aspires to be editor for bevy while there is no official editor.

Core Team

Main features

Getting Started To run the editor, use the following command:

cargo run

To run platformer example, use the following command:

cargo run run --example platformer --features bevy_xpbd_3d

Usage

Space editor comes with 2 binaries:

  1. space_editor, the default application, which can be executed with cargo run -r. This is the game editor for bevy engine.
  2. game_app, a simple game that can be used to generate your own game application. This can be executed with cargo run -r --bin game_app. All the logic for this is located in folder game/.

Add all your game logic to the game folder lib.rs, under GamePlugin plugin to have it reflected in space_editor.

Forking strategy

To allow users to get latest updates from space_editor, the suggested workflow is:

  1. Fork the project.
  2. Rename game_app to your projects name and configure space_editor as you prefer.
  3. Create a branch for space_editor's downstream.
  4. Regularly sync the changes from your desired space_editor branch.
  5. Sync your downstream branch with your local main branch.
  6. Code your game in game/ folder.
  7. Store your assets in the assets folder.

Upstream to space_editor

If you have made some nice new feature, fixed a bug on space editor or any other contribution that you feel might be relevant, all PRs are welcomed!

Usage - As Game Plugin

The following explains how to integrate space_editor as a game plugin to use the created prefabs in your game.

Cargo

Add this line to your Cargo.toml file

space_editor = {git = "https://github.com/rewin123/space_editor.git"}

Prefab spawn system

To utilize the prefab spawn system, simply add the plugin to your application as follows:

App::default()
    .add_plugins(DefaultPlugins)
    .add_plugins(PrefabPlugin)

For spawning, use the PrefabBundle:

 commands.spawn(PrefabBundle::new("cube.scn.ron"))
        .insert(Name::new("Prefab"));

(More code at examples/spawn_prefab.rs)

Customization

More detailed information in docs/README.md

Custom types can be added to the editor gui and prefab spawn system with just a single line:

use editor::prelude::EditorRegistryExt;

app.editor_registry::<Name>();

The representation of components in the editor UI can also be customized by bevy_inspector_egui library.

Events

Custom Events can be added to the editor UI with the following:

#[derive(Event, Default, Resource, Reflect, Clone)]
#[reflect(Resource)]
pub struct Name;

use editor::prelude::EditorRegistryExt;

app.editor_registry_event::<Name>();

One limitation is that events must implement Event, Default, Resource, Reflect, Clone, with Resource reflected. Once registered, events can be sent using the Event Dispatcher tab.

Obs: editor already handles internally objects registration and initialization:

register_type::<T>() and init_resource::<T>()

To disable this, use feature no_event_registration.

Prefab

A prefab is simply a Bevy scene serialized to a readable and editable RON format. However, it needs to be spawned through PrefabBundle to activate custom logic such as adding global transforms to an object.

More documentation can be found at the docs folder

2D Mode support

SpaceEditor can handle most 2D bevy elements, such as 2D Camera, 2D meshes and Sprites.

Game mode can be changed between 3D and 2D in settings > GameMode. This changes the editor camera configuration.

Game Mode Settings

More Documentation on

bevy space_editor crates
0.14 0.6
0.13 0.5
0.12 0.3 - 0.4

Contributing

Any request for adding functionality to the editor is welcome. Open an issue on the issue tracker. Any pull request is welcome too:)

Branch Policy

License

MIT - https://choosealicense.com/licenses/mit/

Project naming

Spaceeditor started as part of my prototype space game, which I feel could be useful in development, so I thought I'd share my inbuilt editor. Since the game is about space and the name of the editor starts with space*:)