bevy_animation_graph_editor 0.8.0

Animation graph editor for the Bevy game engine
Documentation
use bevy::{asset::Handle, prelude::World};
use egui_dock::egui;

use crate::ui::{
    actions::graph::CreateGraphAction,
    generic_widgets::asset_picker::AssetPicker,
    global_state::{
        active_graph::{ActiveGraph, SetActiveGraph},
        get_global_state,
        inspector_selection::{InspectorSelection, SetInspectorSelection},
    },
    native_windows::{EditorWindowContext, NativeEditorWindowExtension},
};

#[derive(Debug)]
pub struct GraphPickerWindow;

impl NativeEditorWindowExtension for GraphPickerWindow {
    fn ui(&self, ui: &mut egui::Ui, world: &mut World, ctx: &mut EditorWindowContext) {
        let mut active = get_global_state::<ActiveGraph>(world)
            .map(|active_scene| active_scene.handle.clone())
            .unwrap_or_default();

        let response = ui.add(AssetPicker::new_salted(
            &mut active,
            world,
            "active graph asset picker",
        ));

        if response.changed() && active != Handle::default() {
            ctx.trigger(SetActiveGraph {
                new: ActiveGraph { handle: active },
            });
            ctx.trigger(SetInspectorSelection {
                selection: InspectorSelection::ActiveGraph,
            })
        }

        if ui.button("New Graph").clicked() {
            ctx.editor_actions.dynamic(CreateGraphAction);
        }
    }

    fn display_name(&self) -> String {
        "Select Graph".to_string()
    }
}