mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-30 05:28:46 +00:00
feat : kuaishou file system support
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cb01efe8cc1750a49878ca2be225ba0c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#if UNITY_WEBGL && KUAISHOUMINIGAME
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
public static class KuaiShouFileSystemCreater
|
||||||
|
{
|
||||||
|
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
|
||||||
|
{
|
||||||
|
string fileSystemClass = $"{nameof(KuaiShouFileSystem)},YooAsset.MiniGame";
|
||||||
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
|
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
|
||||||
|
return fileSystemParams;
|
||||||
|
}
|
||||||
|
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor decryptor)
|
||||||
|
{
|
||||||
|
string fileSystemClass = $"{nameof(KuaiShouFileSystem)},YooAsset.MiniGame";
|
||||||
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
|
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
|
||||||
|
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, decryptor);
|
||||||
|
return fileSystemParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 快手小游戏文件系统
|
||||||
|
/// </summary>
|
||||||
|
internal class KuaiShouFileSystem : WebGameFileSystem
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override IWebGamePlatform CreatePlatform(string packageRoot)
|
||||||
|
{
|
||||||
|
return new KuaiShouPlatform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d27b37f59044ec690f3c407aa125c4a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#if UNITY_WEBGL && KUAISHOUMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using YooAsset;
|
||||||
|
using KSWASM;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 快手小游戏平台实现
|
||||||
|
/// </summary>
|
||||||
|
internal class KuaiShouPlatform : IWebGamePlatform
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public UnityWebRequest CreateAssetBundleRequest(string url)
|
||||||
|
{
|
||||||
|
return KSAssetBundle.GetAssetBundle(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public AssetBundle ExtractAssetBundle(UnityWebRequest request)
|
||||||
|
{
|
||||||
|
var downloadHandler = (DownloadHandlerKSAssetBundle)request.downloadHandler;
|
||||||
|
return downloadHandler.assetBundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void UnloadAssetBundle(AssetBundle assetBundle, bool unloadAll)
|
||||||
|
{
|
||||||
|
assetBundle.KSUnload(unloadAll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 50f0ee9a7d764190a8419e11437074bd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# 快手小游戏文件系统
|
||||||
|
|
||||||
|
该示例用于在 YooAsset 的 WebGL 运行模式下接入快手小游戏。
|
||||||
|
|
||||||
|
参考文档:[快手 Unity/团结 WebGL 小游戏适配方案](https://open.kuaishou.com/miniGameDocs/gameDev/Unity/Basic/Introduction.html)
|
||||||
|
|
||||||
|
## 环境要求
|
||||||
|
|
||||||
|
先安装快手小游戏 Unity/团结 WebGL 适配 SDK,并将项目切换到 WebGL 构建目标。
|
||||||
|
|
||||||
|
在 WebGL Player 的 Scripting Define Symbols 中启用以下宏:
|
||||||
|
|
||||||
|
- `KUAISHOUMINIGAME`
|
||||||
|
|
||||||
|
该宏是 YooAsset 快手小游戏示例约定的编译开关,用于和其它小游戏平台适配代码保持一致。
|
||||||
|
|
||||||
|
如果启用宏后编译提示找不到 `KSWASM`、`KSAssetBundle` 或 `DownloadHandlerKSAssetBundle`,请确认快手 SDK 已导入,并将快手 SDK 的程序集引用添加到 `YooAsset.MiniGame.asmdef`。
|
||||||
|
|
||||||
|
## 初始化 YooAsset
|
||||||
|
|
||||||
|
在快手小游戏构建中初始化 `WebPlayModeOptions` 时,使用 `KuaiShouFileSystemCreater` 创建文件系统参数。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
#if UNITY_WEBGL && KUAISHOUMINIGAME && !UNITY_EDITOR
|
||||||
|
var createParameters = new WebPlayModeOptions();
|
||||||
|
|
||||||
|
string defaultHostServer = GetHostServerURL();
|
||||||
|
string fallbackHostServer = GetHostServerURL();
|
||||||
|
string packageRoot = "/__GAME_FILE_CACHE";
|
||||||
|
IRemoteService remoteService = new RemoteService(defaultHostServer, fallbackHostServer);
|
||||||
|
|
||||||
|
createParameters.WebServerFileSystemParameters =
|
||||||
|
KuaiShouFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteService);
|
||||||
|
|
||||||
|
var initializationOperation = package.InitializePackageAsync(createParameters);
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
对当前文件系统来说,`packageRoot` 只需要是一个非空值。快手小游戏底层会对远程 AssetBundle 请求做平台适配,业务侧仍然按照远程异步加载流程使用 YooAsset。
|
||||||
|
|
||||||
|
## 资源包命名
|
||||||
|
|
||||||
|
快手小游戏构建推荐让资源包文件名携带 hash。YooAsset 推荐只使用 `HashName` 文件命名风格。
|
||||||
|
|
||||||
|
`HashName` 会生成纯 hash 文件名,例如:
|
||||||
|
|
||||||
|
```text
|
||||||
|
8d265a9dfd6cb7669cdb8b726f0afb1e.bundle
|
||||||
|
```
|
||||||
|
|
||||||
|
该命名方式更适合小游戏平台的缓存和更新识别,也能避免暴露原始 Bundle 名称。快手小游戏构建不建议使用 `BundleName` 或 `BundleName_HashName`。
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
加密 AssetBundle 仍然会走 YooAsset 常规的 Web 下载和解密流程。非加密 AssetBundle 会使用快手平台适配器,并通过 `KSAssetBundle.GetAssetBundle` 发起请求。
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2d2cb0b979f440d28b12c81794662e88
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user