pub trait BaseScript:
Visit
+ Reflect
+ Send
+ Debug
+ 'static {
// Required methods
fn clone_box(&self) -> Box<dyn ScriptTrait>;
fn as_any_ref(&self) -> &dyn Any;
fn as_any_ref_mut(&mut self) -> &mut dyn Any;
fn id(&self) -> Uuid;
}
Expand description
Base script trait is used to automatically implement some trait to reduce amount of boilerplate code.
Required Methods§
Sourcefn clone_box(&self) -> Box<dyn ScriptTrait>
fn clone_box(&self) -> Box<dyn ScriptTrait>
Creates exact copy of the script.
Sourcefn as_any_ref(&self) -> &dyn Any
fn as_any_ref(&self) -> &dyn Any
Casts self as Any
Sourcefn as_any_ref_mut(&mut self) -> &mut dyn Any
fn as_any_ref_mut(&mut self) -> &mut dyn Any
Casts self as Any
Sourcefn id(&self) -> Uuid
fn id(&self) -> Uuid
Script instance type UUID. The value will be used for serialization, to write type identifier to a data source so the engine can restore the script from data source.
§Important notes
Do not use Uuid::new_v4
or any other Uuid
methods that generates ids, ids
generated using these methods are random and are not suitable for serialization!
§Example
All you need to do in the method is to return Self::type_uuid
.
use std::str::FromStr;
use fyrox_impl::{
core::visitor::prelude::*,
core::reflect::prelude::*,
core::uuid::Uuid,
script::ScriptTrait,
core::TypeUuidProvider,
core::uuid::uuid, core::type_traits::prelude::*
};
#[derive(Reflect, Visit, Debug, Clone, ComponentProvider)]
struct MyScript { }
// Implement TypeUuidProvider trait that will return type uuid of the type.
// Every script must implement the trait so the script can be registered in
// serialization context of the engine.
impl TypeUuidProvider for MyScript {
fn type_uuid() -> Uuid {
// Use https://www.uuidgenerator.net/ to generate new UUID.
uuid!("4cfbe65e-a2c1-474f-b123-57516d80b1f8")
}
}
impl ScriptTrait for MyScript { }