refactor : 重构代码
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using YooAsset;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
#region InitializeParameters
|
||||
/// <summary>
|
||||
@@ -144,7 +146,27 @@ public class UpdatePackageManifestOperation : AsyncOperationBase
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static class CompatibleOldVersion
|
||||
#region ImportFileInfo
|
||||
public struct ImportFileInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地文件路径
|
||||
/// </summary>
|
||||
public string FilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包GUID
|
||||
/// </summary>
|
||||
public string BundleGUID;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static class CompatibleResourcePackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
@@ -221,15 +243,14 @@ public static class CompatibleOldVersion
|
||||
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static RequestPackageVersionOperation RequestPackageVersionAsync(this ResourcePackage package, bool appendTimeTicks = true, int timeout = 60)
|
||||
{
|
||||
var options = new RequestPackageVersionOptions(appendTimeTicks, timeout);
|
||||
var operation = package.RequestPackageVersionAsync(options);
|
||||
return operation;
|
||||
return package.RequestPackageVersionAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -243,15 +264,14 @@ public static class CompatibleOldVersion
|
||||
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static PreDownloadContentOperation PreDownloadContentAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
|
||||
{
|
||||
var options = new PreDownloadContentOptions(packageVersion, timeout);
|
||||
var operation = package.PreDownloadContentAsync(options);
|
||||
return operation;
|
||||
return package.PreDownloadContentAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -271,4 +291,216 @@ public static class CompatibleOldVersion
|
||||
var options = new ClearCacheFilesOptions(fileClearMode, clearParam);
|
||||
return package.ClearCacheFilesAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(this ResourcePackage package, int loopCount)
|
||||
{
|
||||
var options = new UnloadUnusedAssetsOptions(loopCount);
|
||||
return package.UnloadUnusedAssetsAsync(options);
|
||||
}
|
||||
|
||||
#region 资源下载
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var options = new ResourceDownloaderOptions(downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceDownloader(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string tag, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
string[] tags = new string[] { tag };
|
||||
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceDownloader(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string[] tags, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceDownloader(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
|
||||
var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateBundleDownloader(options);
|
||||
}
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
return package.CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||
foreach (var location in locations)
|
||||
{
|
||||
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
|
||||
assetInfos.Add(assetInfo);
|
||||
}
|
||||
|
||||
var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateBundleDownloader(options);
|
||||
}
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
return package.CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateBundleDownloader(options);
|
||||
}
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
return package.CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||
return package.CreateBundleDownloader(options);
|
||||
}
|
||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
return package.CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源解压
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, int unpackingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var options = new ResourceUnpackerOptions(unpackingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceUnpacker(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string tag, int unpackingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
string[] tags = new string[] { tag };
|
||||
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceUnpacker(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceUnpacker(options);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源导入
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
||||
{
|
||||
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
|
||||
for (int i = 0; i < filePaths.Length; i++)
|
||||
{
|
||||
ImportFileInfo fileInfo = new ImportFileInfo();
|
||||
fileInfo.FilePath = filePaths[i];
|
||||
fileInfos[i] = fileInfo;
|
||||
}
|
||||
|
||||
return package.CreateResourceImporter(fileInfos, importerMaxNumber, failedTryAgain);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容Yoo2版本
|
||||
/// </summary>
|
||||
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
|
||||
{
|
||||
ImportBundleInfo[] bundleInfos = new ImportBundleInfo[fileInfos.Length];
|
||||
for (int i = 0; i < fileInfos.Length; i++)
|
||||
{
|
||||
ImportBundleInfo bundleInfo = new ImportBundleInfo();
|
||||
bundleInfo.FilePath = fileInfos[i].FilePath;
|
||||
bundleInfo.BundleName = fileInfos[i].BundleName;
|
||||
bundleInfo.BundleGUID = fileInfos[i].BundleGUID;
|
||||
bundleInfos[i] = bundleInfo;
|
||||
}
|
||||
|
||||
var options = new BundleImporterOptions(bundleInfos, importerMaxNumber, failedTryAgain);
|
||||
return package.CreateResourceImporter(options);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class CompatibleAssetHandle
|
||||
{
|
||||
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent)
|
||||
{
|
||||
var options = new InstantiateOptions(true, parent, false);
|
||||
return handle.InstantiateSync(options);
|
||||
}
|
||||
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent, bool worldPositionStays)
|
||||
{
|
||||
var options = new InstantiateOptions(true, parent, worldPositionStays);
|
||||
return handle.InstantiateSync(options);
|
||||
}
|
||||
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
var options = new InstantiateOptions(true, position, rotation);
|
||||
return handle.InstantiateSync(options);
|
||||
}
|
||||
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent)
|
||||
{
|
||||
var options = new InstantiateOptions(true, parent, position, rotation);
|
||||
return handle.InstantiateSync(options);
|
||||
}
|
||||
|
||||
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool actived = true)
|
||||
{
|
||||
var options = new InstantiateOptions(actived, parent, false);
|
||||
return handle.InstantiateAsync(options);
|
||||
}
|
||||
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool worldPositionStays, bool actived = true)
|
||||
{
|
||||
var options = new InstantiateOptions(actived, parent, worldPositionStays);
|
||||
return handle.InstantiateAsync(options);
|
||||
}
|
||||
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, bool actived = true)
|
||||
{
|
||||
var options = new InstantiateOptions(actived, position, rotation);
|
||||
return handle.InstantiateAsync(options);
|
||||
}
|
||||
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
|
||||
{
|
||||
var options = new InstantiateOptions(actived, parent, position, rotation);
|
||||
return handle.InstantiateAsync(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user