mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
using System.IO;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
|
|
namespace HotMain.SHGame.YooAsset
|
|
{
|
|
public class RemoteServices : IRemoteServices
|
|
{
|
|
private string defaultHostServer;
|
|
private string fallbackHostServer;
|
|
|
|
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
|
{
|
|
this.defaultHostServer = defaultHostServer;
|
|
this.fallbackHostServer = fallbackHostServer;
|
|
}
|
|
|
|
public string GetRemoteMainURL(string fileName)
|
|
{
|
|
return $"{defaultHostServer}/{fileName}";
|
|
}
|
|
|
|
public string GetRemoteFallbackURL(string fileName)
|
|
{
|
|
return $"{fallbackHostServer}/{fileName}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 资源文件解密流
|
|
/// </summary>
|
|
public class BundleStream : FileStream
|
|
{
|
|
public const byte KEY = 64;
|
|
|
|
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
|
{
|
|
}
|
|
|
|
public BundleStream(string path, FileMode mode) : base(path, mode)
|
|
{
|
|
}
|
|
|
|
public override int Read(byte[] array, int offset, int count)
|
|
{
|
|
var index = base.Read(array, offset, count);
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] ^= KEY;
|
|
}
|
|
|
|
return index;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 资源文件流加载解密类
|
|
/// </summary>
|
|
public class FileStreamDecryption : IDecryptionServices
|
|
{
|
|
/// <summary>
|
|
/// 同步方式获取解密的资源包对象
|
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
/// </summary>
|
|
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
|
{
|
|
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
managedStream = bundleStream;
|
|
return AssetBundle.LoadFromStream(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步方式获取解密的资源包对象
|
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
/// </summary>
|
|
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
|
{
|
|
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
managedStream = bundleStream;
|
|
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
|
}
|
|
|
|
private static uint GetManagedReadBufferSize()
|
|
{
|
|
return 1024;
|
|
}
|
|
}
|
|
|
|
} |