Compare commits

...

8 Commits

Author SHA1 Message Date
何冠峰
7d8fce6f46 Update CHANGELOG.md 2024-07-10 16:54:45 +08:00
何冠峰
13ad50aef5 Update package.json 2024-07-10 16:54:43 +08:00
何冠峰
30245b3668 update extension sample 2024-07-10 16:50:19 +08:00
何冠峰
589eea7cf3 update file system
统一所有PlayMode的初始化行为
2024-07-09 23:37:20 +08:00
何冠峰
24c5108ce1 update asset bundle collector
适配团结引擎
2024-07-09 16:33:41 +08:00
何冠峰
21fbb01ce4 merge #317
根据NETAnalyzers调整代码
2024-07-08 18:54:07 +08:00
何冠峰
e664f20d34 update extension sample 2024-07-08 17:36:39 +08:00
何冠峰
b0ce14dc0e update file system
IFileSystem新增ReadFileData方法
2024-07-08 17:36:25 +08:00
47 changed files with 392 additions and 339 deletions

View File

@@ -2,6 +2,18 @@
All notable changes to this package will be documented in this file.
## [2.2.1-preview] - 2024-07-10
统一了所有PlayMode的初始化逻辑EditorSimulateMode和OfflinePlayMode初始化不再主动加载资源清单
### Added
- 新增了IFileSystem.ReadFileData方法支持原生文件自定义获取文本和二进制数据。
### Improvements
- 优化了DefaultWebFileSystem和DefaultBuildFileSystem文件系统的内部初始化逻辑。
## [2.2.0-preview] - 2024-07-07
重构了运行时代码新增了文件系统接口IFileSystem方便开发者扩展特殊需求。

View File

@@ -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

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -14,7 +14,7 @@ namespace YooAsset.Editor
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
{
return new string[] { };
return Array.Empty<string>();
}
}
}

View File

@@ -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)

View File

@@ -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";
}
}

View File

@@ -106,19 +106,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;
}
@@ -254,6 +248,29 @@ namespace YooAsset
return false;
}
public virtual byte[] ReadFileData(PackageBundle bundle)
{
if (NeedUnpack(bundle))
return _unpackFileSystem.ReadFileData(bundle);
if (Exists(bundle) == false)
return null;
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;
string filePath = GetBuildinFileLoadPath(bundle);
return FileUtility.ReadAllText(filePath);
}
#region
protected string GetDefaultRoot()
{
@@ -288,7 +305,12 @@ 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>
/// 记录文件信息
/// </summary>

View File

@@ -24,7 +24,7 @@ namespace YooAsset
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false)
{
Debug.LogWarning($"Can not found buildin root folder : {rootPath}");
Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}");
return;
}
@@ -32,10 +32,14 @@ namespace YooAsset
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;

View File

@@ -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;
}
}
}
}

View File

@@ -111,7 +111,6 @@ namespace YooAsset
{
None,
LoadBuildinRawBundle,
CheckLoadBuildinResult,
Done,
}
@@ -139,32 +138,17 @@ 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}";
}
}
}

View File

@@ -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);
}

View File

@@ -303,6 +303,23 @@ namespace YooAsset
return Exists(bundle) == false;
}
public virtual byte[] ReadFileData(PackageBundle bundle)
{
if (Exists(bundle) == false)
return null;
string filePath = GetCacheFileLoadPath(bundle);
return FileUtility.ReadAllBytes(filePath);
}
public virtual string ReadFileText(PackageBundle bundle)
{
if (Exists(bundle) == false)
return null;
string filePath = GetCacheFileLoadPath(bundle);
return FileUtility.ReadAllText(filePath);
}
#region
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
@@ -368,7 +385,7 @@ namespace YooAsset
}
return filePath;
}
public string GetFileLoadPath(PackageBundle bundle)
public string GetCacheFileLoadPath(PackageBundle bundle)
{
return GetDataFilePath(bundle);
}

View File

@@ -78,7 +78,7 @@ namespace YooAsset
if (_steps == ESteps.LoadAssetBundle)
{
string filePath = _fileSystem.GetFileLoadPath(_bundle);
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
if (_isWaitForAsyncComplete)
{
Result = AssetBundle.LoadFromFile(filePath);
@@ -122,7 +122,7 @@ namespace YooAsset
{
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
string filePath = _fileSystem.GetFileLoadPath(_bundle);
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
byte[] fileData = FileUtility.ReadAllBytes(filePath);
if (fileData != null && fileData.Length > 0)
{
@@ -165,7 +165,7 @@ namespace YooAsset
while (true)
{
if(_downloadFileOp != null)
if (_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone())
@@ -195,8 +195,7 @@ namespace YooAsset
None,
CheckExist,
DownloadFile,
LoadRawBundle,
CheckResult,
LoadCacheRawBundle,
Done,
}
@@ -226,7 +225,7 @@ namespace YooAsset
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadRawBundle;
_steps = ESteps.LoadCacheRawBundle;
}
else
{
@@ -249,7 +248,7 @@ namespace YooAsset
if (_downloadFileOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadRawBundle;
_steps = ESteps.LoadCacheRawBundle;
}
else
{
@@ -259,35 +258,20 @@ 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}";
}
}
}

View File

@@ -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
}

View File

@@ -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);
}

View File

@@ -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}";
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 137c898b6a637c74d8d5e281e6124a72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -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;

View File

@@ -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>
/// 记录文件信息

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -92,8 +92,7 @@ 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;
}

View File

@@ -67,7 +67,7 @@ namespace YooAsset
/// <summary>
/// 子资源对象集合
/// </summary>
public UnityEngine.Object[] AllAssetObjects
public IReadOnlyList<UnityEngine.Object> AllAssetObjects
{
get
{

View File

@@ -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();
}
}
}

View File

@@ -67,7 +67,7 @@ namespace YooAsset
/// <summary>
/// 子资源对象集合
/// </summary>
public UnityEngine.Object[] AllAssetObjects
public IReadOnlyList<UnityEngine.Object> AllAssetObjects
{
get
{

View File

@@ -45,7 +45,7 @@ namespace YooAsset
public long DownloadedBytes { set; get; } = 0;
/// <summary>
/// 载结果
/// 载结果
/// </summary>
public object Result { set; get; }

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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>

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6e71c986d2a8c74d981deeed7b5a8ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}

View File

@@ -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)

View File

@@ -3,8 +3,6 @@ namespace YooAsset
{
public class SimulateBuildResult
{
public string PackageVersionFilePath;
public string PackageManifestFilePath;
public string PackageHashFilePath;
public string PackageRootDirectory;
}
}

View File

@@ -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);
}

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOperation

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal class LoadWechatPackageManifestOperation : AsyncOperationBase

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal class RequestWechatPackageHashOperation : AsyncOperationBase

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal class RequestWechatPackageVersionOperation : AsyncOperationBase

View File

@@ -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

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "2.2.0-preview",
"version": "2.2.1-preview",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {