aboutsummaryrefslogtreecommitdiff
path: root/src/classes/transform.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/transform.rs
parentd4dcece739216cae8f214900af7fc6f1728f09b8 (diff)
downloadunity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar
unity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar.bz2
unity-tools-79e341769d04a6daa5c1edae87d6ff8a9adba9c6.tar.zst
fromvalue trait
Diffstat (limited to 'src/classes/transform.rs')
-rw-r--r--src/classes/transform.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/classes/transform.rs b/src/classes/transform.rs
index 518e248..b05985f 100644
--- a/src/classes/transform.rs
+++ b/src/classes/transform.rs
@@ -1,26 +1,44 @@
-use super::pptr::PPtr;
+use super::{FromValue, gameobject::GameObject, pptr::PPtr};
use crate::object::Value;
use anyhow::Result;
+use glam::{Quat, Vec3};
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct Transform {
pub father: PPtr<Transform>,
pub children: Vec<PPtr<Transform>>,
+ pub gameobject: PPtr<GameObject>,
+ pub local_position: Vec3,
+ pub local_rotation: Quat,
+ pub local_scale: Vec3,
}
-impl Transform {
- pub fn from_value(v: Value) -> Result<Self> {
+impl FromValue for Transform {
+ fn from_value(v: Value) -> Result<Self> {
let mut fields = v.as_class("Transform").unwrap();
Ok(Self {
children: fields
.remove("m_Children")
.unwrap()
+ .as_class("vector")
+ .unwrap()
+ .remove("Array")
+ .unwrap()
.as_array()
.unwrap()
.into_iter()
.map(|e| PPtr::from_value(e).unwrap().cast())
.collect(),
- father: PPtr::from_value(fields.remove("m_Father").unwrap())?.cast(),
+ father: fields
+ .remove("m_Father")
+ .unwrap()
+ .parse::<PPtr>()
+ .unwrap()
+ .cast(),
+ gameobject: fields.remove("m_GameObject").unwrap().parse().unwrap(),
+ local_position: fields.remove("m_LocalPosition").unwrap().parse().unwrap(),
+ local_rotation: fields.remove("m_LocalRotation").unwrap().parse().unwrap(),
+ local_scale: fields.remove("m_LocalScale").unwrap().parse().unwrap(),
})
}
}