A virtual file system for Unity and .NET projects that unifies directory-based storage and .vpk package-based storage behind one API.
- Exposes unified
IFileSystemManagerandIVirtualFileSystemabstractions - Uses
FileSystemManager.AddFileSystem(VFSPath)to auto-detect directories and.vpkpackages - Supports synchronous reads with
GetStream(),ReadAllText(), andReadAllBytes() - Supports asynchronous reads with
GetStreamAsync(),ReadAllTextAsync(), andReadAllBytesAsync() - Includes
PackageVirtualFileSystemfor creating, writing, and reading.vpkfiles - Includes
PackageVirtualFileOperator.CreatePackage()andExtractPackage()for batch workflows - Includes
VFSPathfor normalization, combination, and relative-path handling - Ships a Unity extension for Android
StreamingAssetsaccess - Splits runtime code into
vFrame.VFSandvFrame.VFS.UnityExtensionassemblies
- Unity
2019.4.40f1or a compatible2019.4+release vFrame.CoredependencyvFrame.Core.Unitydependency for the Unity extension package
This repository contains two UPM packages:
com.vyronlee.vframe.vfs1.0.1com.vyronlee.vframe.vfs.unity-extension1.0.1
Add the dependencies to your project's Packages/manifest.json:
{
"dependencies": {
"com.vyronlee.vframe.core": "https://github.com/VyronLee/vFrame.Core.git#upm-core",
"com.vyronlee.vframe.vfs": "https://github.com/VyronLee/vFrame.VFS.git#upm-vfs",
"com.vyronlee.vframe.vfs.unity-extension": "https://github.com/VyronLee/vFrame.VFS.git#upm-vfs-unity"
}
}You can also install them through Unity Package Manager with Window > Package Manager > Add package from git URL....
using vFrame.VFS;
var manager = new FileSystemManager();
manager.Create();
var root = VFSPath.Create(UnityEngine.Application.persistentDataPath).AsDirectory();
manager.AddFileSystem(root);
var text = manager.ReadAllText("config/game.json");
manager.Destroy();using vFrame.VFS;
var manager = new FileSystemManager();
manager.Create();
manager.AddFileSystem(VFSPath.Create(UnityEngine.Application.streamingAssetsPath + "/data.vpk"));
using (var stream = manager.GetStream("config/game.json")) {
var json = stream.ReadAllText();
}
manager.Destroy();FileSystemManager checks mounted file systems in insertion order. The first match wins.
using vFrame.VFS;
var manager = new FileSystemManager();
manager.Create();
manager.AddFileSystem(VFSPath.Create(UnityEngine.Application.persistentDataPath).AsDirectory());
manager.AddFileSystem(VFSPath.Create(UnityEngine.Application.streamingAssetsPath + "/base.vpk"));
var bytes = manager.ReadAllBytes("bundles/ui/panel.prefab");
manager.Destroy();using vFrame.VFS;
var root = VFSPath.Create("D:/GameData").AsDirectory();
var file = VFSPath.Create("config/settings.json");
var full = root.Combine(file);
var fileName = file.GetFileName();
var extension = file.GetExtension();
var directory = full.GetDirectory();
var relative = full.GetRelative(root);using System.IO;
using vFrame.VFS;
var package = PackageVirtualFileSystem.CreatePackage("D:/Build/data.vpk");
using (var input = File.OpenRead("D:/Build/config/game.json")) {
package.AddStream(
"config/game.json",
input,
BlockFlags.BlockEncryptXor,
PackageFileSystemConst.Id,
BlockFlags.BlockCompressLZMA);
}
package.Flush(true);
package.Close();using vFrame.VFS;
PackageVirtualFileOperator.CreatePackage(
"D:/Build/RawData",
"D:/Build/content.vpk",
force: true);
PackageVirtualFileOperator.ExtractPackage(
"D:/Build/content.vpk",
"D:/Build/Extracted",
force: true);using vFrame.VFS;
var manager = new FileSystemManager();
manager.Create();
manager.AddFileSystem(VFSPath.Create("D:/GameData").AsDirectory());
var request = manager.ReadAllTextAsync("config/game.json");
while (!request.IsDone) {
}
var text = request.Result;
manager.Destroy();Assets/vFrame.VFS/Runtime/ConstantsAssets/vFrame.VFS/Runtime/ExceptionsAssets/vFrame.VFS/Runtime/PackageAssets/vFrame.VFS/Runtime/PoolsAssets/vFrame.VFS/Runtime/StandardAssets/vFrame.VFS.UnityExtension/Runtime/3rdAssets/vFrame.VFS.UnityExtension/Runtime/StreamingAssets
vFrame.VFS: core runtime withFileSystemManager,VFSPath,PackageVirtualFileSystem, andPackageVirtualFileOperatorvFrame.VFS.UnityExtension: Unity-specific runtime withvFrame.VFS.UnityExtension.FileSystemManager,SAStandardVirtualFileSystem, andSAPackageVirtualFileSystem
- Standard file system: handled by
StandardVirtualFileSystemfor directories - Package file system: handled by
PackageVirtualFileSystemfor.vpkfiles - Android
StreamingAssets: handled bySAStandardVirtualFileSystemandSAPackageVirtualFileSystem
PackageVirtualFileSystemreads existing package data in read-only mode and only supportsFileMode.OpenwithFileAccess.ReadFileSystemManager.ReadAllText()returns an empty string when no file is found, andReadAllBytes()returnsnullPackageVirtualFileOperator.CreatePackage()defaults toBlockFlags.BlockEncryptXor,PackageFileSystemConst.Id, andBlockFlags.BlockCompressLZMA- On Android, use
vFrame.VFS.UnityExtension.FileSystemManagerforStreamingAssets; do not usevFrame.VFS.FileSystemManager SAStandardVirtualFileSystem.GetFiles()currently throwsNotSupportedException, so AndroidStreamingAssetsenumeration is not supported
This project is licensed under the Apache License 2.0.