2021-03-09 01:07:01 +00:00
|
|
|
use bevy::{prelude::*, reflect::TypeRegistry};
|
2020-11-28 00:39:59 +00:00
|
|
|
use std::any::TypeId;
|
|
|
|
|
|
|
|
/// You must manually register each instance of a generic type
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.register_type::<MyType<u32>>()
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_startup_system(setup.system())
|
2020-11-28 00:39:59 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Reflect)]
|
|
|
|
struct MyType<T: Reflect> {
|
|
|
|
value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(type_registry: Res<TypeRegistry>) {
|
|
|
|
let type_registry = type_registry.read();
|
|
|
|
|
|
|
|
let registration = type_registry.get(TypeId::of::<MyType<u32>>()).unwrap();
|
|
|
|
println!("Registration for {} exists", registration.short_name());
|
|
|
|
|
|
|
|
// MyType<String> was not manually registered, so it does not exist
|
|
|
|
assert!(type_registry.get(TypeId::of::<MyType<String>>()).is_none());
|
|
|
|
}
|