mirror of https://github.com/tuyoogame/YooAsset
update extension sample
parent
16117b67f1
commit
8d1f0d2010
|
@ -126,15 +126,19 @@ internal class ByteGameFileSystem : IFileSystem
|
|||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
{
|
||||
var operation = new BGFSLoadBundleOperation(this, bundle);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual void UnloadBundleFile(PackageBundle bundle, object result)
|
||||
{
|
||||
AssetBundle assetBundle = result as AssetBundle;
|
||||
if (assetBundle != null)
|
||||
assetBundle.Unload(true);
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new BGFSLoadBundleOperation(this, bundle);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(ByteGameFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
var operation = new FSLoadBundleCompleteOperation(error);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
|
@ -190,15 +194,19 @@ internal class ByteGameFileSystem : IFileSystem
|
|||
return false;
|
||||
}
|
||||
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
private string GetCacheFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#if UNITY_WEBGL && BYTEMINIGAME
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using WeChatWASM;
|
||||
using YooAsset;
|
||||
|
||||
internal class BGFSLoadBundleOperation : FSLoadBundleOperation
|
||||
|
@ -48,9 +49,19 @@ internal class BGFSLoadBundleOperation : FSLoadBundleOperation
|
|||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = (_webRequest.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
|
||||
Status = EOperationStatus.Succeed;
|
||||
var assetBundle = (_webRequest.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
|
||||
if (assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(DownloadHandlerAssetBundle)} loaded asset bundle is null !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new AssetBundleResult(_fileSystem, _bundle, assetBundle, null);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4c0dec5e8fae814eb7ac0299187e8f4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,68 @@
|
|||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using WeChatWASM;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class WXAssetBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
|
||||
public WXAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.WXUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 750c122b5d921aa4a9c882e21982ebd5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -49,9 +49,19 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = (_webRequest.downloadHandler as DownloadHandlerWXAssetBundle).assetBundle;
|
||||
Status = EOperationStatus.Succeed;
|
||||
var assetBundle = (_webRequest.downloadHandler as DownloadHandlerWXAssetBundle).assetBundle;
|
||||
if (assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(DownloadHandlerWXAssetBundle)} loaded asset bundle is null !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -66,7 +76,7 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "WebGL platform not support sync load method !";
|
||||
Error = "Wechat platform not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,15 +147,19 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
{
|
||||
var operation = new WXFSLoadBundleOperation(this, bundle);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual void UnloadBundleFile(PackageBundle bundle, object result)
|
||||
{
|
||||
AssetBundle assetBundle = result as AssetBundle;
|
||||
if (assetBundle != null)
|
||||
assetBundle.WXUnload(true);
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new WXFSLoadBundleOperation(this, bundle);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(WechatFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
var operation = new FSLoadBundleCompleteOperation(error);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
|
@ -181,9 +185,9 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
|
||||
_wxFileSystemMgr = WX.GetFileSystemManager();
|
||||
_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
|
||||
//_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE/子目录"; //注意:如果有子目录,请修改此处!
|
||||
//_fileCacheRoot = PathUtility.Combine(WX.PluginCachePath, $"StreamingAssets/WebGL");
|
||||
_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
|
||||
//_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE/子目录"; //注意:如果有子目录,请修改此处!
|
||||
//_fileCacheRoot = PathUtility.Combine(WX.PluginCachePath, $"StreamingAssets/WebGL");
|
||||
}
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
|
@ -214,7 +218,11 @@ internal class WechatFileSystem : IFileSystem
|
|||
return false;
|
||||
}
|
||||
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||||
{
|
||||
return GetCacheFileLoadPath(bundle);
|
||||
}
|
||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
if (CheckCacheFileExist(filePath))
|
||||
|
@ -222,7 +230,7 @@ internal class WechatFileSystem : IFileSystem
|
|||
else
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
if (CheckCacheFileExist(filePath))
|
||||
|
|
Loading…
Reference in New Issue