box collider
This commit is contained in:
@@ -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};
|
||||
|
||||
54
unity-parser/src/types/unity_types/box_collider.rs
Normal file
54
unity-parser/src/types/unity_types/box_collider.rs
Normal file
@@ -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<Vector3>,
|
||||
center: Option<Vector3>,
|
||||
}
|
||||
|
||||
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<Vector3>) {
|
||||
self.size = size;
|
||||
}
|
||||
|
||||
/// Set the center offset of the box collider
|
||||
pub fn set_center(&mut self, center: Option<Vector3>) {
|
||||
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<Self> {
|
||||
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,));
|
||||
}
|
||||
}
|
||||
@@ -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::{
|
||||
|
||||
Reference in New Issue
Block a user