1
This commit is contained in:
70
Src/Unity/Scripts/Mod/UnityAssetModLoader.cs
Normal file
70
Src/Unity/Scripts/Mod/UnityAssetModLoader.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using BITKit.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace BITKit.Mod
|
||||
{
|
||||
public sealed class LoadAssetMod:MyMod
|
||||
{
|
||||
public override async UniTask OnInitializedAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var package = YooAssets.CreatePackage(PackageName);
|
||||
|
||||
var defaultHostServer = new RemoteServices(
|
||||
$"file://{FolderPath}",FolderPath)
|
||||
{
|
||||
|
||||
};
|
||||
var queryServices = new LocalQueryServices($"{FolderPath}");
|
||||
|
||||
var initParameters = new HostPlayModeParameters
|
||||
{
|
||||
BuildinQueryServices = queryServices,
|
||||
RemoteServices = defaultHostServer
|
||||
};
|
||||
var initOperation = package.InitializeAsync(initParameters);
|
||||
await initOperation;
|
||||
|
||||
if(initOperation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
YooAssetUtils.RegisterPackage(PackageName);
|
||||
|
||||
var logBuilder = new StringBuilder();
|
||||
logBuilder.AppendLine("该包中的资源:");
|
||||
foreach (var x in package.GetAssetInfos(Tags))
|
||||
{
|
||||
logBuilder.AppendLine(x.Address);
|
||||
}
|
||||
logBuilder.AppendLine("默认包中的资源");
|
||||
foreach (var x in YooAssets.GetAssetInfos(Tags))
|
||||
{
|
||||
logBuilder.AppendLine(x.Address);
|
||||
}
|
||||
BIT4Log.Log<UnityModLoadAssetTester>(logBuilder.ToString());
|
||||
|
||||
BIT4Log.Log<UnityModLoadAssetTester>($"资源包{PackageName}初始化成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
BIT4Log.Log<UnityModLoadAssetTester>($"资源包初始化失败:{initOperation.Error}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDispose()
|
||||
{
|
||||
YooAssets.DestroyPackage(PackageName);
|
||||
}
|
||||
|
||||
public override void OnDisposed()
|
||||
{
|
||||
YooAssetUtils.UnregisterPackage(PackageName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user