mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
fixed project template generator
This commit is contained in:
+28
-14
@@ -164,7 +164,7 @@ use fyrox::{
|
||||
core::pool::Handle, core::visitor::prelude::*, core::reflect::prelude::*,
|
||||
event::Event,
|
||||
gui::{message::UiMessage, UserInterface},
|
||||
plugin::{Plugin, PluginContext, PluginRegistrationContext},
|
||||
plugin::{Plugin, PluginContext, PluginRegistrationContext, error::GameResult},
|
||||
scene::Scene,
|
||||
};
|
||||
use std::path::Path;
|
||||
@@ -179,30 +179,35 @@ pub struct Game {
|
||||
}
|
||||
|
||||
impl Plugin for Game {
|
||||
fn register(&self, _context: PluginRegistrationContext) {
|
||||
fn register(&self, _context: PluginRegistrationContext) -> GameResult {
|
||||
// Register your scripts here.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init(&mut self, scene_path: Option<&str>, context: PluginContext) {
|
||||
fn init(&mut self, scene_path: Option<&str>, context: PluginContext) -> GameResult {
|
||||
context
|
||||
.async_scene_loader
|
||||
.request(scene_path.unwrap_or("data/scene.rgs"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_deinit(&mut self, _context: PluginContext) {
|
||||
fn on_deinit(&mut self, _context: PluginContext) -> GameResult {
|
||||
// Do a cleanup here.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _context: &mut PluginContext) {
|
||||
fn update(&mut self, _context: &mut PluginContext) -> GameResult {
|
||||
// Add your global update code here.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_os_event(
|
||||
&mut self,
|
||||
_event: &Event<()>,
|
||||
_context: PluginContext,
|
||||
) {
|
||||
) -> GameResult {
|
||||
// Do something on OS event here.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_ui_message(
|
||||
@@ -210,14 +215,16 @@ impl Plugin for Game {
|
||||
_context: &mut PluginContext,
|
||||
_message: &UiMessage,
|
||||
_ui_handle: Handle<UserInterface>
|
||||
) {
|
||||
) -> GameResult {
|
||||
// Handle UI events here.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_scene_begin_loading(&mut self, _path: &Path, ctx: &mut PluginContext) {
|
||||
fn on_scene_begin_loading(&mut self, _path: &Path, ctx: &mut PluginContext) -> GameResult {
|
||||
if self.scene.is_some() {
|
||||
ctx.scenes.remove(self.scene);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_scene_loaded(
|
||||
@@ -226,8 +233,9 @@ impl Plugin for Game {
|
||||
scene: Handle<Scene>,
|
||||
_data: &[u8],
|
||||
_context: &mut PluginContext,
|
||||
) {
|
||||
) -> GameResult {
|
||||
self.scene = scene;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
"#,
|
||||
@@ -676,6 +684,7 @@ use fyrox::graph::prelude::*;
|
||||
use fyrox::{{
|
||||
core::{{visitor::prelude::*, reflect::prelude::*, type_traits::prelude::*}},
|
||||
event::Event, script::{{ScriptContext, ScriptDeinitContext, ScriptTrait}},
|
||||
plugin::error::GameResult
|
||||
}};
|
||||
|
||||
#[derive(Visit, Reflect, Default, Debug, Clone, TypeUuidProvider, ComponentProvider)]
|
||||
@@ -686,25 +695,30 @@ pub struct {script_name} {{
|
||||
}}
|
||||
|
||||
impl ScriptTrait for {script_name} {{
|
||||
fn on_init(&mut self, context: &mut ScriptContext) {{
|
||||
fn on_init(&mut self, context: &mut ScriptContext) -> GameResult {{
|
||||
// Put initialization logic here.
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
fn on_start(&mut self, context: &mut ScriptContext) {{
|
||||
fn on_start(&mut self, context: &mut ScriptContext) -> GameResult {{
|
||||
// There should be a logic that depends on other scripts in scene.
|
||||
// It is called right after **all** scripts were initialized.
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
fn on_deinit(&mut self, context: &mut ScriptDeinitContext) {{
|
||||
fn on_deinit(&mut self, context: &mut ScriptDeinitContext) -> GameResult {{
|
||||
// Put de-initialization logic here.
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
fn on_os_event(&mut self, event: &Event<()>, context: &mut ScriptContext) {{
|
||||
fn on_os_event(&mut self, event: &Event<()>, context: &mut ScriptContext) -> GameResult {{
|
||||
// Respond to OS events here.
|
||||
Ok(())
|
||||
}}
|
||||
|
||||
fn on_update(&mut self, context: &mut ScriptContext) {{
|
||||
fn on_update(&mut self, context: &mut ScriptContext) -> GameResult {{
|
||||
// Put object logic here.
|
||||
Ok(())
|
||||
}}
|
||||
}}
|
||||
"#
|
||||
|
||||
Reference in New Issue
Block a user