5个不稳定版本

0.3.0 2024年7月4日
0.3.0-rc2024年6月11日
0.2.0 2024年2月18日
0.1.2 2024年2月6日
0.1.0 2020年7月15日

69游戏开发 中排名

Download history 246/week @ 2024-04-19 426/week @ 2024-04-26 221/week @ 2024-05-03 47/week @ 2024-05-10 123/week @ 2024-05-17 158/week @ 2024-05-24 151/week @ 2024-05-31 163/week @ 2024-06-07 67/week @ 2024-06-14 100/week @ 2024-06-21 148/week @ 2024-06-28 122/week @ 2024-07-05 52/week @ 2024-07-12 48/week @ 2024-07-19 83/week @ 2024-07-26 33/week @ 2024-08-02

每月下载量 223
用于 4 个crate(直接使用2个)

MIT/Apache

1MB
18K SLoC

Rust 版本的 Yarn Spinner

Crates.io Docs Discord

注意: Rust 版本的 Yarn Spinner 是一个正在进行中的项目。我们目前不提供任何官方支持。如果您有任何问题,请提交 问题,并加入官方 Yarn Spinner Discord 讨论该项目!

Yarn Spinner 是 Rust 的版本,用于编写游戏对话。更多内容请参阅 docs.yarnspinner.dev 或查看使用 Bevy 引擎 编写的 实时演示。此项目为 Bevy 提供一级支持,并假设您正在使用它。如果您没有,请查看 书籍的相关部分

Yarn Spinner for Rust Demo

快速入门

直接来自我们的 示例

首先,让我们添加我们的依赖项

cargo add bevy bevy_yarnspinner bevy_yarnspinner_example_dialogue_view

现在,是 main.rs

use bevy::prelude::*;
use bevy_yarnspinner::prelude::*;
use bevy_yarnspinner_example_dialogue_view::prelude::*;

fn main() {
    let mut app = App::new();
    app.add_plugins((
        DefaultPlugins,
        // Register the Yarn Spinner plugin using its default settings, which will look for Yarn files in the "dialogue" folder.
        // If this app should support Wasm or Android, we cannot load files without specifying them, so use the following instead.
        // YarnSpinnerPlugin::with_yarn_source(YarnFileSource::file("dialogue/hello_world.yarn")),
        YarnSpinnerPlugin::new(),
        // Initialize the bundled example UI
        ExampleYarnSpinnerDialogueViewPlugin::new(),
    ))
        .add_systems(Startup, setup_camera)
        .add_systems(
            Update,
            // Spawn the dialogue runner once the Yarn project has finished compiling
            spawn_dialogue_runner.run_if(resource_added::<YarnProject>),
        )
        .run();
}

fn setup_camera(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
    // Create a dialogue runner from the project.
    let mut dialogue_runner = project.create_dialogue_runner();
    // Immediately start showing the dialogue to the player
    dialogue_runner.start_node("HelloWorld");
    commands.spawn(dialogue_runner);
}

最后,是 assets/dialogue/hello_world.yarn

title: HelloWorld
---
Hello World! To continue the dialogue, click with your mouse, press the space bar or the enter key.
These are options. You can select one by clicking on it or pressing the corresponding number on your keyboard.
-> Some cool option
-> Some other cool option
Now we'll jump to another node!
<<jump AnotherNode>>

===

title: AnotherNode
---
Now, a character will talk. Notice how the upper left corner of the dialogue will show their name.
Hohenheim: Hi, I'm Jan Hohenheim, creator of Yarn Spinner for Rust. I hope you enjoy using it!
Let's set a condition. Do you prefer dogs or cats?
-> Dogs
    <<set $animal = "dog">>
-> Cats
    <<set $animal = "cats">>
-> Turtles
    I, uuuh... okay, why not.
    <<set $animal = "turtles">>
Now let's print the result of the condition. Your preference is...
(Drum roll)
<<if $animal == "dog">>
Dogs! Arf Arf!
<<elseif $animal == "cats">>
Cats! (Can't say I agree, but you do you)
<<else>>
Turtles! Solid choice.
<<endif>>
Et voilà! That was all. Thanks for checking out Yarn Spinner for Rust! Continuing from the last node will exit the dialogue.
===

版本表

Bevy Rust 版本的 Yarn Spinner
0.14 0.3
0.13 0.2
0.12 0.1

依赖项

~8–52MB
~818K SLoC