mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 20:20:08 +00:00
Compare commits
33 Commits
2.2.0-prev
...
2.2.3-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
7d8fce6f46 | ||
|
|
13ad50aef5 | ||
|
|
30245b3668 | ||
|
|
589eea7cf3 | ||
|
|
24c5108ce1 | ||
|
|
21fbb01ce4 | ||
|
|
e664f20d34 | ||
|
|
b0ce14dc0e |
@@ -2,6 +2,60 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [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初始化不再主动加载资源清单!
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了IFileSystem.ReadFileData方法,支持原生文件自定义获取文本和二进制数据。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 优化了DefaultWebFileSystem和DefaultBuildFileSystem文件系统的内部初始化逻辑。
|
||||
|
||||
## [2.2.0-preview] - 2024-07-07
|
||||
|
||||
重构了运行时代码,新增了文件系统接口(IFileSystem)方便开发者扩展特殊需求。
|
||||
|
||||
@@ -73,12 +73,7 @@ namespace YooAsset.Editor
|
||||
if (buildResult.Success)
|
||||
{
|
||||
SimulateBuildResult reulst = new SimulateBuildResult();
|
||||
string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
string hashFileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
reulst.PackageVersionFilePath = $"{buildResult.OutputPackageDirectory}/{versionFileName}";
|
||||
reulst.PackageManifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||
reulst.PackageHashFilePath = $"{buildResult.OutputPackageDirectory}/{hashFileName}";
|
||||
reulst.PackageRootDirectory = buildResult.OutputPackageDirectory;
|
||||
return reulst;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -180,9 +180,9 @@ namespace YooAsset.Editor
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[index];
|
||||
if (_cacheBundleTags.ContainsKey(index))
|
||||
if (_cacheBundleTags.TryGetValue(index, out var value))
|
||||
{
|
||||
packageBundle.Tags = _cacheBundleTags[index].ToArray();
|
||||
packageBundle.Tags = value.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -56,9 +56,9 @@ namespace YooAsset.Editor
|
||||
string bundleName = collectAssetInfo.BundleName;
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(dependAsset.AssetPath))
|
||||
if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out var value))
|
||||
{
|
||||
allBuildAssetInfos[dependAsset.AssetPath].AddReferenceBundleName(bundleName);
|
||||
value.AddReferenceBundleName(bundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace YooAsset.Editor
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
{
|
||||
return new string[] { };
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset.Editor
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 配置数据是否被修改
|
||||
/// </summary>
|
||||
@@ -275,23 +275,23 @@ namespace YooAsset.Editor
|
||||
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheActiveRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheAddressRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||
return _cachePackRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheFilterRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasIgnoreRuleName(string ruleName)
|
||||
{
|
||||
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheIgnoreRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
|
||||
@@ -20,7 +20,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
string extension = Path.GetExtension(data.AssetPath);
|
||||
return extension == ".unity" || extension == ".scene";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -106,19 +111,13 @@ namespace YooAsset
|
||||
}
|
||||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var operation = new DBFSInitializeInEditorPlayModeOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
#else
|
||||
var operation = new DBFSInitializeOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
#endif
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this);
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -178,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);
|
||||
}
|
||||
}
|
||||
@@ -187,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}");
|
||||
@@ -216,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()
|
||||
@@ -254,6 +261,69 @@ namespace YooAsset
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
{
|
||||
if (NeedUnpack(bundle))
|
||||
return _unpackFileSystem.ReadFileData(bundle);
|
||||
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
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)
|
||||
{
|
||||
if (NeedUnpack(bundle))
|
||||
return _unpackFileSystem.ReadFileText(bundle);
|
||||
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
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 内部方法
|
||||
protected string GetDefaultRoot()
|
||||
{
|
||||
@@ -288,6 +358,11 @@ namespace YooAsset
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public string GetStreamingAssetsPackageRoot()
|
||||
{
|
||||
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
return PathUtility.Combine(rootPath, PackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
@@ -311,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,18 +26,21 @@ namespace YooAsset
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"Can not found buildin root folder : {rootPath}");
|
||||
return;
|
||||
throw new System.Exception($"Can not found StreamingAssets root directory : {rootPath}");
|
||||
}
|
||||
|
||||
// 搜索所有Package目录
|
||||
DirectoryInfo[] subDirectories = rootDirectory.GetDirectories();
|
||||
foreach (var subDirectory in subDirectories)
|
||||
{
|
||||
CreateBuildinManifest(subDirectory.Name, subDirectory.FullName);
|
||||
CreateBuildinCatalogFile(subDirectory.Name, subDirectory.FullName);
|
||||
}
|
||||
}
|
||||
private void CreateBuildinManifest(string packageName, string pacakgeDirectory)
|
||||
|
||||
/// <summary>
|
||||
/// 生成包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
public static void CreateBuildinCatalogFile(string packageName, string pacakgeDirectory)
|
||||
{
|
||||
// 获取资源清单版本
|
||||
string packageVersion;
|
||||
@@ -44,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);
|
||||
@@ -58,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);
|
||||
@@ -86,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;
|
||||
@@ -105,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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,13 @@ namespace YooAsset
|
||||
{
|
||||
if (_loadCatalogFileOp == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 兼容性初始化
|
||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
||||
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
|
||||
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
|
||||
#endif
|
||||
|
||||
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp);
|
||||
}
|
||||
@@ -77,110 +84,4 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在编辑器下离线模式的兼容性初始化
|
||||
/// </summary>
|
||||
internal sealed class DBFSInitializeInEditorPlayModeOperation : FSInitializeFileSystemOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitUnpackFileSystem,
|
||||
LoadPackageManifest,
|
||||
RecordFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
||||
private DBFSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal DBFSInitializeInEditorPlayModeOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitUnpackFileSystem)
|
||||
{
|
||||
if (_initUnpackFIleSystemOp == null)
|
||||
_initUnpackFIleSystemOp = _fileSystem.InitializeUpackFileSystem();
|
||||
|
||||
Progress = _initUnpackFIleSystemOp.Progress;
|
||||
if (_initUnpackFIleSystemOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_initUnpackFIleSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initUnpackFIleSystemOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
_loadPackageManifestOp = new DBFSLoadPackageManifestOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp);
|
||||
}
|
||||
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.RecordFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RecordFiles)
|
||||
{
|
||||
PackageManifest manifest = _loadPackageManifestOp.Manifest;
|
||||
string pacakgeDirectory = _fileSystem.FileRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
|
||||
FileInfo[] fileInfos = rootDirectory.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".version" ||
|
||||
fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes")
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle value))
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(fileName);
|
||||
_fileSystem.RecordFile(value.BundleGUID, fileWrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Failed to mapping buildin bundle file : {fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +149,6 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadBuildinRawBundle,
|
||||
CheckLoadBuildinResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -139,32 +176,18 @@ namespace YooAsset
|
||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
Result = filePath;
|
||||
_steps = ESteps.CheckLoadBuildinResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckLoadBuildinResult)
|
||||
{
|
||||
if (Result != null)
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string filePath = Result as string;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
}
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundle(_fileSystem, _bundle, filePath);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load buildin raw bundle file : {_bundle.BundleName}";
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,61 +6,37 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestBuildinPackageVersion,
|
||||
RequestBuildinPackageHash,
|
||||
LoadBuildinPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private readonly string _packageVersion;
|
||||
private RequestBuildinPackageHashOperation _requestBuildinPackageHashOp;
|
||||
private LoadBuildinPackageManifestOperation _loadBuildinPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem)
|
||||
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.RequestBuildinPackageVersion;
|
||||
_steps = ESteps.RequestBuildinPackageHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestBuildinPackageVersion)
|
||||
{
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.RequestBuildinPackageHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestBuildinPackageHash)
|
||||
{
|
||||
if (_requestBuildinPackageHashOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, packageVersion);
|
||||
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, _packageVersion);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageHashOp);
|
||||
}
|
||||
|
||||
@@ -83,9 +59,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_loadBuildinPackageManifestOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
string packageHash = _requestBuildinPackageHashOp.PackageHash;
|
||||
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, packageVersion, packageHash);
|
||||
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadBuildinPackageManifestOp);
|
||||
}
|
||||
|
||||
|
||||
@@ -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}");
|
||||
@@ -303,6 +315,63 @@ namespace YooAsset
|
||||
return Exists(bundle) == false;
|
||||
}
|
||||
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
{
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
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;
|
||||
|
||||
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 内部方法
|
||||
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
|
||||
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
@@ -368,7 +437,7 @@ namespace YooAsset
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetFileLoadPath(PackageBundle bundle)
|
||||
public string GetCacheFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
return GetDataFilePath(bundle);
|
||||
}
|
||||
@@ -511,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.GetFileLoadPath(_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.GetFileLoadPath(_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()
|
||||
@@ -165,7 +201,7 @@ namespace YooAsset
|
||||
|
||||
while (true)
|
||||
{
|
||||
if(_downloadFileOp != null)
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
@@ -195,8 +231,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
LoadRawBundle,
|
||||
CheckResult,
|
||||
LoadCacheRawBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -226,7 +261,7 @@ namespace YooAsset
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadRawBundle;
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -249,7 +284,7 @@ namespace YooAsset
|
||||
|
||||
if (_downloadFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadRawBundle;
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -259,35 +294,21 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadRawBundle)
|
||||
if (_steps == ESteps.LoadCacheRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetFileLoadPath(_bundle);
|
||||
Result = filePath;
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (Result != null)
|
||||
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string filePath = Result as string;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found cache raw bundle file : {filePath}";
|
||||
}
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundle(_fileSystem, _bundle, filePath);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load cache raw bundle file : {_bundle.BundleName}";
|
||||
Error = $"Can not found cache raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
@@ -35,13 +36,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:模拟构建结果
|
||||
/// </summary>
|
||||
public SimulateBuildResult BuildResult { private set; get; } = null;
|
||||
#endregion
|
||||
|
||||
|
||||
public DefaultEditorFileSystem()
|
||||
{
|
||||
@@ -54,7 +48,7 @@ namespace YooAsset
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DEFSLoadPackageManifestOperation(this);
|
||||
var operation = new DEFSLoadPackageManifestOperation(this, packageVersion);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -92,23 +86,17 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == "SIMULATE_BUILD_RESULT")
|
||||
{
|
||||
BuildResult = (SimulateBuildResult)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
}
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
}
|
||||
public virtual void OnCreate(string packageName, string rootDirectory)
|
||||
{
|
||||
PackageName = packageName;
|
||||
|
||||
if (string.IsNullOrEmpty(rootDirectory))
|
||||
rootDirectory = GetDefaultRoot();
|
||||
throw new Exception($"{nameof(DefaultEditorFileSystem)} root directory is null or empty !");
|
||||
|
||||
_packageRoot = PathUtility.Combine(rootDirectory, packageName);
|
||||
// 注意:基础目录即为包裹目录
|
||||
_packageRoot = rootDirectory;
|
||||
}
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
@@ -135,10 +123,30 @@ namespace YooAsset
|
||||
return false;
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
protected string GetDefaultRoot()
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
{
|
||||
return "Assets/";
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
public string GetEditorPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public string GetEditorPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public string GetEditorPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -6,33 +6,61 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadEditorPackageHash,
|
||||
LoadEditorPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultEditorFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private LoadEditorPackageHashOperation _loadEditorPackageHashOpe;
|
||||
private LoadEditorPackageManifestOperation _loadEditorPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem)
|
||||
internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadEditorPackageManifest;
|
||||
_steps = ESteps.LoadEditorPackageHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadEditorPackageHash)
|
||||
{
|
||||
if (_loadEditorPackageHashOpe == null)
|
||||
{
|
||||
_loadEditorPackageHashOpe = new LoadEditorPackageHashOperation(_fileSystem, _packageVersion);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageHashOpe);
|
||||
}
|
||||
|
||||
if (_loadEditorPackageHashOpe.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadEditorPackageHashOpe.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadEditorPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadEditorPackageHashOpe.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadEditorPackageManifest)
|
||||
{
|
||||
if (_loadEditorPackageManifestOp == null)
|
||||
{
|
||||
_loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem);
|
||||
string packageHash = _loadEditorPackageHashOpe.PackageHash;
|
||||
_loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageManifestOp);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadEditorPackageHashOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadHash,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultEditorFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹哈希值
|
||||
/// </summary>
|
||||
public string PackageHash { private set; get; }
|
||||
|
||||
|
||||
internal LoadEditorPackageHashOperation(DefaultEditorFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadHash)
|
||||
{
|
||||
string hashFilePath = _fileSystem.GetEditorPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
PackageHash = FileUtility.ReadAllText(hashFilePath);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found simulation package hash file : {hashFilePath}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 137c898b6a637c74d8d5e281e6124a72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,11 +8,14 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadFileData,
|
||||
VerifyFileData,
|
||||
LoadManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultEditorFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private readonly string _packageHash;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private byte[] _fileData;
|
||||
private ESteps _steps = ESteps.None;
|
||||
@@ -23,9 +26,11 @@ namespace YooAsset
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem)
|
||||
internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion, string packageHash)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
_packageHash = packageHash;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -38,10 +43,10 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadFileData)
|
||||
{
|
||||
string manifestFilePath = _fileSystem.BuildResult.PackageManifestFilePath;
|
||||
string manifestFilePath = _fileSystem.GetEditorPackageManifestFilePath(_packageVersion);
|
||||
if (File.Exists(manifestFilePath))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
_steps = ESteps.VerifyFileData;
|
||||
_fileData = FileUtility.ReadAllBytes(manifestFilePath);
|
||||
}
|
||||
else
|
||||
@@ -52,6 +57,21 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
string fileHash = HashUtility.BytesMD5(_fileData);
|
||||
if (fileHash == _packageHash)
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify simulation package manifest file !";
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifest)
|
||||
{
|
||||
if (_deserializer == null)
|
||||
@@ -67,7 +87,7 @@ namespace YooAsset
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Manifest = _deserializer.Manifest;
|
||||
Manifest = _deserializer.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadVersion)
|
||||
{
|
||||
string versionFilePath = _fileSystem.BuildResult.PackageVersionFilePath;
|
||||
string versionFilePath = _fileSystem.GetEditorPackageVersionFilePath();
|
||||
if (File.Exists(versionFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -157,6 +157,15 @@ namespace YooAsset
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
protected string GetDefaultWebRoot()
|
||||
{
|
||||
@@ -192,6 +201,11 @@ namespace YooAsset
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public string GetStreamingAssetsPackageRoot()
|
||||
{
|
||||
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
return PathUtility.Combine(rootPath, PackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
|
||||
@@ -32,6 +32,13 @@ namespace YooAsset
|
||||
{
|
||||
if (_loadCatalogFileOp == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 兼容性初始化
|
||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
||||
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
|
||||
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
|
||||
#endif
|
||||
|
||||
_loadCatalogFileOp = new LoadWebCatalogFileOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
@@ -38,7 +38,7 @@ namespace YooAsset
|
||||
/// 清空所有的文件
|
||||
/// </summary>
|
||||
FSClearAllBundleFilesOperation ClearAllBundleFilesAsync();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清空未使用的文件
|
||||
/// </summary>
|
||||
@@ -95,10 +95,21 @@ namespace YooAsset
|
||||
/// 是否需要解压
|
||||
/// </summary>
|
||||
bool NeedUnpack(PackageBundle bundle);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要导入
|
||||
/// </summary>
|
||||
bool NeedImport(PackageBundle bundle);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件二进制数据
|
||||
/// </summary>
|
||||
byte[] ReadFileData(PackageBundle bundle);
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件文本数据
|
||||
/// </summary>
|
||||
string ReadFileText(PackageBundle bundle);
|
||||
}
|
||||
}
|
||||
@@ -92,36 +92,39 @@ namespace YooAsset
|
||||
public static FileSystemParameters CreateDefaultEditorFileSystemParameters(SimulateBuildResult simulateBuildResult)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultEditorFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter("SIMULATE_BUILD_RESULT", simulateBuildResult);
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, simulateBuildResult.PackageRootDirectory);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
@@ -129,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;
|
||||
}
|
||||
|
||||
@@ -144,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;
|
||||
}
|
||||
|
||||
@@ -165,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>
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
public IReadOnlyList<UnityEngine.Object> AllAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -72,8 +72,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
return Provider.RawBundleObject.ReadFileData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,8 +82,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
return Provider.RawBundleObject.ReadFileText();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +92,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return string.Empty;
|
||||
return Provider.RawFilePath;
|
||||
return Provider.RawBundleObject.GetFilePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
public IReadOnlyList<UnityEngine.Object> AllAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
public long DownloadedBytes { set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 下载结果
|
||||
/// 加载结果
|
||||
/// </summary>
|
||||
public object Result { set; get; }
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if (LoadBundleFileOp.Result is string == false)
|
||||
if (LoadBundleFileOp.Result is RawBundle == false)
|
||||
{
|
||||
string error = "Try load AssetBundle file using load raw file method !";
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
// 2. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
RawFilePath = LoadBundleFileOp.Result as string;
|
||||
RawBundleObject = LoadBundleFileOp.Result as RawBundle;
|
||||
InvokeCompletion(string.Empty, 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;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace YooAsset
|
||||
// 2. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
RawFilePath = MainAssetInfo.AssetPath;
|
||||
RawBundleObject = new RawBundle(null, null, MainAssetInfo.AssetPath);
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -46,16 +46,16 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取的原生对象
|
||||
/// </summary>
|
||||
public RawBundle RawBundleObject { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载的场景名称
|
||||
/// </summary>
|
||||
public string SceneName { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件路径
|
||||
/// </summary>
|
||||
public string RawFilePath { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
|
||||
36
Assets/YooAsset/Runtime/ResourceManager/RawBundle.cs
Normal file
36
Assets/YooAsset/Runtime/ResourceManager/RawBundle.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundle
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly string _filePath;
|
||||
|
||||
internal RawBundle(IFileSystem fileSystem, PackageBundle packageBundle, string filePath)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
_filePath = filePath;
|
||||
}
|
||||
|
||||
public string GetFilePath()
|
||||
{
|
||||
return _filePath;
|
||||
}
|
||||
public byte[] ReadFileData()
|
||||
{
|
||||
if (_fileSystem != null)
|
||||
return _fileSystem.ReadFileData(_packageBundle);
|
||||
else
|
||||
return FileUtility.ReadAllBytes(_filePath);
|
||||
}
|
||||
public string ReadFileText()
|
||||
{
|
||||
if (_fileSystem != null)
|
||||
return _fileSystem.ReadFileText(_packageBundle);
|
||||
else
|
||||
return FileUtility.ReadAllText(_filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Runtime/ResourceManager/RawBundle.cs.meta
Normal file
11
Assets/YooAsset/Runtime/ResourceManager/RawBundle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e71c986d2a8c74d981deeed7b5a8ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// 移除已经完成的下载器(无论成功或失败)
|
||||
|
||||
@@ -18,14 +18,12 @@ namespace YooAsset
|
||||
None,
|
||||
CreateFileSystem,
|
||||
InitFileSystem,
|
||||
LoadManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly EditorSimulateModeImpl _impl;
|
||||
private readonly EditorSimulateModeParameters _parameters;
|
||||
private FSInitializeFileSystemOperation _initFileSystemOp;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters)
|
||||
@@ -71,37 +69,15 @@ namespace YooAsset
|
||||
return;
|
||||
|
||||
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initFileSystemOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifestFile)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
_loadPackageManifestOp = _impl.EditorFileSystem.LoadPackageManifestAsync(null, int.MaxValue);
|
||||
|
||||
Progress = _loadPackageManifestOp.Progress;
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
_impl.ActiveManifest = _loadPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
Error = _initFileSystemOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,13 +93,13 @@ namespace YooAsset
|
||||
None,
|
||||
CreateFileSystem,
|
||||
InitFileSystem,
|
||||
LoadManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly OfflinePlayModeImpl _impl;
|
||||
private readonly OfflinePlayModeParameters _parameters;
|
||||
private FSInitializeFileSystemOperation _initFileSystemOp;
|
||||
private FSRequestPackageVersionOperation _requestPackageVersionOp;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -173,37 +149,15 @@ namespace YooAsset
|
||||
return;
|
||||
|
||||
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initFileSystemOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifestFile)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
_loadPackageManifestOp = _impl.BuildinFileSystem.LoadPackageManifestAsync(null, int.MaxValue);
|
||||
|
||||
Progress = _loadPackageManifestOp.Progress;
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
_impl.ActiveManifest = _loadPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
Error = _initFileSystemOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,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;
|
||||
@@ -263,6 +209,19 @@ 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;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parameters.DeliveryFileSystemParameters != null)
|
||||
{
|
||||
_impl.DeliveryFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.DeliveryFileSystemParameters);
|
||||
@@ -275,15 +234,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)
|
||||
{
|
||||
@@ -298,6 +248,13 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.InitBuildinFileSystem)
|
||||
{
|
||||
// 注意:内置文件系统可以为空
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.InitDeliveryFileSystem;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_initBuildinFileSystemOp == null)
|
||||
_initBuildinFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
// 检查路径末尾是否有空格
|
||||
int index = location.LastIndexOf(" ");
|
||||
int index = location.LastIndexOf(' ');
|
||||
if (index != -1)
|
||||
{
|
||||
if (location.Length == index + 1)
|
||||
|
||||
@@ -3,8 +3,6 @@ namespace YooAsset
|
||||
{
|
||||
public class SimulateBuildResult
|
||||
{
|
||||
public string PackageVersionFilePath;
|
||||
public string PackageManifestFilePath;
|
||||
public string PackageHashFilePath;
|
||||
public string PackageRootDirectory;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -29,7 +27,7 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return str;
|
||||
|
||||
int index = str.LastIndexOf(".");
|
||||
int index = str.LastIndexOf('.');
|
||||
if (index == -1)
|
||||
return str;
|
||||
else
|
||||
@@ -121,7 +119,7 @@ namespace YooAsset
|
||||
public static string ReadAllText(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return string.Empty;
|
||||
return null;
|
||||
return File.ReadAllText(filePath, Encoding.UTF8);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using YooAsset;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using YooAsset;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class LoadWechatPackageManifestOperation : AsyncOperationBase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class RequestWechatPackageHashOperation : AsyncOperationBase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class RequestWechatPackageVersionOperation : AsyncOperationBase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_WECHAT_GAME
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
@@ -52,12 +52,12 @@ internal class WechatFileSystem : IFileSystem
|
||||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; } = null;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
public WechatFileSystem()
|
||||
@@ -162,7 +162,16 @@ internal class WechatFileSystem : IFileSystem
|
||||
return false;
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
private string GetWXFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
@@ -172,6 +181,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.0-preview",
|
||||
"version": "2.2.3-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user