| Crates.io | uvm_detect |
| lib.rs | uvm_detect |
| version | 1.1.1 |
| created_at | 2025-09-17 16:39:55.734106+00 |
| updated_at | 2025-09-22 09:03:38.377516+00 |
| description | Unity project detection and version extraction library |
| homepage | |
| repository | https://github.com/larusso/unity-version-manager |
| max_upload_size | |
| id | 1843579 |
| size | 68,862 |
A Rust library for detecting Unity projects and extracting Unity version information from project directories.
uvm_detect provides utilities to:
std::fs::OpenOptions for clean configurationstd::fs::OpenOptionsunity-version for version parsingAdd this to your Cargo.toml:
[dependencies]
uvm_detect = "0.1.0"
use std::path::Path;
use uvm_detect::DetectOptions;
// Search for Unity project in current directory only
match DetectOptions::new().detect_unity_project_dir(Path::new(".")) {
Ok(project_path) => {
println!("Found Unity project at: {}", project_path.display());
}
Err(_) => {
println!("No Unity project found in current directory");
}
}
use std::path::Path;
use uvm_detect::DetectOptions;
// Search recursively through subdirectories
match DetectOptions::new()
.recursive(true)
.detect_unity_project_dir(Path::new("./projects")) {
Ok(project_path) => {
println!("Found Unity project at: {}", project_path.display());
}
Err(_) => {
println!("No Unity project found in projects directory or subdirectories");
}
}
use std::path::Path;
use uvm_detect::DetectOptions;
// Search recursively but only 3 levels deep
match DetectOptions::new()
.recursive(true)
.max_depth(3)
.detect_unity_project_dir(Path::new("./projects")) {
Ok(project_path) => {
println!("Found Unity project at: {}", project_path.display());
}
Err(_) => {
println!("No Unity project found within 3 directory levels");
}
}
use std::path::Path;
use uvm_detect::DetectOptions;
// Get Unity version from a project directory
match DetectOptions::new()
.recursive(true)
.max_depth(5)
.detect_project_version(Path::new("./my-unity-project")) {
Ok(version) => {
println!("Unity version: {}", version);
}
Err(e) => {
println!("Failed to detect Unity version: {}", e);
}
}
For simple use cases, convenience functions are available:
use std::path::Path;
use uvm_detect::{detect_unity_project_dir, detect_project_version, try_get_project_version};
// Simple project detection (non-recursive)
if let Ok(project_path) = detect_unity_project_dir(Path::new(".")) {
println!("Found Unity project at: {}", project_path.display());
}
// Simple version detection (non-recursive)
if let Ok(version) = detect_project_version(Path::new("./my-unity-project")) {
println!("Unity version: {}", version);
}
// Check if a directory contains Unity project structure
if let Some(version_file_path) = try_get_project_version(Path::new("./suspected-unity-project")) {
println!("Found Unity project! ProjectVersion.txt at: {}", version_file_path.display());
} else {
println!("Not a Unity project directory");
}
This library detects Unity projects by looking for the standard Unity project structure:
UnityProject/
├── ProjectSettings/
│ └── ProjectVersion.txt ← This file is the detection marker
├── Assets/
├── Library/
└── ...
The ProjectVersion.txt file contains Unity editor version information in formats like:
m_EditorVersion: 2021.3.16f1
m_EditorVersionWithRevision: 2021.3.16f1 (4016570cf34f)
The main configuration struct that provides a builder-style API for configuring Unity project detection.
DetectOptions::new() -> SelfCreates a new DetectOptions with default settings:
recursive: false (search only in specified directory)max_depth: u32::MAX (unlimited depth when recursive)case_sensitive: true (for future use)recursive(&mut self, recursive: bool) -> &mut SelfSets whether to search recursively through subdirectories.
max_depth(&mut self, max_depth: u32) -> &mut SelfSets the maximum depth to search when recursive search is enabled. Use u32::MAX for unlimited depth.
case_sensitive(&mut self, case_sensitive: bool) -> &mut SelfSets whether to use case-sensitive path matching (reserved for future functionality).
detect_unity_project_dir(&self, dir: &Path) -> io::Result<PathBuf>Detects a Unity project directory using the configured options.
detect_project_version(&self, dir: &Path) -> io::Result<Version>Detects and parses the Unity version from a Unity project using the configured options.
detect_unity_project_dir(dir: &Path) -> io::Result<PathBuf>Detects a Unity project directory using default options (non-recursive search).
detect_project_version(project_path: &Path) -> io::Result<Version>Detects and parses the Unity version from a Unity project using default options.
try_get_project_version<P: AsRef<Path>>(base_dir: P) -> Option<PathBuf>Attempts to get the path to the Unity ProjectVersion.txt file if it exists.
use std::path::Path;
use uvm_detect::DetectOptions;
let result = DetectOptions::new()
.recursive(true) // Enable recursive search
.max_depth(10) // Limit to 10 directory levels
.case_sensitive(true) // Use case-sensitive matching (future)
.detect_unity_project_dir(Path::new("./workspace"));
match result {
Ok(project_path) => {
println!("Found Unity project at: {}", project_path.display());
// Now get the version from the found project
let version = DetectOptions::new()
.detect_project_version(&project_path)?;
println!("Unity version: {}", version);
}
Err(e) => println!("No Unity project found: {}", e),
}
// For large directory trees, limit depth to improve performance
let result = DetectOptions::new()
.recursive(true)
.max_depth(5) // Only search 5 levels deep
.detect_unity_project_dir(Path::new("./large-workspace"));
The library uses Rust's standard error handling patterns:
io::Result<T> for operations that can fail due to I/O errors or missing projectsOption<T> for simple existence checks where absence isn't an errorCommon error scenarios:
Run the test suite:
cargo test
The library includes comprehensive tests covering:
unity-version - For parsing Unity version stringstempfile (dev-dependency) - For creating temporary test directoriesThis project is part of the Unity Version Manager (UVM) toolkit.
Contributions are welcome! Please ensure that:
cargo test)cargo test --doc)This crate is part of the larger Unity Version Manager ecosystem:
unity-version - Unity version parsing and manipulationuvm_install - Unity installation managementuvm - Main CLI application