Bevy
이 페이지는 영어에서 번역되었습니다. 두 내용이 다를 경우 영어 페이지가 정확합니다. 영어 페이지 읽기
bevy_lingara는 Lingara의 플레이어 코어 위에 만든 Bevy 플러그인입니다. 앱에 추가하고 토큰을 받기 위해 여러분의 서버에 연결하는 방법을 알려 주면, Lingara가 보내는 것을 일반적인 Bevy Message로 읽을 수 있습니다.
플러그인 추가하기
게임에 크레이트를 추가한 다음, LingaraPlugin을 LingaraConfig와 함께 앱에 추가합니다.
서버에서 토큰 받기
플러그인은 시크릿을 보관하지 않습니다. 토큰이 필요하면 플러그인은 여러분 자체의 서버에 요청하고, 서버는 서버 키트로 토큰을 발급해 토큰과 그 만료 시각으로 응답합니다.
응답하는 방법은 두 가지입니다. 일반적인 경우에는 설정에 서버의 토큰 라우트와 세션에 필요한 헤더를 지정하면 플러그인이 대신 호출합니다. 또는 라우트를 설정하지 않고, 각 LingaraTokenNeeded Message에 ProvideToken으로 직접 응답합니다. 이때 게임에 이미 있는 로그인 방식을 그대로 쓸 수 있습니다.
프레임마다 한 번 이벤트 읽기
코어는 네트워크 I/O를 자체 스레드에서 실행하며, 여러분의 코드를 호출하지 않습니다. 플러그인은 프레임마다 한 번 큐를 비우고, 도착한 것을 여러분의 시스템이 다른 Message처럼 읽을 수 있는 Message로 바꿉니다.
LingaraEventReceived: 수업 계획이 준비되는 등 플레이어에 관한 이벤트NpcTranscript: 각 캐릭터에 붙는 컴포넌트로, 응답이 스트리밍되면서 늘어납니다(NPC 대화 참조)PracticeFinished: 연습 세션이 끝났을 때(연습 결과 참조)
프레임을 막는 것은 없습니다. 네트워크가 느리면 Message가 조금 늦게 도착할 뿐입니다.
Bevy
cargo add bevy_lingara@0.1.0-alpha.6Bevy
/// The common case: the plugin POSTs to your own server's token route, with
/// your game's session as a header, and reads `{token, expires_at}`.
fn lingara_config(session_header: bevy_lingara::lingara_embed::Header) -> LingaraConfig {
LingaraConfig::new()
.token_endpoint("https://game.example.com/lingara-token", vec![session_header])
.source_lang("en")
}
/// Or keep the session in ECS: leave the token endpoint unset, answer each
/// `LingaraTokenNeeded` with what your server returned.
fn answer_token_requests(mut needed: MessageReader<LingaraTokenNeeded>, mut provide: MessageWriter<ProvideToken>) {
for _request in needed.read() {
let (token, expires_at) = fetch_from_your_server();
provide.write(ProvideToken::new(token, expires_at));
}
}Bevy
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(LingaraPlugin::new(lingara_config(header)))
.add_systems(Update, on_lingara_event)
/// The plugin drains Lingara's events once per frame: read them as Messages.
fn on_lingara_event(mut events: MessageReader<LingaraEventReceived>) {
for LingaraEventReceived(event) in events.read() {
info!("{}: {}", event.event_type, event.data_json);
}
}