aboutsummaryrefslogtreecommitdiff
path: root/src/classes/gameobject.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-11 21:57:44 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-11 21:57:44 +0100
commit79e341769d04a6daa5c1edae87d6ff8a9adba9c6 (patch)
tree06792cc2a331aca1f36f9a65a1beb6c89bf361a2 /src/classes/gameobject.rs
parentd4dcece739216cae8f214900af7fc6f1728f09b8 (diff)
downloadunity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar
unity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar.bz2
unity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar.zst
fromvalue trait
Diffstat (limited to 'src/classes/gameobject.rs')
-rw-r--r--src/classes/gameobject.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/classes/gameobject.rs b/src/classes/gameobject.rs
index fde042d..94436fa 100644
--- a/src/classes/gameobject.rs
+++ b/src/classes/gameobject.rs
@@ -1,7 +1,7 @@
+use super::{FromValue, pptr::PPtr};
+use crate::object::Value;
use anyhow::Result;
use serde::Serialize;
-use crate::object::Value;
-use super::pptr::PPtr;
#[derive(Debug, Serialize)]
pub struct GameObject {
@@ -11,24 +11,27 @@ pub struct GameObject {
pub name: String,
pub is_active: bool,
}
-impl GameObject {
- pub fn from_value(v: Value) -> Result<Self> {
+impl FromValue for GameObject {
+ fn from_value(v: Value) -> Result<Self> {
let mut fields = v.as_class("GameObject").unwrap();
Ok(GameObject {
components: fields
.remove("m_Component")
.unwrap()
+ .as_class("vector")
+ .unwrap()
+ .remove("Array")
+ .unwrap()
.as_array()
.unwrap()
.into_iter()
.map(|e| {
- PPtr::from_value(
- e.as_class("ComponentPair")
- .unwrap()
- .remove("component")
- .unwrap(),
- )
- .unwrap()
+ e.as_class("ComponentPair")
+ .unwrap()
+ .remove("component")
+ .unwrap()
+ .parse::<PPtr>()
+ .unwrap()
})
.collect(),
layer: fields["m_Layer"].as_u32().unwrap(),