Giter Club home page Giter Club logo

bevy-inspector-egui's Introduction

bevy-inspector-egui

Examples can be found at ./crates/bevy-inspector-egui/examples.

This crate contains

  • general purpose machinery for displaying Reflect values in reflect_inspector,
  • a way of associating arbitrary options with fields and enum variants in inspector_options
  • utility functions for displaying bevy resource, entities and assets in bevy_inspector
  • some drop-in plugins in quick to get you started without any code necessary.

The changelog can be found at docs/CHANGELOG.md.

Use case 1: Quick plugins

These plugins can be easily added to your app, but don't allow for customization of the presentation and content.

WorldInspectorPlugin

Displays the world's entities, resources and assets.

image of the world inspector

use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(WorldInspectorPlugin::new())
        .run();
}

ResourceInspectorPlugin

Display a single resource in a window.

image of the resource inspector

use bevy::prelude::*;
use bevy_inspector_egui::prelude::*;
use bevy_inspector_egui::quick::ResourceInspectorPlugin;

// `InspectorOptions` are completely optional
#[derive(Reflect, Resource, Default, InspectorOptions)]
#[reflect(Resource, InspectorOptions)]
struct Configuration {
    name: String,
    #[inspector(min = 0.0, max = 1.0)]
    option: f32,
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .init_resource::<Configuration>() // `ResourceInspectorPlugin` won't initialize the resource
        .register_type::<Configuration>() // you need to register your type to display it
        .add_plugins(ResourceInspectorPlugin::<Configuration>::default())
        // also works with built-in resources, as long as they are `Reflect`
        .add_plugins(ResourceInspectorPlugin::<Time>::default())
        .run();
}

There is also the StateInspectorPlugin and the AssetInspectorPlugin.

Use case 2: Manual UI

The quick plugins don't allow customization of the egui window or its content, but you can easily build your own UI:

use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use bevy_inspector_egui::prelude::*;
use std::any::TypeId;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EguiPlugin)
        .add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s
        .add_systems(Update, inspector_ui)
        .run();
}

fn inspector_ui(world: &mut World) {
    let Ok(egui_context) = world
        .query_filtered::<&mut EguiContext, With<PrimaryWindow>>()
        .get_single(world)
    else {
        return;
    };
    let mut egui_context = egui_context.clone();

    egui::Window::new("UI").show(egui_context.get_mut(), |ui| {
        egui::ScrollArea::vertical().show(ui, |ui| {
            // equivalent to `WorldInspectorPlugin`
            bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui);

            egui::CollapsingHeader::new("Materials").show(ui, |ui| {
                bevy_inspector_egui::bevy_inspector::ui_for_assets::<StandardMaterial>(world, ui);
            });

            ui.heading("Entities");
            bevy_inspector_egui::bevy_inspector::ui_for_world_entities(world, ui);
        });
    });
}

Pair this with a crate like egui_dock and you have your own editor in less than 100 lines: examples/egui_dock.rs. image of the egui_dock example

Cargo features

  • highlight_changes - highlight changed values every frame. Ideally this should be runtime-configurable, but it was implemented like this as a stopgap solution. If you'd like to configure this at runtime, please open an issue to let me know it's more of a priority.
  • bevy_pbr (default): register default options for bevy_pbr types. You should disable this if you don't use bevy_pbr to reduce the dependency footprint.

FAQ

Q: How do I change the names of the entities in the world inspector?

A: You can insert the Name component.

Q: What if I just want to display a single value without passing in the whole &mut World?

A: You can use reflect_inspector::ui_for_value. Note that displaying things like Handle<StandardMaterial> won't be able to display the asset's value.

Bevy support table

bevy bevy-inspector-egui
0.12 0.22
0.12 0.21
0.11 0.19-0.20
0.10 0.18
0.9 0.14-0.17
0.8 0.12-0.13
0.7 0.10-0.11
0.6 0.9
0.6 0.8
0.6 0.7
0.5 0.5-0.6
0.5 0.4
0.4 0.1-0.3

bevy-inspector-egui's People

Contributors

823984418 avatar aceeri avatar ariofrio avatar askor avatar b-reif avatar barsoosayque avatar brysonmci avatar danilamihailov avatar icesentry avatar imizao avatar jakobhellermann avatar johanhelsing avatar kmaheshbhat avatar luminoth avatar mvlabat avatar mwfiae avatar nia-e avatar nikola-milovic avatar paul-hansen avatar raffaeleragni avatar rezural avatar rparrett avatar shatur avatar slyedoc avatar st0rmbtw avatar tversteeg avatar vrixyz avatar wendivoid avatar willcrichton avatar yoshierahuang3456 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.