A Unity asset extractor for Python based on AssetStudio that supports extraction, editing, and manipulation of Unity game assets.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core functionality for loading Unity asset files, directories, and compressed bundles. The Environment class serves as the primary interface for managing multiple asset files and provides unified access to all contained objects.
The main class for loading and managing Unity assets. It can load individual files, entire directories, or mixed collections of asset files.
class Environment:
"""
Main interface for loading and managing Unity asset files.
Can load:
- Individual asset files (.assets, .unity3d, .bundle)
- Directories containing asset files
- Compressed bundles and archives
- ZIP files containing Unity assets
"""
def __init__(self, *args, fs=None, path=None):
"""
Initialize Environment with asset files or directories.
Parameters:
- *args: File paths, directory paths, or file-like objects to load
- fs: Optional filesystem interface (defaults to local filesystem)
- path: Base path for relative file operations
"""
def load_file(self, file, parent=None, name=None, is_dependency=False):
"""
Load a single asset file into the Environment.
Parameters:
- file: File path, file-like object, or bytes to load
- parent: Parent Environment or File object
- name: Optional name for the loaded file
- is_dependency: Whether this is a dependency file
Returns:
Loaded file object (SerializedFile, BundleFile, or WebFile)
"""
def load_folder(self, path: str):
"""
Load all files in a directory and subdirectories.
Parameters:
- path: Directory path to scan recursively
"""
def load_files(self, files):
"""
Load multiple files and merge split files automatically.
Parameters:
- files: List of file paths to load
"""
def save(self, pack="none", out_path="output"):
"""
Save all modified assets to disk.
Parameters:
- pack: Compression method ("none", "lz4")
- out_path: Output directory path
"""
@property
def objects(self):
"""
Get all objects from all loaded files.
Returns:
List[ObjectReader]: All objects in the Environment
"""
@property
def container(self):
"""
Get the container mapping for asset paths.
Returns:
Dict mapping asset paths to objects
"""Convenience functions for asset loading with various input types.
def load(*args, **kwargs):
"""
Create and return an Environment with loaded assets.
Parameters:
- *args: Same as Environment.__init__
- **kwargs: Same as Environment.__init__
Returns:
Environment: Initialized Environment with loaded assets
"""Support for encrypted asset bundles with custom decryption keys.
def set_assetbundle_decrypt_key(key):
"""
Set the decryption key for encrypted asset bundles.
Parameters:
- key: Decryption key as bytes or string
"""import UnityPy
# Load a single asset file
env = UnityPy.Environment("game_data.assets")
# Load multiple specific files
env = UnityPy.Environment("file1.assets", "file2.bundle", "file3.unity3d")
# Alternative using load function
env = UnityPy.load("path/to/asset.bundle")import UnityPy
# Load all assets in a directory
env = UnityPy.Environment("Assets/")
# Load folder with specific path
env = UnityPy.Environment()
env.load_folder("StreamingAssets/")import UnityPy
# Load ZIP file containing Unity assets
env = UnityPy.Environment("game_assets.zip")
# Load APK file (which is a ZIP)
env = UnityPy.Environment("game.apk")import UnityPy
# Set decryption key before loading
UnityPy.set_assetbundle_decrypt_key(b"my_secret_key")
# Load encrypted bundle
env = UnityPy.Environment("encrypted.bundle")import UnityPy
env = UnityPy.load("game_assets/")
# Get all objects
all_objects = env.objects
print(f"Loaded {len(all_objects)} objects")
# Access container mapping
container = env.container
for path, obj in container.items():
print(f"Asset path: {path} -> Object ID: {obj.path_id}")
# Filter objects by type
textures = [obj for obj in env.objects if obj.type.name == "Texture2D"]
audio_clips = [obj for obj in env.objects if obj.type.name == "AudioClip"]import UnityPy
env = UnityPy.load("original_assets/")
# Modify some objects...
for obj in env.objects:
if obj.type.name == "Texture2D":
texture = obj.read()
texture.name = "modified_" + texture.name
obj.save(texture)
# Save with no compression
env.save(pack="none", out_path="modified_assets/")
# Save with LZ4 compression
env.save(pack="lz4", out_path="compressed_assets/")import UnityPy
from fsspec.implementations.http import HTTPFileSystem
# Load from HTTP
http_fs = HTTPFileSystem()
env = UnityPy.Environment("https://example.com/assets.bundle", fs=http_fs)
# Load with custom base path
env = UnityPy.Environment(path="/game/assets/")
env.load_file("relative/path/to/asset.bundle")
# Load split files (automatically merged)
env = UnityPy.Environment("large_asset.split0") # Will load all split partsInstall with Tessl CLI
npx tessl i tessl/pypi-unitypy