pub struct YamlDocument { /* private fields */ }Expand description
A Unity YAML document containing one or more Unity objects
Implementations§
Source§impl YamlDocument
impl YamlDocument
Sourcepub fn new() -> YamlDocument
pub fn new() -> YamlDocument
Create a new empty YAML document
Sourcepub fn load_yaml<P>(
path: P,
_preserve_types: bool,
) -> Result<YamlDocument, UnityAssetError>
pub fn load_yaml<P>( path: P, _preserve_types: bool, ) -> Result<YamlDocument, UnityAssetError>
Sourcepub fn load_yaml_with_warnings<P>(
path: P,
_preserve_types: bool,
) -> Result<(YamlDocument, Vec<SerdeUnityWarning>), UnityAssetError>
pub fn load_yaml_with_warnings<P>( path: P, _preserve_types: bool, ) -> Result<(YamlDocument, Vec<SerdeUnityWarning>), UnityAssetError>
Load a Unity YAML file and return non-fatal conversion warnings.
Sourcepub fn line_ending(&self) -> LineEnding
pub fn line_ending(&self) -> LineEnding
Get the line ending style
Sourcepub fn set_line_ending(&mut self, newline: LineEnding)
pub fn set_line_ending(&mut self, newline: LineEnding)
Set the line ending style
Sourcepub fn yaml_metadata(&self) -> &HashMap<String, String>
pub fn yaml_metadata(&self) -> &HashMap<String, String>
Get the YAML metadata
Sourcepub fn save(&self) -> Result<(), UnityAssetError>
pub fn save(&self) -> Result<(), UnityAssetError>
Save document to its original file
This method saves the document back to the file it was loaded from. If the document was not loaded from a file, this will return an error.
§Examples
use unity_asset_yaml::YamlDocument;
let mut doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
// ... modify the document ...
doc.save()?; // Save back to original fileSourcepub fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
pub fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
Save document to a specific file
This method serializes the document to Unity YAML format and saves it to the specified file path.
§Examples
use unity_asset_yaml::YamlDocument;
let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
doc.save_to("ProjectSettings_backup.asset")?;Sourcepub fn dump_yaml(&self) -> Result<String, UnityAssetError>
pub fn dump_yaml(&self) -> Result<String, UnityAssetError>
Get YAML content as string
This method serializes the document to Unity YAML format and returns it as a string without writing to a file.
§Examples
use unity_asset_yaml::YamlDocument;
let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
let yaml_string = doc.dump_yaml()?;
println!("{}", yaml_string);Sourcepub fn filter(
&self,
class_names: Option<&[&str]>,
attributes: Option<&[&str]>,
) -> Vec<&UnityClass>
pub fn filter( &self, class_names: Option<&[&str]>, attributes: Option<&[&str]>, ) -> Vec<&UnityClass>
Filter entries by class names and/or attributes
This method provides advanced filtering capabilities similar to the Python reference library’s filter() method.
§Arguments
class_names- Optional list of class names to filter byattributes- Optional list of attribute names that entries must have
§Examples
use unity_asset_yaml::YamlDocument;
let doc = YamlDocument::load_yaml("scene.unity", false)?;
// Find all GameObjects
let gameobjects = doc.filter(Some(&["GameObject"]), None);
// Find all objects with m_Enabled property
let enabled_objects = doc.filter(None, Some(&["m_Enabled"]));
// Find MonoBehaviours with m_Script property
let scripts = doc.filter(Some(&["MonoBehaviour"]), Some(&["m_Script"]));Sourcepub fn get(
&self,
class_name: Option<&str>,
attributes: Option<&[&str]>,
) -> Result<&UnityClass, UnityAssetError>
pub fn get( &self, class_name: Option<&str>, attributes: Option<&[&str]>, ) -> Result<&UnityClass, UnityAssetError>
Get a single entry by class name and/or attributes
This method returns the first entry that matches the criteria. Returns an error if no matching entry is found or if multiple entries match.
§Arguments
class_name- Optional class name to matchattributes- Optional list of attribute names that the entry must have
§Examples
use unity_asset_yaml::YamlDocument;
let doc = YamlDocument::load_yaml("scene.unity", false)?;
// Get the first GameObject
let gameobject = doc.get(Some("GameObject"), None)?;
// Get an object with specific attributes
let script = doc.get(Some("MonoBehaviour"), Some(&["m_Script", "m_Enabled"]))?;