mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 04:00:16 +00:00
Compare commits
31 Commits
2.2.1-prev
...
2.2.4-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7089952895 | ||
|
|
737d2a796b | ||
|
|
e25fd14675 | ||
|
|
c55dc713f4 | ||
|
|
418536ded1 | ||
|
|
ae454b72dc | ||
|
|
d34d1117a0 | ||
|
|
a5f3767cbc | ||
|
|
3bdb339f54 | ||
|
|
22cb3c3942 | ||
|
|
e5f5241879 | ||
|
|
79ac231df2 | ||
|
|
b7b375092f | ||
|
|
f86ea04521 | ||
|
|
738c02f58f | ||
|
|
d017688416 | ||
|
|
6b56275f87 | ||
|
|
b89f00130e | ||
|
|
4f58c54eff | ||
|
|
9001be21ac | ||
|
|
b421e7d2f8 | ||
|
|
0e7c14abde | ||
|
|
caf072ed9b | ||
|
|
51f2709956 | ||
|
|
0d5558f29f | ||
|
|
c6377ce544 | ||
|
|
07d34891ef | ||
|
|
ddce031ee5 | ||
|
|
6680a6450b | ||
|
|
dc119b26c7 | ||
|
|
2cbfca4f3b |
@@ -2,6 +2,54 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.2.4-preview] - 2024-08-15
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了HostPlayMode初始化卡死的问题。
|
||||
|
||||
## [2.2.3-preview] - 2024-08-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#311) 修复了断点续传下载器极小概率报错 : “416 Range Not Satisfiable”
|
||||
|
||||
### Improvements
|
||||
|
||||
- 原生文件构建管线支持原生文件加密。
|
||||
|
||||
- HostPlayMode模式下内置文件系统初始化参数可以为空。
|
||||
|
||||
- 场景加载增加了LocalPhysicsMode参数来控制物理运行模式。
|
||||
|
||||
- 默认的内置文件系统和缓存文件系统增加解密方法。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的缓存文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
|
||||
```
|
||||
|
||||
## [2.2.2-preview] - 2024-07-31
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#321) 修复了在Unity2022里编辑器下离线模式运行失败的问题。
|
||||
- (#325) 修复了在Unity2019里编译报错问题。
|
||||
|
||||
## [2.2.1-preview] - 2024-07-10
|
||||
|
||||
统一了所有PlayMode的初始化逻辑,EditorSimulateMode和OfflinePlayMode初始化不再主动加载资源清单!
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_BBP : TaskEncryption, IBuildTask
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_RFBP : TaskEncryption, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3e156139dcc25f4c9440ec3d6cb96d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -32,6 +32,7 @@ namespace YooAsset.Editor
|
||||
new TaskPrepare_RFBP(),
|
||||
new TaskGetBuildMap_RFBP(),
|
||||
new TaskBuilding_RFBP(),
|
||||
new TaskEncryption_RFBP(),
|
||||
new TaskUpdateBundleInfo_RFBP(),
|
||||
new TaskCreateManifest_RFBP(),
|
||||
new TaskCreateReport_RFBP(),
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_SBP : TaskEncryption, IBuildTask
|
||||
|
||||
@@ -3,6 +3,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public interface IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog);
|
||||
BuildResult Run(BuildParameters buildParameters, bool enableLog);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,12 @@ namespace YooAsset.Editor
|
||||
AssetPath = assetPath;
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(AssetPath);
|
||||
|
||||
// 注意:如果资源文件损坏或者实例化关联脚本丢失,获取的资源类型会无效!
|
||||
if (AssetType == null)
|
||||
{
|
||||
throw new Exception($"Found invalid asset : {AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -559,6 +559,21 @@ namespace YooAsset.Editor
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除路径里的后缀名
|
||||
/// </summary>
|
||||
public static string RemoveExtension(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return str;
|
||||
|
||||
int index = str.LastIndexOf('.');
|
||||
if (index == -1)
|
||||
return str;
|
||||
else
|
||||
return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test"
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目工程路径
|
||||
|
||||
@@ -98,6 +98,11 @@ namespace YooAsset
|
||||
/// 自定义参数:原生文件构建管线
|
||||
/// </summary>
|
||||
public bool RawFileBuildPipeline { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -172,8 +177,11 @@ namespace YooAsset
|
||||
|
||||
if (_loadedStream.TryGetValue(bundle.BundleGUID, out Stream managedStream))
|
||||
{
|
||||
managedStream.Close();
|
||||
managedStream.Dispose();
|
||||
if (managedStream != null)
|
||||
{
|
||||
managedStream.Close();
|
||||
managedStream.Dispose();
|
||||
}
|
||||
_loadedStream.Remove(bundle.BundleGUID);
|
||||
}
|
||||
}
|
||||
@@ -181,18 +189,22 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == "FILE_VERIFY_LEVEL")
|
||||
if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
{
|
||||
FileVerifyLevel = (EFileVerifyLevel)value;
|
||||
}
|
||||
else if (name == "APPEND_FILE_EXTENSION")
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
AppendFileExtension = (bool)value;
|
||||
}
|
||||
else if (name == "RAW_FILE_BUILD_PIPELINE")
|
||||
else if (name == FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE)
|
||||
{
|
||||
RawFileBuildPipeline = (bool)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
@@ -210,10 +222,11 @@ namespace YooAsset
|
||||
// 创建解压文件系统
|
||||
var remoteServices = new UnpackRemoteServices(_packageRoot);
|
||||
_unpackFileSystem = new DefaultUnpackFileSystem();
|
||||
_unpackFileSystem.SetParameter("REMOTE_SERVICES", remoteServices);
|
||||
_unpackFileSystem.SetParameter("FILE_VERIFY_LEVEL", FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter("APPEND_FILE_EXTENSION", AppendFileExtension);
|
||||
_unpackFileSystem.SetParameter("RAW_FILE_BUILD_PIPELINE", RawFileBuildPipeline);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE, RawFileBuildPipeline);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, DecryptionServices);
|
||||
_unpackFileSystem.OnCreate(packageName, null);
|
||||
}
|
||||
public virtual void OnUpdate()
|
||||
@@ -256,8 +269,28 @@ namespace YooAsset
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileData(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
}
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
@@ -267,8 +300,28 @@ namespace YooAsset
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileText(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
@@ -310,7 +363,7 @@ namespace YooAsset
|
||||
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
return PathUtility.Combine(rootPath, PackageName);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// </summary>
|
||||
@@ -333,6 +386,42 @@ namespace YooAsset
|
||||
{
|
||||
return _unpackFileSystem.InitializeFileSystemAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public AssetBundle LoadEncryptedAssetBundle(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
|
||||
var assetBundle = DecryptionServices.LoadAssetBundle(fileInfo, out var managedStream);
|
||||
_loadedStream.Add(bundle.BundleGUID, managedStream);
|
||||
return assetBundle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public AssetBundleCreateRequest LoadEncryptedAssetBundleAsync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
|
||||
var createRequest = DecryptionServices.LoadAssetBundleAsync(fileInfo, out var managedStream);
|
||||
_loadedStream.Add(bundle.BundleGUID, managedStream);
|
||||
return createRequest;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
YooLogger.Log("Begin to create catalog file !");
|
||||
|
||||
string savePath = $"Assets/Resources/{YooAssetSettingsData.Setting.DefaultYooFolderName}";
|
||||
DirectoryInfo saveDirectory = new DirectoryInfo(savePath);
|
||||
if (saveDirectory.Exists)
|
||||
@@ -24,8 +26,7 @@ namespace YooAsset
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}");
|
||||
return;
|
||||
throw new System.Exception($"Can not found StreamingAssets root directory : {rootPath}");
|
||||
}
|
||||
|
||||
// 搜索所有Package目录
|
||||
@@ -35,7 +36,7 @@ namespace YooAsset
|
||||
CreateBuildinCatalogFile(subDirectory.Name, subDirectory.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
@@ -48,8 +49,7 @@ namespace YooAsset
|
||||
string versionFilePath = $"{pacakgeDirectory}/{versionFileName}";
|
||||
if (File.Exists(versionFilePath) == false)
|
||||
{
|
||||
Debug.LogWarning($"Can not found package version file : {versionFilePath}");
|
||||
return;
|
||||
throw new System.Exception($"Can not found package version file : {versionFilePath}");
|
||||
}
|
||||
|
||||
packageVersion = FileUtility.ReadAllText(versionFilePath);
|
||||
@@ -62,8 +62,7 @@ namespace YooAsset
|
||||
string manifestFilePath = $"{pacakgeDirectory}/{manifestFileName}";
|
||||
if (File.Exists(manifestFilePath) == false)
|
||||
{
|
||||
Debug.LogWarning($"Can not found package manifest file : {manifestFilePath}");
|
||||
return;
|
||||
throw new System.Exception($"Can not found package manifest file : {manifestFilePath}");
|
||||
}
|
||||
|
||||
var binaryData = FileUtility.ReadAllBytes(manifestFilePath);
|
||||
@@ -90,7 +89,8 @@ namespace YooAsset
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".version" ||
|
||||
fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes")
|
||||
fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes" ||
|
||||
fileInfo.Extension == ".json")
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
@@ -109,8 +109,12 @@ namespace YooAsset
|
||||
FileUtility.CreateFileDirectory(saveFilePath);
|
||||
|
||||
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
|
||||
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
|
||||
#if UNITY_2019
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#else
|
||||
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
|
||||
#endif
|
||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuidlinAssetBundle,
|
||||
CheckLoadBuildinResult,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -32,28 +32,56 @@ namespace YooAsset
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadBuidlinAssetBundle;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuidlinAssetBundle)
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
if (_fileSystem.DecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IDecryptionServices)} is null !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_isWaitForAsyncComplete)
|
||||
{
|
||||
Result = AssetBundle.LoadFromFile(filePath);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
Result = _fileSystem.LoadEncryptedAssetBundle(_bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
Result = AssetBundle.LoadFromFile(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_createRequest = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
}
|
||||
}
|
||||
_steps = ESteps.CheckLoadBuildinResult;
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckLoadBuildinResult)
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
{
|
||||
@@ -75,12 +103,22 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load encrypted buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +187,7 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,11 @@ namespace YooAsset
|
||||
/// 自定义参数:断点续传下载器关注的错误码
|
||||
/// </summary>
|
||||
public List<long> ResumeDownloadResponseCodes { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -200,38 +205,45 @@ namespace YooAsset
|
||||
|
||||
if (_loadedStream.TryGetValue(bundle.BundleGUID, out Stream managedStream))
|
||||
{
|
||||
managedStream.Close();
|
||||
managedStream.Dispose();
|
||||
if (managedStream != null)
|
||||
{
|
||||
managedStream.Close();
|
||||
managedStream.Dispose();
|
||||
}
|
||||
_loadedStream.Remove(bundle.BundleGUID);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == "REMOTE_SERVICES")
|
||||
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
else if (name == "FILE_VERIFY_LEVEL")
|
||||
else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
{
|
||||
FileVerifyLevel = (EFileVerifyLevel)value;
|
||||
}
|
||||
else if (name == "APPEND_FILE_EXTENSION")
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
AppendFileExtension = (bool)value;
|
||||
}
|
||||
else if (name == "RAW_FILE_BUILD_PIPELINE")
|
||||
else if (name == FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE)
|
||||
{
|
||||
RawFileBuildPipeline = (bool)value;
|
||||
}
|
||||
else if (name == "RESUME_DOWNLOAD_MINMUM_SIZE")
|
||||
else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_MINMUM_SIZE)
|
||||
{
|
||||
ResumeDownloadMinimumSize = (long)value;
|
||||
}
|
||||
else if (name == "RESUME_DOWNLOAD_RESPONSE_CODES")
|
||||
else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_RESPONSE_CODES)
|
||||
{
|
||||
ResumeDownloadResponseCodes = (List<long>)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
@@ -308,16 +320,56 @@ namespace YooAsset
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileData(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
}
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileText(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
@@ -528,6 +580,42 @@ namespace YooAsset
|
||||
{
|
||||
return _wrappers.Keys.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public AssetBundle LoadEncryptedAssetBundle(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
|
||||
var assetBundle = DecryptionServices.LoadAssetBundle(fileInfo, out var managedStream);
|
||||
_loadedStream.Add(bundle.BundleGUID, managedStream);
|
||||
return assetBundle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public AssetBundleCreateRequest LoadEncryptedAssetBundleAsync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
|
||||
var createRequest = DecryptionServices.LoadAssetBundleAsync(fileInfo, out var managedStream);
|
||||
_loadedStream.Add(bundle.BundleGUID, managedStream);
|
||||
return createRequest;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -250,17 +250,17 @@ namespace YooAsset
|
||||
if (File.Exists(_tempFilePath))
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
||||
fileBeginLength = fileInfo.Length;
|
||||
_fileOriginLength = fileBeginLength;
|
||||
DownloadedBytes = _fileOriginLength;
|
||||
}
|
||||
|
||||
// 检测下载起始位置
|
||||
if (fileBeginLength >= Bundle.FileSize)
|
||||
{
|
||||
// 删除临时文件
|
||||
if (File.Exists(_tempFilePath))
|
||||
if (fileInfo.Length >= Bundle.FileSize)
|
||||
{
|
||||
// 删除临时文件
|
||||
File.Delete(_tempFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileBeginLength = fileInfo.Length;
|
||||
_fileOriginLength = fileBeginLength;
|
||||
DownloadedBytes = _fileOriginLength;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建下载器
|
||||
|
||||
@@ -78,15 +78,43 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
if (_fileSystem.DecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IDecryptionServices)} is null !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_isWaitForAsyncComplete)
|
||||
{
|
||||
Result = AssetBundle.LoadFromFile(filePath);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
Result = _fileSystem.LoadEncryptedAssetBundle(_bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
Result = AssetBundle.LoadFromFile(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_createRequest = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
@@ -112,51 +140,59 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
EFileVerifyResult verifyResult = _fileSystem.VerifyCacheFile(_bundle);
|
||||
if (verifyResult == EFileVerifyResult.Succeed)
|
||||
{
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
EFileVerifyResult verifyResult = _fileSystem.VerifyCacheFile(_bundle);
|
||||
if (verifyResult == EFileVerifyResult.Succeed)
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
byte[] fileData = FileUtility.ReadAllBytes(filePath);
|
||||
if (fileData != null && fileData.Length > 0)
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load encrypted asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
byte[] fileData = FileUtility.ReadAllBytes(filePath);
|
||||
if (fileData != null && fileData.Length > 0)
|
||||
{
|
||||
Result = AssetBundle.LoadFromMemory(fileData);
|
||||
if (Result == null)
|
||||
{
|
||||
Result = AssetBundle.LoadFromMemory(fileData);
|
||||
if (Result == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load assetBundle from memory : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load asset bundle from memory : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to read assetBundle file bytes : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
_fileSystem.DeleteCacheFile(_bundle.BundleGUID);
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Find corrupted file and delete the file : {_bundle.BundleName}";
|
||||
Error = $"Failed to read asset bundle file bytes : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
_fileSystem.DeleteCacheFile(_bundle.BundleGUID);
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Find corrupted asset bundle file and delete : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
@@ -272,6 +308,7 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found cache raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == "DISABLE_UNITY_WEB_CACHE")
|
||||
if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
{
|
||||
DisableUnityWebCache = (bool)value;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class FileSystemParametersDefine
|
||||
{
|
||||
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
|
||||
public const string REMOTE_SERVICES = "REMOTE_SERVICES";
|
||||
public const string DECRYPTION_SERVICES = "DECRYPTION_SERVICES";
|
||||
public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION";
|
||||
public const string RAW_FILE_BUILD_PIPELINE = "RAW_FILE_BUILD_PIPELINE";
|
||||
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
|
||||
public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE";
|
||||
public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b83a734e8baddb46aa731ee31fe988d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -99,28 +99,32 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter("FILE_VERIFY_LEVEL", verifyLevel);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数(原生文件)
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinRawFileSystemParameters(EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultBuildinRawFileSystemParameters(IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter("FILE_VERIFY_LEVEL", verifyLevel);
|
||||
fileSystemParams.AddParameter("APPEND_FILE_EXTENSION", true);
|
||||
fileSystemParams.AddParameter("RAW_FILE_BUILD_PIPELINE", true);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE, true);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -128,14 +132,16 @@ namespace YooAsset
|
||||
/// 创建默认的缓存文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
||||
fileSystemParams.AddParameter("FILE_VERIFY_LEVEL", verifyLevel);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -143,16 +149,18 @@ namespace YooAsset
|
||||
/// 创建默认的缓存文件系统参数(原生文件)
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheRawFileSystemParameters(IRemoteServices remoteServices, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultCacheRawFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
||||
fileSystemParams.AddParameter("FILE_VERIFY_LEVEL", verifyLevel);
|
||||
fileSystemParams.AddParameter("APPEND_FILE_EXTENSION", true);
|
||||
fileSystemParams.AddParameter("RAW_FILE_BUILD_PIPELINE", true);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE, true);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -164,7 +172,7 @@ namespace YooAsset
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter("DISABLE_UNITY_WEB_CACHE", disableUnityWebCache);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,14 @@ namespace YooAsset
|
||||
return IsDone;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空完成回调
|
||||
/// </summary>
|
||||
protected void ClearCompletedCallback()
|
||||
{
|
||||
_callback = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
|
||||
@@ -15,6 +15,10 @@ namespace YooAsset
|
||||
{
|
||||
OnAbort();
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
OnWaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作开始
|
||||
@@ -31,6 +35,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
protected abstract void OnAbort();
|
||||
|
||||
/// <summary>
|
||||
/// 异步等待完成
|
||||
/// </summary>
|
||||
protected virtual void OnWaitForAsyncComplete() { }
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作系统是否繁忙
|
||||
/// </summary>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
||||
add
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid");
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
else
|
||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
||||
remove
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid");
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
@@ -168,13 +168,12 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 卸载子场景
|
||||
// 注意:如果场景正在加载过程,必须等待加载完成后才可以卸载该场景。
|
||||
{
|
||||
var operation = new UnloadSceneOperation(Provider);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,13 @@ namespace YooAsset
|
||||
CheckError,
|
||||
PrepareDone,
|
||||
UnLoadScene,
|
||||
Checking,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly string _error;
|
||||
private readonly ProviderOperation _provider;
|
||||
private AsyncOperation _asyncOp;
|
||||
private AsyncOperation _asyncOp = null;
|
||||
|
||||
internal UnloadSceneOperation(string error)
|
||||
{
|
||||
@@ -96,16 +95,16 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.UnLoadScene)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
if (_asyncOp == null)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone == false)
|
||||
return;
|
||||
|
||||
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
@@ -8,13 +8,24 @@ namespace YooAsset
|
||||
{
|
||||
internal sealed class BundledSceneProvider : ProviderOperation
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
public readonly LoadSceneParameters LoadSceneParams;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private bool _suspendLoadMode;
|
||||
|
||||
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
/// <summary>
|
||||
/// 场景加载模式
|
||||
/// </summary>
|
||||
public LoadSceneMode SceneMode
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
get
|
||||
{
|
||||
return LoadSceneParams.loadSceneMode;
|
||||
}
|
||||
}
|
||||
|
||||
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
LoadSceneParams = loadSceneParams;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
@@ -61,15 +72,14 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。
|
||||
LoadSceneParameters parameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = SceneManager.LoadScene(MainAssetInfo.AssetPath, parameters);
|
||||
SceneObject = SceneManager.LoadScene(MainAssetInfo.AssetPath, LoadSceneParams);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:如果场景不存在异步加载方法返回NULL
|
||||
// 注意:即使是异步加载也要在当帧获取到场景对象
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, LoadSceneParams);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
|
||||
@@ -8,13 +8,24 @@ namespace YooAsset
|
||||
{
|
||||
internal sealed class DatabaseSceneProvider : ProviderOperation
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private bool _suspendLoadMode;
|
||||
public readonly LoadSceneParameters LoadSceneParams;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private bool _suspendLoadMode;
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
/// <summary>
|
||||
/// 场景加载模式
|
||||
/// </summary>
|
||||
public LoadSceneMode SceneMode
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
get
|
||||
{
|
||||
return LoadSceneParams.loadSceneMode;
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
LoadSceneParams = loadSceneParams;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
@@ -53,14 +64,12 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, LoadSceneParams);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, LoadSceneParams);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace YooAsset
|
||||
/// 注意:返回的场景句柄是唯一的,每个场景句柄对应自己的场景提供者对象。
|
||||
/// 注意:业务逻辑层应该避免同时加载一个子场景。
|
||||
/// </summary>
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad, uint priority)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 如果加载的是主场景,则卸载所有缓存的场景
|
||||
if (sceneMode == LoadSceneMode.Single)
|
||||
if (loadSceneParams.loadSceneMode == LoadSceneMode.Single)
|
||||
{
|
||||
UnloadAllScene();
|
||||
}
|
||||
@@ -107,9 +107,9 @@ namespace YooAsset
|
||||
ProviderOperation provider;
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad);
|
||||
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
|
||||
else
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad);
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
|
||||
@@ -45,6 +45,12 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.ClearFileSystemA)
|
||||
{
|
||||
if (_fileSystemA == null)
|
||||
{
|
||||
_steps = ESteps.ClearFileSystemB;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clearAllBundleFilesOpA == null)
|
||||
_clearAllBundleFilesOpA = _fileSystemA.ClearAllBundleFilesAsync();
|
||||
|
||||
|
||||
@@ -45,6 +45,12 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.ClearFileSystemA)
|
||||
{
|
||||
if (_fileSystemA == null)
|
||||
{
|
||||
_steps = ESteps.ClearFileSystemB;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clearUnusedBundleFilesOpA == null)
|
||||
_clearUnusedBundleFilesOpA = _fileSystemA.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace YooAsset
|
||||
long downloadBytes = _cachedDownloadBytes;
|
||||
foreach (var downloader in _downloaders)
|
||||
{
|
||||
downloadBytes += (long)downloader.DownloadedBytes;
|
||||
downloadBytes += downloader.DownloadedBytes;
|
||||
if (downloader.IsDone == false)
|
||||
continue;
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace YooAsset
|
||||
// 下载成功
|
||||
_removeList.Add(downloader);
|
||||
_cachedDownloadCount++;
|
||||
_cachedDownloadBytes += (long)downloader.DownloadedBytes;
|
||||
_cachedDownloadBytes += downloader.DownloadedBytes;
|
||||
}
|
||||
|
||||
// 移除已经完成的下载器(无论成功或失败)
|
||||
|
||||
@@ -201,14 +201,6 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CreateFileSystem)
|
||||
{
|
||||
if (_parameters.BuildinFileSystemParameters == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Buildin file system parameters is null";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parameters.CacheFileSystemParameters == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -217,6 +209,18 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parameters.BuildinFileSystemParameters != null)
|
||||
{
|
||||
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to create buildin file system";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_parameters.DeliveryFileSystemParameters != null)
|
||||
{
|
||||
_impl.DeliveryFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.DeliveryFileSystemParameters);
|
||||
@@ -229,15 +233,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to create buildin file system";
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.CacheFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.CacheFileSystemParameters);
|
||||
if (_impl.CacheFileSystem == null)
|
||||
{
|
||||
@@ -252,6 +247,13 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.InitBuildinFileSystem)
|
||||
{
|
||||
// 注意:内置文件系统可以为空
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.InitDeliveryFileSystem;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_initBuildinFileSystemOp == null)
|
||||
_initBuildinFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset
|
||||
internal class HostPlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
public readonly string PackageName;
|
||||
public IFileSystem BuildinFileSystem { set; get; }
|
||||
public IFileSystem BuildinFileSystem { set; get; } //可以为空!
|
||||
public IFileSystem DeliveryFileSystem { set; get; } //可以为空!
|
||||
public IFileSystem CacheFileSystem { set; get; }
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace YooAsset
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
if (BuildinFileSystem.Belong(packageBundle))
|
||||
if (BuildinFileSystem != null && BuildinFileSystem.Belong(packageBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle);
|
||||
return bundleInfo;
|
||||
|
||||
@@ -486,11 +486,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -498,10 +499,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -509,13 +511,14 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0)
|
||||
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -523,18 +526,20 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0)
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
|
||||
@@ -34,5 +34,15 @@ namespace YooAsset
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream);
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] ReadFileData(DecryptFileInfo fileInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string ReadFileText(DecryptFileInfo fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,10 +161,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneSync(location, sceneMode);
|
||||
return _defaultPackage.LoadSceneSync(location, sceneMode, physicsMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -172,10 +173,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneSync(assetInfo, sceneMode);
|
||||
return _defaultPackage.LoadSceneSync(assetInfo, sceneMode, physicsMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,12 +185,13 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
|
||||
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
return _defaultPackage.LoadSceneAsync(location, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -196,12 +199,13 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
|
||||
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ using UnityEditor;
|
||||
public class ShaderVariantCollectionManifest
|
||||
{
|
||||
[Serializable]
|
||||
public class ShaderVariantElement
|
||||
public class ShaderVariantElement : IComparable<ShaderVariantElement>
|
||||
{
|
||||
public string SortValue { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Pass type to use in this variant.
|
||||
/// </summary>
|
||||
@@ -22,11 +24,31 @@ public class ShaderVariantCollectionManifest
|
||||
/// Array of shader keywords to use in this variant.
|
||||
/// </summary>
|
||||
public string[] Keywords;
|
||||
|
||||
public void MakeSortValue()
|
||||
{
|
||||
string combineKeyword = string.Empty;
|
||||
for (int i = 0; i < Keywords.Length; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
combineKeyword = Keywords[0];
|
||||
else
|
||||
combineKeyword = $"{combineKeyword}+{Keywords[0]}";
|
||||
}
|
||||
|
||||
SortValue = $"{PassType}+{combineKeyword}";
|
||||
}
|
||||
public int CompareTo(ShaderVariantElement other)
|
||||
{
|
||||
return SortValue.CompareTo(other.SortValue);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ShaderVariantInfo : IComparable<ShaderVariantInfo>
|
||||
{
|
||||
public string SortValue { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 着色器资源路径.
|
||||
/// </summary>
|
||||
@@ -47,11 +69,13 @@ public class ShaderVariantCollectionManifest
|
||||
/// </summary>
|
||||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||
|
||||
public void MakeSortValue()
|
||||
{
|
||||
SortValue = AssetPath + "+" + ShaderName;
|
||||
}
|
||||
public int CompareTo(ShaderVariantInfo other)
|
||||
{
|
||||
string thisStr = AssetPath + "+" +ShaderName;
|
||||
string otherStr = other.AssetPath + "+" + other.ShaderName;
|
||||
return thisStr.CompareTo(otherStr);
|
||||
return SortValue.CompareTo(other.SortValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +100,15 @@ public class ShaderVariantCollectionManifest
|
||||
/// </summary>
|
||||
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
||||
{
|
||||
// 排序Keyword列表
|
||||
List<string> temper = new List<string>(keywords);
|
||||
temper.Sort();
|
||||
|
||||
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
||||
ShaderVariantElement element = new ShaderVariantElement();
|
||||
element.PassType = passType;
|
||||
element.Keywords = keywords;
|
||||
element.Keywords = temper.ToArray();
|
||||
element.MakeSortValue();
|
||||
info.ShaderVariantElements.Add(element);
|
||||
info.ShaderVariantCount++;
|
||||
}
|
||||
@@ -91,6 +120,7 @@ public class ShaderVariantCollectionManifest
|
||||
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
||||
newInfo.AssetPath = assetPath;
|
||||
newInfo.ShaderName = shaderName;
|
||||
newInfo.MakeSortValue();
|
||||
ShaderVariantInfos.Add(newInfo);
|
||||
return newInfo;
|
||||
}
|
||||
@@ -150,6 +180,11 @@ public class ShaderVariantCollectionManifest
|
||||
|
||||
// 重新排序
|
||||
manifest.ShaderVariantInfos.Sort();
|
||||
foreach (var shaderVariantInfo in manifest.ShaderVariantInfos)
|
||||
{
|
||||
shaderVariantInfo.ShaderVariantElements.Sort();
|
||||
}
|
||||
|
||||
return manifest;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ public static class ShaderVariantCollector
|
||||
WaitingDone,
|
||||
}
|
||||
|
||||
private const float WaitMilliseconds = 1000f;
|
||||
private const float SleepMilliseconds = 2000f;
|
||||
private const float WaitMilliseconds = 3000f;
|
||||
private const float SleepMilliseconds = 3000f;
|
||||
private static string _savePath;
|
||||
private static string _packageName;
|
||||
private static int _processMaxNum;
|
||||
|
||||
@@ -21,6 +21,36 @@ public static class WechatFileSystemCreater
|
||||
/// </summary>
|
||||
internal class WechatFileSystem : IFileSystem
|
||||
{
|
||||
private class WebRemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _webPackageRoot;
|
||||
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
|
||||
|
||||
public WebRemoteServices(string buildinPackRoot)
|
||||
{
|
||||
_webPackageRoot = buildinPackRoot;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return GetFileLoadURL(fileName);
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return GetFileLoadURL(fileName);
|
||||
}
|
||||
|
||||
private string GetFileLoadURL(string fileName)
|
||||
{
|
||||
if (_mapping.TryGetValue(fileName, out string url) == false)
|
||||
{
|
||||
string filePath = PathUtility.Combine(_webPackageRoot, fileName);
|
||||
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_mapping.Add(fileName, url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, string> _wxFilePaths = new Dictionary<string, string>(10000);
|
||||
private WXFileSystemManager _wxFileSystemMgr;
|
||||
private string _wxFileCacheRoot = string.Empty;
|
||||
@@ -52,12 +82,12 @@ internal class WechatFileSystem : IFileSystem
|
||||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; } = null;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
public WechatFileSystem()
|
||||
@@ -129,6 +159,13 @@ internal class WechatFileSystem : IFileSystem
|
||||
{
|
||||
PackageName = packageName;
|
||||
|
||||
// 注意:CDN服务未启用的情况下,使用微信WEB服务器
|
||||
if (RemoteServices == null)
|
||||
{
|
||||
string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName);
|
||||
RemoteServices = new WebRemoteServices(webRoot);
|
||||
}
|
||||
|
||||
_wxFileSystemMgr = WX.GetFileSystemManager();
|
||||
_wxFileCacheRoot = WX.env.USER_DATA_PATH; //注意:如果有子目录,请修改此处!
|
||||
}
|
||||
@@ -171,7 +208,7 @@ internal class WechatFileSystem : IFileSystem
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
#region 内部方法
|
||||
private string GetWXFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
@@ -181,6 +218,6 @@ internal class WechatFileSystem : IFileSystem
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
@@ -100,12 +100,12 @@ public class BattleRoom
|
||||
if (_startWaitTimer.Update(Time.deltaTime))
|
||||
{
|
||||
// 生成实体
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("player_ship");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_ship");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(_roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
_steps = ESteps.SpawnEnemy;
|
||||
}
|
||||
}
|
||||
@@ -117,12 +117,12 @@ public class BattleRoom
|
||||
Quaternion spawnRotation = Quaternion.identity;
|
||||
|
||||
// 生成实体
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>(enemyLocation);
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>(enemyLocation);
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(spawnPosition, spawnRotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
|
||||
_waveSpawnCount++;
|
||||
if (_waveSpawnCount >= EnemyCount)
|
||||
@@ -166,12 +166,12 @@ public class BattleRoom
|
||||
var msg = message as BattleEventDefine.PlayerDead;
|
||||
|
||||
// 创建爆炸效果
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_player");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_player");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
|
||||
_steps = ESteps.GameOver;
|
||||
BattleEventDefine.GameOver.SendEventMessage();
|
||||
@@ -181,12 +181,12 @@ public class BattleRoom
|
||||
var msg = message as BattleEventDefine.EnemyDead;
|
||||
|
||||
// 创建爆炸效果
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_enemy");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_enemy");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
|
||||
_totalScore += EnemyScore;
|
||||
BattleEventDefine.ScoreChange.SendEventMessage(_totalScore);
|
||||
@@ -196,12 +196,12 @@ public class BattleRoom
|
||||
var msg = message as BattleEventDefine.AsteroidExplosion;
|
||||
|
||||
// 创建爆炸效果
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_asteroid");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_asteroid");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
|
||||
_totalScore += AsteroidScore;
|
||||
BattleEventDefine.ScoreChange.SendEventMessage(_totalScore);
|
||||
@@ -211,24 +211,24 @@ public class BattleRoom
|
||||
var msg = message as BattleEventDefine.PlayerFireBullet;
|
||||
|
||||
// 创建子弹实体
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("player_bullet");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_bullet");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
}
|
||||
else if (message is BattleEventDefine.EnemyFireBullet)
|
||||
{
|
||||
var msg = message as BattleEventDefine.EnemyFireBullet;
|
||||
|
||||
// 创建子弹实体
|
||||
var handle = YooAssets.LoadAssetAsync<GameObject>("enemy_bullet");
|
||||
handle.Completed += (AssetHandle handle) =>
|
||||
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("enemy_bullet");
|
||||
assetHandle.Completed += (AssetHandle handle) =>
|
||||
{
|
||||
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
|
||||
};
|
||||
_handles.Add(handle);
|
||||
_handles.Add(assetHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,22 @@ internal class FsmInitializePackage : IStateNode
|
||||
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
{
|
||||
return 1024;
|
||||
@@ -203,6 +219,22 @@ internal class FsmInitializePackage : IStateNode
|
||||
return AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static ulong GetFileOffset()
|
||||
{
|
||||
return 32;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "2.2.1-preview",
|
||||
"version": "2.2.4-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user