Unravel Engine C++ Reference
Loading...
Searching...
No Matches
animation_component.cpp
Go to the documentation of this file.
6
7namespace unravel
8{
9
11{
12 entt::meta_factory<animation_component::culling_mode>{}
13 .type("culling_mode"_hs)
15 entt::attribute{"name", "culling_mode"},
16 entt::attribute{"pretty_name", "Culling Mode"},
17 })
18 .data<animation_component::culling_mode::always_animate>("always_animate"_hs)
20 entt::attribute{"name", "always_animate"},
21 entt::attribute{"pretty_name", "Always Animate"},
22 })
23 .data<animation_component::culling_mode::renderer_based>("renderer_based"_hs)
25 entt::attribute{"name", "renderer_based"},
26 entt::attribute{"pretty_name", "Renderer Based"},
27 });
28
29 // Register animation_component class with entt
30 entt::meta_factory<animation_component>{}
31 .type("animation_component"_hs)
33 entt::attribute{"name", "animation_component"},
34 entt::attribute{"category", "ANIMATION"},
35 entt::attribute{"pretty_name", "Animation"},
36 })
37 .func<&component_meta<animation_component>::exists>("component_exists"_hs)
38 .func<&component_meta<animation_component>::add>("component_add"_hs)
39 .func<&component_meta<animation_component>::save>("component_save"_hs)
40 .func<&component_meta<animation_component>::load>("component_load"_hs)
41 .func<&component_meta<animation_component>::remove>("component_remove"_hs)
43 .custom<entt::attributes>(entt::attributes{
44 entt::attribute{"name", "animation"},
45 entt::attribute{"pretty_name", "Animation"},
46 })
47 .data<&animation_component::set_autoplay, &animation_component::get_autoplay>("auto_play"_hs)
49 entt::attribute{"name", "auto_play"},
50 entt::attribute{"pretty_name", "Auto Play"},
51 entt::attribute{"tooltip", "Controls whether the animation should auto start."},
52 })
53 .data<&animation_component::set_culling_mode, &animation_component::get_culling_mode>("culling_mode"_hs)
55 entt::attribute{"name", "culling_mode"},
56 entt::attribute{"pretty_name", "Culling Mode"},
57 entt::attribute{"tooltip", "Controls how the animation logic should be culled."},
58 })
59 .data<&animation_component::set_apply_root_motion, &animation_component::get_apply_root_motion>("apply_root_motion"_hs)
61 entt::attribute{"name", "apply_root_motion"},
62 entt::attribute{"pretty_name", "Apply Root Motion"},
63 })
64 .data<&animation_component::set_speed, &animation_component::get_speed>("speed"_hs)
66 entt::attribute{"name", "speed"},
67 entt::attribute{"pretty_name", "Speed"},
68 entt::attribute{"tooltip", "Controls the playback speed of the animation. 1.0 = normal speed, 2.0 = double speed, 0.5 = half speed."},
69 entt::attribute{"min", 0.0f},
70 entt::attribute{"max", 10.0f},
71 });
72}
73
75{
76 try_save(ar, ser20::make_nvp("animation", obj.get_animation()));
77 try_save(ar, ser20::make_nvp("auto_play", obj.get_autoplay()));
78 try_save(ar, ser20::make_nvp("culling_mode", obj.get_culling_mode()));
79 try_save(ar, ser20::make_nvp("apply_root_motion", obj.get_apply_root_motion()));
80 try_save(ar, ser20::make_nvp("speed", obj.get_speed()));
81}
84
86{
88 if(try_load(ar, ser20::make_nvp("animation", animation)))
89 {
90 obj.set_animation(animation);
91 }
92
93 bool auto_play{};
94 if(try_load(ar, ser20::make_nvp("auto_play", auto_play)))
95 {
96 obj.set_autoplay(auto_play);
97 }
98
100 if(try_load(ar, ser20::make_nvp("culling_mode", culling_mode)))
101 {
102 obj.set_culling_mode(culling_mode);
103 }
104
105 bool apply_root_motion{};
106 if(try_load(ar, ser20::make_nvp("apply_root_motion", apply_root_motion)))
107 {
108 obj.set_apply_root_motion(apply_root_motion);
109 }
110
111 float speed{1.0f};
112 if(try_load(ar, ser20::make_nvp("speed", speed)))
113 {
114 obj.set_speed(speed);
115 }
116}
119
120} // namespace unravel
auto get_animation() const -> const asset_handle< animation_clip > &
void set_animation(const asset_handle< animation_clip > &animation)
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Represents a handle to an asset, providing access and management functions.