diff --git a/unity-parser/src/types/mod.rs b/unity-parser/src/types/mod.rs index d1a0b20..a8f5239 100644 --- a/unity-parser/src/types/mod.rs +++ b/unity-parser/src/types/mod.rs @@ -23,7 +23,7 @@ pub use reference::UnityReference; pub use type_filter::TypeFilter; pub use type_registry::{get_class_name, get_type_id}; pub use unity_types::{ - GameObject, MeshFilter, PrefabInstance, PrefabInstanceComponent, PrefabModification, - PrefabResolver, RectTransform, Renderer, Transform, + BoxCollider, GameObject, MeshFilter, PrefabInstance, PrefabInstanceComponent, + PrefabModification, PrefabResolver, RectTransform, Renderer, Transform, }; pub use values::{Color, ExternalRef, FileRef, Quaternion, Vector2, Vector3}; diff --git a/unity-parser/src/types/unity_types/box_collider.rs b/unity-parser/src/types/unity_types/box_collider.rs new file mode 100644 index 0000000..93d2c6b --- /dev/null +++ b/unity-parser/src/types/unity_types/box_collider.rs @@ -0,0 +1,54 @@ +//! BoxCollider component wrapper + +use crate::types::{yaml_helpers, ComponentContext, UnityComponent, Vector3}; +use sparsey::Entity; + +/// A BoxCollider component +/// +/// BoxCollider is a basic collision primitive in the shape of a box. +/// It defines a box-shaped volume that can be used for collision detection. +#[derive(Debug, Clone)] +pub struct BoxCollider { + size: Option, + center: Option, +} + +impl BoxCollider { + /// Get the size of the box collider + pub fn size(&self) -> Option<&Vector3> { + self.size.as_ref() + } + + /// Get the center offset of the box collider + pub fn center(&self) -> Option<&Vector3> { + self.center.as_ref() + } + + /// Set the size of the box collider + pub fn set_size(&mut self, size: Option) { + self.size = size; + } + + /// Set the center offset of the box collider + pub fn set_center(&mut self, center: Option) { + self.center = center; + } +} + +impl UnityComponent for BoxCollider { + /// Parse a BoxCollider from YAML + /// + /// Note: Caller is responsible for ensuring this is called on the correct document type. + fn parse(yaml: &serde_yaml::Mapping, _ctx: &ComponentContext) -> Option { + let size = yaml_helpers::get_vector3(yaml, "m_Size"); + let center = yaml_helpers::get_vector3(yaml, "m_Center"); + + Some(Self { size, center }) + } +} + +impl crate::types::EcsInsertable for BoxCollider { + fn insert_into_world(self, world: &mut sparsey::World, entity: Entity) { + world.insert(entity, (self,)); + } +} diff --git a/unity-parser/src/types/unity_types/mod.rs b/unity-parser/src/types/unity_types/mod.rs index fca9e4a..7622376 100644 --- a/unity-parser/src/types/unity_types/mod.rs +++ b/unity-parser/src/types/unity_types/mod.rs @@ -1,11 +1,13 @@ //! Unity-specific types (GameObjects, Transforms, PrefabInstances) +pub mod box_collider; pub mod game_object; pub mod mesh_filter; pub mod prefab_instance; pub mod renderer; pub mod transform; +pub use box_collider::BoxCollider; pub use game_object::GameObject; pub use mesh_filter::MeshFilter; pub use prefab_instance::{