unity-pack

Crates.iounity-pack
lib.rsunity-pack
version0.1.0
created_at2025-12-22 23:38:33.313916+00
updated_at2025-12-22 23:38:33.313916+00
descriptionCreate Unity .unitypackage files and assets from Rust
homepage
repositoryhttps://github.com/Autarkis/unity-pack-rs
max_upload_size
id2000482
size108,560
boris (Autarkis)

documentation

README

unity-pack

CI Crates.io Documentation License: MIT

Create Unity .unitypackage files from Rust.

Why?

Unity packages are typically created from within the Unity Editor, but sometimes you need to generate them programmatically:

  • CI/CD pipelines - Automate asset packaging without opening Unity
  • Procedural generation - Export terrain, textures, or configs from external tools
  • Asset pipelines - Build Unity packages from non-Unity source data

Quick Start

use unity_pack::{UnityPackage, Asset};

fn main() -> unity_pack::Result<()> {
    UnityPackage::builder()
        .asset(Asset::text("Assets/Config/settings.json", r#"{"volume": 0.8}"#))
        .asset(Asset::binary("Assets/Data/heightmap.raw", include_bytes!("terrain.raw").to_vec()))
        .build()?
        .save("my-assets.unitypackage")?;
    Ok(())
}

Installation

[dependencies]
unity-pack = "0.1"

Optional Features

Feature Description
scriptable Generate Unity ScriptableObject YAML files
terrain Heightmap conversion helpers (f32 → 16/32-bit raw)
tui Interactive terminal UI for package creation
unity-pack = { version = "0.1", features = ["scriptable", "terrain"] }

Features

  • Generate valid Unity .meta files with proper GUIDs
  • Support for binary assets, text assets, and folders
  • Deterministic GUIDs for reproducible builds
  • Builder pattern API
  • Load assets directly from files on disk

Examples

Adding Assets

use unity_pack::{UnityPackage, Asset};

let mut pkg = UnityPackage::new();

// From raw data
pkg.add(Asset::binary("Assets/Textures/noise.raw", vec![0u8; 1024]))?;
pkg.add(Asset::text("Assets/Scripts/Player.cs", "using UnityEngine;"))?;
pkg.add(Asset::folder("Assets/Levels"))?;

// From files on disk
pkg.add(Asset::from_file("Assets/Models/tree.fbx", "./exports/tree.fbx")?)?;

pkg.save("game-assets.unitypackage")?;

ScriptableObject Generation

use unity_pack::scriptable::{ScriptableObject, vec3, color};
use unity_pack::UnityGuid;

let script_guid = UnityGuid::from_hex("0123456789abcdef0123456789abcdef")?;

let config = ScriptableObject::new("PlayerConfig")
    .script(script_guid)
    .field("maxHealth", 100)
    .field("walkSpeed", 5.5)
    .field("spawnPoint", vec3(10.0, 0.0, 20.0))
    .field("teamColor", color(1.0, 0.0, 0.0, 1.0));

let asset = config.to_asset("Assets/Config/PlayerConfig.asset");

Terrain Heightmaps

use unity_pack::terrain::heightmap_16bit;

let heights: Vec<f32> = generate_terrain(256, 256); // 0.0 - 1.0 range
let asset = heightmap_16bit("Assets/Terrain/heightmap.raw", &heights, 256, 256);

Interactive TUI

cargo install unity-pack --features tui
unity-pack

Navigate your filesystem, select files, and create packages interactively.

Unity Package Format

A .unitypackage is a gzipped tar archive containing one directory per asset:

<GUID>/
  ├── pathname    # Unity path (e.g., "Assets/Data/file.raw")
  ├── asset       # File contents
  └── asset.meta  # Unity metadata

Requirements

  • Rust 1.70+

API Documentation

Full API documentation is available on docs.rs.

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request.

Development Setup

Enable pre-commit hooks (runs fmt + clippy before each commit):

git config core.hooksPath .githooks

See CHANGELOG.md for release history.

License

MIT

Commit count: 0

cargo fmt