Crate unity_asset

Crate unity_asset 

Source
Expand description

Unity Asset Parser

A comprehensive Rust library for parsing Unity asset files, supporting both YAML and binary formats.

This crate provides high-performance, memory-safe parsing of Unity files while maintaining exact compatibility with Unity’s formats.

§Features

  • YAML Processing: Complete Unity YAML format support with multi-document parsing
  • Binary Assets: AssetBundle and SerializedFile parsing with compression support
  • Async Support: Optional async/await API for concurrent processing (enable with async feature)
  • Type Safety: Rust’s type system prevents common parsing vulnerabilities
  • Performance: Zero-cost abstractions and memory-efficient parsing

§Examples

§Basic YAML Processing

use unity_asset::{YamlDocument, UnityDocument};

// Load a Unity YAML file
let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;

// Access and filter objects
let settings = doc.get(Some("PlayerSettings"), None)?;
println!("Product name: {:?}", settings.get("productName"));

§Binary Asset Processing

use unity_asset::load_bundle_from_memory;

// Load and parse AssetBundle
let data = std::fs::read("game.bundle")?;
let bundle = load_bundle_from_memory(data)?;

// Process assets
for asset in &bundle.assets {
    println!("Found asset with {} objects", asset.object_count());
}

§Async Processing (requires async feature)

use unity_asset::{YamlDocument, AsyncUnityDocument};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load file asynchronously
    let doc = YamlDocument::load_yaml_async("ProjectSettings.asset", false).await?;

    // Same API as sync version
    let settings = doc.get(Some("PlayerSettings"), None)?;
    println!("Product name: {:?}", settings.get("productName"));

    Ok(())
}

Modules§

class_ids
Common Unity class IDs
class_names
Common Unity class names
environment
Environment for managing multiple Unity assets

Structs§

AssetBundle
A Unity AssetBundle
GLOBAL_CLASS_ID_MAP
Global class ID map instance
SerializedFile
Complete SerializedFile structure
UnityClass
A Unity class instance
UnityClassIdMap
Unity class ID to name mapping This is a global registry that maps class IDs to class names
UnityClassRegistry
Registry for Unity class types
YamlDocument
A Unity YAML document containing one or more Unity objects

Enums§

DocumentFormat
Supported Unity document formats
LineEnding
Line ending types
UnityAssetError
Main error type for Unity asset parsing operations
UnityValue
A Unity value that can be stored in a Unity class

Constants§

UNITY_TAG_URI
Unity YAML tag URI
UNITY_YAML_VERSION
Unity YAML version

Traits§

UnityDocument
Abstract trait for Unity documents

Functions§

load_bundle
Convenience functions for quick bundle loading Load a single bundle from file
load_bundle_from_memory
Load a bundle from memory
load_bundle_with_options
Load a bundle with specific options

Type Aliases§

Result
Result type alias for Unity asset operations