mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-29 12:41:00 +00:00
update mini game sample
新增Google Play文件系统扩展
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d27136885efd6ab4fae1a1fea23b0010
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public static class GooglePlayFileSystemCreater
|
||||||
|
{
|
||||||
|
public static FileSystemParameters CreateFileSystemParameters(string packageRoot)
|
||||||
|
{
|
||||||
|
string fileSystemClass = $"{nameof(GooglePlayFileSystem)},YooAsset.MiniGame";
|
||||||
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
|
return fileSystemParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容谷歌Play Asset Delivery的文件系统
|
||||||
|
/// </summary>
|
||||||
|
internal class GooglePlayFileSystem : DefaultBuildinFileSystem
|
||||||
|
{
|
||||||
|
public GooglePlayFileSystem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||||
|
{
|
||||||
|
var operation = new DBFSLoadAssetBundleOperation(this, bundle);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string error = $"{nameof(GooglePlayFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||||
|
var operation = new FSLoadBundleCompleteOperation(error);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e26d6ba3f3c6cd48bc22d40f1857f89
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 055e7cf3bb9567f43bf15964d43c632f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
using Google.Play.AssetDelivery;
|
||||||
|
|
||||||
|
internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadAssetBundle,
|
||||||
|
CheckResult,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly GooglePlayFileSystem _fileSystem;
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private PlayAssetBundleRequest _bundleRequest;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal GPFSLoadAssetBundleOperation(GooglePlayFileSystem fileSystem, PackageBundle bundle)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_bundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _bundle.FileSize;
|
||||||
|
_steps = ESteps.LoadAssetBundle;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadAssetBundle)
|
||||||
|
{
|
||||||
|
if (_bundle.Encrypted)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The {nameof(GooglePlayFileSystem)} not support bundle encrypted !";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(_bundle.FileName);
|
||||||
|
_steps = ESteps.CheckResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckResult)
|
||||||
|
{
|
||||||
|
if (_bundleRequest.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_bundleRequest.Error != AssetDeliveryErrorCode.NoError)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Failed to load delivery asset bundle file : {_bundle.BundleName} Error : {_bundleRequest.Error}";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = new AssetBundleResult(_fileSystem, _bundle, _bundleRequest.AssetBundle, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
if (_steps != ESteps.Done)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"{nameof(GooglePlayFileSystem)} not support sync load method !";
|
||||||
|
UnityEngine.Debug.LogError(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0aeb57dcd2a7a8841bb161f5f343a25e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"references": [
|
"references": [
|
||||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||||
"GUID:5efd170ecd8084500bed5692932fe14e",
|
"GUID:5efd170ecd8084500bed5692932fe14e",
|
||||||
"GUID:bb21d6197862c4c3e863390dec9859a7"
|
"GUID:bb21d6197862c4c3e863390dec9859a7",
|
||||||
|
"GUID:870f26a2ffa82429195df0861505c5d5"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user