PythonLikeUnityDocument

Struct PythonLikeUnityDocument 

Source
pub struct PythonLikeUnityDocument { /* private fields */ }
Expand description

Python-like wrapper for Unity documents

This provides an API similar to the Python reference library:

doc = UnityDocument.load_yaml("file.asset")
entry = doc.entry
entry.m_Name = "NewName"
doc.dump_yaml()

Implementations§

Source§

impl PythonLikeUnityDocument

Source

pub fn load_yaml<P: AsRef<Path>>( file_path: P, try_preserve_types: bool, ) -> Result<Self>

Load a Unity YAML file (similar to Python’s UnityDocument.load_yaml)

§Arguments
  • file_path - Path to the Unity YAML file
  • try_preserve_types - Whether to preserve original types (similar to Python’s flag)
§Examples
use unity_asset_yaml::python_like_api::PythonLikeUnityDocument;

let doc = PythonLikeUnityDocument::load_yaml("ProjectSettings.asset", false)?;
Source

pub fn entry(&self) -> Option<PythonLikeUnityClass<'_>>

Get the first entry (similar to Python’s doc.entry)

Source

pub fn entries(&self) -> Vec<PythonLikeUnityClass<'_>>

Get all entries (similar to Python’s doc.entries)

Source

pub fn filter( &self, class_names: Option<&[&str]>, attributes: Option<&[&str]>, ) -> Vec<PythonLikeUnityClass<'_>>

Filter entries by class names and attributes (similar to Python’s doc.filter)

§Examples
use unity_asset_yaml::python_like_api::PythonLikeUnityDocument;

let doc = PythonLikeUnityDocument::load_yaml("scene.unity", false)?;

// Find all GameObjects
let gameobjects = doc.filter(Some(&["GameObject"]), None);

// Find objects with m_Enabled property
let enabled_objects = doc.filter(None, Some(&["m_Enabled"]));
Source

pub fn get( &self, class_name: Option<&str>, attributes: Option<&[&str]>, ) -> Result<PythonLikeUnityClass<'_>>

Get a single entry by class name and attributes (similar to Python’s doc.get)

Source

pub fn dump_yaml(&self) -> Result<()>

Save the document (similar to Python’s doc.dump_yaml())

Source

pub fn dump_yaml_to<P: AsRef<Path>>(&self, file_path: P) -> Result<()>

Save to a specific file (similar to Python’s doc.dump_yaml(file_path=“…”))

Source

pub fn inner(&self) -> &YamlDocument

Get the underlying YamlDocument for advanced operations

Source

pub fn inner_mut(&mut self) -> &mut YamlDocument

Get mutable access to the underlying YamlDocument

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.