diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-11 17:08:42 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-11 17:08:42 +0100 |
commit | 792ecfb57424ec407ee7b5f0de903cd0c902b68d (patch) | |
tree | e4319d44c6afbdbb87a2c7582eb71701266752d7 /src/classes/gameobject.rs | |
parent | 7250587f46ca51ad662a0895a51742669b9cbb8f (diff) | |
download | unity-tools-792ecfb57424ec407ee7b5f0de903cd0c902b68d.tar unity-tools-792ecfb57424ec407ee7b5f0de903cd0c902b68d.tar.bz2 unity-tools-792ecfb57424ec407ee7b5f0de903cd0c902b68d.tar.zst |
move classes to modules
Diffstat (limited to 'src/classes/gameobject.rs')
-rw-r--r-- | src/classes/gameobject.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/classes/gameobject.rs b/src/classes/gameobject.rs new file mode 100644 index 0000000..fde042d --- /dev/null +++ b/src/classes/gameobject.rs @@ -0,0 +1,40 @@ +use anyhow::Result; +use serde::Serialize; +use crate::object::Value; +use super::pptr::PPtr; + +#[derive(Debug, Serialize)] +pub struct GameObject { + pub components: Vec<PPtr>, + pub layer: u32, + pub tag: u16, + pub name: String, + pub is_active: bool, +} +impl GameObject { + pub fn from_value(v: Value) -> Result<Self> { + let mut fields = v.as_class("GameObject").unwrap(); + Ok(GameObject { + components: fields + .remove("m_Component") + .unwrap() + .as_array() + .unwrap() + .into_iter() + .map(|e| { + PPtr::from_value( + e.as_class("ComponentPair") + .unwrap() + .remove("component") + .unwrap(), + ) + .unwrap() + }) + .collect(), + layer: fields["m_Layer"].as_u32().unwrap(), + tag: fields["m_Tag"].as_u16().unwrap(), + name: fields["m_Name"].clone().as_string().unwrap(), + is_active: fields["m_IsActive"].as_bool().unwrap(), + }) + } +} |