# unity-pack
[](https://github.com/Autarkis/unity-pack-rs/actions/workflows/ci.yml)
[](https://crates.io/crates/unity-pack)
[](https://docs.rs/unity-pack)
[](LICENSE)
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
```rust
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
```toml
[dependencies]
unity-pack = "0.1"
```
### Optional Features
| `scriptable` | Generate Unity ScriptableObject YAML files |
| `terrain` | Heightmap conversion helpers (f32 → 16/32-bit raw) |
| `tui` | Interactive terminal UI for package creation |
```toml
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
```rust
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
```rust
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
```rust
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
```bash
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](https://docs.rs/unity-pack).
## 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):
```bash
git config core.hooksPath .githooks
```
See [CHANGELOG.md](CHANGELOG.md) for release history.
## License
MIT