1个不稳定版本
0.1.0 | 2021年2月4日 |
---|
#2135在游戏开发
在bevy_assetio_zip中使用
8KB
129 行
bevy_assetio_zip
一个允许从可选加密的zip资产包中读取的Bevy AssetIo实现。使用bevy_assetio_zip_bundler
crate,你还可以在build.rs
脚本中自动将你的资产打包成所需的格式。
使用方法
只需在设置Bevy应用时启用插件,即可启用从资产包文件加载。
App::build()
// Any config must be inserted before adding plugins. This is optional.
.add_resource(AssetIoZipConfig {
// The name of the asset bundle file, excluding the extension, to load
file_name: "assets".into(), // This is the default
})
// Add the default plugins
.add_plugins_with(DefaultPlugins, |group| {
// With our additinoal asset IO plugin
group.add_before::<bevy::asset::AssetPlugin, _>(AssetIoZipPlugin)
})
.run();
一旦启用插件,当尝试加载资产时,游戏现在将搜索与可执行文件相邻的assets.zip
和assets.bin
文件。如果zip文件中找不到资产,它将尝试使用目标平台默认的Bevy资产加载器加载该资产。
资产包类型
此插件支持两种类型的资产包文件,普通.zip
文件和混淆zip文件(具有.bin
扩展名)。普通.zip
文件是典型的zip文件,可以使用常规的zip软件创建。混淆zip文件可以使用bevy_assetio_zip_bundler
创建,它只是一个经过字节XOR操作(0b01010101
)的正常zip文件。
⚠️警告:混淆zip文件并不能真正保护你的资产安全。即使它被混淆,解密资产包也是轻而易举的。混淆zip文件只是防止普通用户立即查看数据的措施。
资产打包
要打包你的bevy资产,可以使用bevy_assetio_zip_bundler
crate。使用它的最简单方法是将其添加到你的build.rs
文件中。
fn main() {
bevy_assetio_zip_bundler::bundle_crate_assets();
}
在编译发布版本时,这会自动将您存储箱的 assets
文件夹压缩,并将其放置在您的 target/
目录中。在分发您的应用程序时,只需将资产包放置在可执行文件旁边,Bevy 会尝试从包中加载资源,如果失败则回退到 assets
目录。
您可以通过创建一个位于您的 Cargo.toml
文件旁边的 asset_config.toml
文件来配置包的名称、混淆和压缩。
# Bundle assets even for debug builds
bundle-for-debug-builds = true # Default: false
# Obfuscate assets. This doesn't protect from reverse-engineering, but it makes it a little harder
# for the average user to read them.
obfuscate = true # Default: false
# Compress the asset bundle using Bzip2 compression. Other options are "deflate" and "none".
compression = "bzip2" # Default: "bzip2"
# The name of the file, not counting the exention, which will be different based on the `obfuscate`
# setting. Obfuscated bundles will end in `.bin` and non-obfuscated bundles will end in `.zip`.
file-name = "assets" # Default: "assets"
# Set the directory that asset bundle should be placed.
out-dir = "../target" # Default "./target"
或者,如果您想创建自己的工具或自定义资产打包过程,可以使用 bevy_assetio_zip_bundler::bundle_assets
函数手动打包资源。
Bevy 版本
每个插件版本支持的 Bevy 版本
Bevy 版本 | 插件版本 |
---|---|
0.4 | 0.1 |
master | 0.1 版本,带有 bevy-unstable 功能(见下文) |
从 Master 使用 Bevy
您可以通过向您的 Cargo.toml
添加补丁,并将 bevy-unstable
功能添加到这个包中来使用此包与 Bevy master。
[dependencies]
# Bevy version must be set to "0.4" and we will
# override it in the patch below.
bevy = "0.4"
bevy_assetio_zip = { version = "0.1", features = ["bevy-unstable"] }
[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy.git" }
请注意,由于 Bevy master 可能或可能不会引入破坏性 API 变更,此包在使用 bevy-unstable
功能时可能或可能无法编译。
许可证
此包受 Katharos 许可证 的许可,该许可证对您可以使用它做什么有一定的限制。请在使用此包之前阅读并理解条款。
lib.rs
:
为 bevy_assetio_zip
包使用的设计为打包的资产。有关用法,请参阅 bevy_assetio_zip
。
许可证
此包受 Katharos 许可证 的许可,该许可证对您可以使用它做什么有一定的限制。请在使用此包之前阅读并理解条款。
依赖项
~2–11MB
~98K SLoC