Compare commits

...

15 Commits

Author SHA1 Message Date
hevinci
b421e7d2f8 Update CHANGELOG.md 2024-07-31 12:06:23 +08:00
hevinci
0e7c14abde Update package.json 2024-07-31 12:06:15 +08:00
hevinci
caf072ed9b Update DefaultBuildinFileSystemBuild.cs 2024-07-31 12:02:07 +08:00
hevinci
51f2709956 Update EditorTools.cs 2024-07-31 12:01:29 +08:00
hevinci
6680a6450b fix #325
适配unity2019引擎
2024-07-24 10:12:42 +08:00
hevinci
dc119b26c7 fix #321 2024-07-19 12:02:43 +08:00
hevinci
2cbfca4f3b update extension sample
着色器变种文件增加内部排序
2024-07-15 18:51:32 +08:00
何冠峰
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
52 changed files with 486 additions and 371 deletions

View File

@@ -2,6 +2,25 @@
All notable changes to this package will be documented in this file. All notable changes to this package will be documented in this file.
## [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 ## [2.2.0-preview] - 2024-07-07
重构了运行时代码新增了文件系统接口IFileSystem方便开发者扩展特殊需求。 重构了运行时代码新增了文件系统接口IFileSystem方便开发者扩展特殊需求。

View File

@@ -73,12 +73,7 @@ namespace YooAsset.Editor
if (buildResult.Success) if (buildResult.Success)
{ {
SimulateBuildResult reulst = new SimulateBuildResult(); SimulateBuildResult reulst = new SimulateBuildResult();
string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName); reulst.PackageRootDirectory = buildResult.OutputPackageDirectory;
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}";
return reulst; return reulst;
} }
else else

View File

@@ -180,9 +180,9 @@ namespace YooAsset.Editor
for (int index = 0; index < manifest.BundleList.Count; index++) for (int index = 0; index < manifest.BundleList.Count; index++)
{ {
var packageBundle = manifest.BundleList[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 else
{ {

View File

@@ -56,9 +56,9 @@ namespace YooAsset.Editor
string bundleName = collectAssetInfo.BundleName; string bundleName = collectAssetInfo.BundleName;
foreach (var dependAsset in collectAssetInfo.DependAssets) 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 else
{ {

View File

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

View File

@@ -3,6 +3,6 @@ namespace YooAsset.Editor
{ {
public interface IBuildPipeline public interface IBuildPipeline
{ {
public BuildResult Run(BuildParameters buildParameters, bool enableLog); BuildResult Run(BuildParameters buildParameters, bool enableLog);
} }
} }

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, System.Type> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>(); private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
/// <summary> /// <summary>
/// 配置数据是否被修改 /// 配置数据是否被修改
/// </summary> /// </summary>
@@ -275,23 +275,23 @@ namespace YooAsset.Editor
public static bool HasActiveRuleName(string ruleName) public static bool HasActiveRuleName(string ruleName)
{ {
return _cacheActiveRuleTypes.Keys.Contains(ruleName); return _cacheActiveRuleTypes.ContainsKey(ruleName);
} }
public static bool HasAddressRuleName(string ruleName) public static bool HasAddressRuleName(string ruleName)
{ {
return _cacheAddressRuleTypes.Keys.Contains(ruleName); return _cacheAddressRuleTypes.ContainsKey(ruleName);
} }
public static bool HasPackRuleName(string ruleName) public static bool HasPackRuleName(string ruleName)
{ {
return _cachePackRuleTypes.Keys.Contains(ruleName); return _cachePackRuleTypes.ContainsKey(ruleName);
} }
public static bool HasFilterRuleName(string ruleName) public static bool HasFilterRuleName(string ruleName)
{ {
return _cacheFilterRuleTypes.Keys.Contains(ruleName); return _cacheFilterRuleTypes.ContainsKey(ruleName);
} }
public static bool HasIgnoreRuleName(string ruleName) public static bool HasIgnoreRuleName(string ruleName)
{ {
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName); return _cacheIgnoreRuleTypes.ContainsKey(ruleName);
} }
public static IActiveRule GetActiveRuleInstance(string ruleName) public static IActiveRule GetActiveRuleInstance(string ruleName)

View File

@@ -20,7 +20,8 @@ namespace YooAsset.Editor
{ {
public bool IsCollectAsset(FilterRuleData data) public bool IsCollectAsset(FilterRuleData data)
{ {
return Path.GetExtension(data.AssetPath) == ".unity"; string extension = Path.GetExtension(data.AssetPath);
return extension == ".unity" || extension == ".scene";
} }
} }

View File

@@ -559,6 +559,21 @@ namespace YooAsset.Editor
{ {
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式 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> /// <summary>
/// 获取项目工程路径 /// 获取项目工程路径

View File

@@ -106,19 +106,13 @@ namespace YooAsset
} }
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync() public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
{ {
#if UNITY_EDITOR
var operation = new DBFSInitializeInEditorPlayModeOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
#else
var operation = new DBFSInitializeOperation(this); var operation = new DBFSInitializeOperation(this);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
#endif
} }
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{ {
var operation = new DBFSLoadPackageManifestOperation(this); var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -254,6 +248,29 @@ namespace YooAsset
return false; 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 #region
protected string GetDefaultRoot() protected string GetDefaultRoot()
{ {
@@ -288,7 +305,12 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName); 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>
/// 记录文件信息 /// 记录文件信息
/// </summary> /// </summary>

View File

@@ -5,7 +5,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
{ {
public int callbackOrder { get { return 0; } } public int callbackOrder { get { return 0; } }
@@ -24,7 +24,7 @@ namespace YooAsset
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false) if (rootDirectory.Exists == false)
{ {
Debug.LogWarning($"Can not found buildin root folder : {rootPath}"); Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}");
return; return;
} }
@@ -32,10 +32,14 @@ namespace YooAsset
DirectoryInfo[] subDirectories = rootDirectory.GetDirectories(); DirectoryInfo[] subDirectories = rootDirectory.GetDirectories();
foreach (var subDirectory in subDirectories) 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; string packageVersion;
@@ -86,7 +90,8 @@ namespace YooAsset
foreach (var fileInfo in fileInfos) foreach (var fileInfo in fileInfos)
{ {
if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".version" || if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".version" ||
fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes") fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes" ||
fileInfo.Extension == ".json")
continue; continue;
string fileName = fileInfo.Name; string fileName = fileInfo.Name;
@@ -105,8 +110,12 @@ namespace YooAsset
FileUtility.CreateFileDirectory(saveFilePath); FileUtility.CreateFileDirectory(saveFilePath);
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath); UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
#if UNITY_2019
UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.SaveAssets();
UnityEditor.AssetDatabase.Refresh(); #else
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
#endif
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}"); Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
} }
} }

View File

@@ -56,6 +56,13 @@ namespace YooAsset
{ {
if (_loadCatalogFileOp == null) if (_loadCatalogFileOp == null)
{ {
#if UNITY_EDITOR
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
#endif
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem); _loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp); 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, None,
LoadBuildinRawBundle, LoadBuildinRawBundle,
CheckLoadBuildinResult,
Done, Done,
} }
@@ -139,32 +138,17 @@ namespace YooAsset
if (_steps == ESteps.LoadBuildinRawBundle) if (_steps == ESteps.LoadBuildinRawBundle)
{ {
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle); string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
Result = filePath; if (File.Exists(filePath))
_steps = ESteps.CheckLoadBuildinResult;
}
if (_steps == ESteps.CheckLoadBuildinResult)
{
if (Result != null)
{ {
string filePath = Result as string; _steps = ESteps.Done;
if (File.Exists(filePath)) Result = new RawBundle(_fileSystem, _bundle, filePath);
{ Status = EOperationStatus.Succeed;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Can not found buildin raw bundle file : {filePath}";
}
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; 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 private enum ESteps
{ {
None, None,
RequestBuildinPackageVersion,
RequestBuildinPackageHash, RequestBuildinPackageHash,
LoadBuildinPackageManifest, LoadBuildinPackageManifest,
Done, Done,
} }
private readonly DefaultBuildinFileSystem _fileSystem; private readonly DefaultBuildinFileSystem _fileSystem;
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp; private readonly string _packageVersion;
private RequestBuildinPackageHashOperation _requestBuildinPackageHashOp; private RequestBuildinPackageHashOperation _requestBuildinPackageHashOp;
private LoadBuildinPackageManifestOperation _loadBuildinPackageManifestOp; private LoadBuildinPackageManifestOperation _loadBuildinPackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem) public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem, string packageVersion)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_packageVersion = packageVersion;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.RequestBuildinPackageVersion; _steps = ESteps.RequestBuildinPackageHash;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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 (_steps == ESteps.RequestBuildinPackageHash)
{ {
if (_requestBuildinPackageHashOp == null) if (_requestBuildinPackageHashOp == null)
{ {
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion; _requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, _packageVersion);
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, packageVersion);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageHashOp); OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageHashOp);
} }
@@ -83,9 +59,8 @@ namespace YooAsset
{ {
if (_loadBuildinPackageManifestOp == null) if (_loadBuildinPackageManifestOp == null)
{ {
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
string packageHash = _requestBuildinPackageHashOp.PackageHash; string packageHash = _requestBuildinPackageHashOp.PackageHash;
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, packageVersion, packageHash); _loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadBuildinPackageManifestOp); OperationSystem.StartOperation(_fileSystem.PackageName, _loadBuildinPackageManifestOp);
} }

View File

@@ -303,6 +303,23 @@ namespace YooAsset
return Exists(bundle) == false; 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 #region
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024); private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize) public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
@@ -368,7 +385,7 @@ namespace YooAsset
} }
return filePath; return filePath;
} }
public string GetFileLoadPath(PackageBundle bundle) public string GetCacheFileLoadPath(PackageBundle bundle)
{ {
return GetDataFilePath(bundle); return GetDataFilePath(bundle);
} }

View File

@@ -78,7 +78,7 @@ namespace YooAsset
if (_steps == ESteps.LoadAssetBundle) if (_steps == ESteps.LoadAssetBundle)
{ {
string filePath = _fileSystem.GetFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
if (_isWaitForAsyncComplete) if (_isWaitForAsyncComplete)
{ {
Result = AssetBundle.LoadFromFile(filePath); 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); byte[] fileData = FileUtility.ReadAllBytes(filePath);
if (fileData != null && fileData.Length > 0) if (fileData != null && fileData.Length > 0)
{ {
@@ -165,7 +165,7 @@ namespace YooAsset
while (true) while (true)
{ {
if(_downloadFileOp != null) if (_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete(); _downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone()) if (ExecuteWhileDone())
@@ -195,8 +195,7 @@ namespace YooAsset
None, None,
CheckExist, CheckExist,
DownloadFile, DownloadFile,
LoadRawBundle, LoadCacheRawBundle,
CheckResult,
Done, Done,
} }
@@ -226,7 +225,7 @@ namespace YooAsset
{ {
DownloadProgress = 1f; DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize; DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadRawBundle; _steps = ESteps.LoadCacheRawBundle;
} }
else else
{ {
@@ -249,7 +248,7 @@ namespace YooAsset
if (_downloadFileOp.Status == EOperationStatus.Succeed) if (_downloadFileOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.LoadRawBundle; _steps = ESteps.LoadCacheRawBundle;
} }
else else
{ {
@@ -259,35 +258,20 @@ namespace YooAsset
} }
} }
if (_steps == ESteps.LoadRawBundle) if (_steps == ESteps.LoadCacheRawBundle)
{ {
string filePath = _fileSystem.GetFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
Result = filePath; if (File.Exists(filePath))
_steps = ESteps.CheckResult;
}
if (_steps == ESteps.CheckResult)
{
if (Result != null)
{ {
string filePath = Result as string; _steps = ESteps.Done;
if (File.Exists(filePath)) Result = new RawBundle(_fileSystem, _bundle, filePath);
{ Status = EOperationStatus.Succeed;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Can not found cache raw bundle file : {filePath}";
}
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; 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 namespace YooAsset
{ {
/// <summary> /// <summary>
@@ -35,13 +36,6 @@ namespace YooAsset
} }
} }
#region
/// <summary>
/// 自定义参数:模拟构建结果
/// </summary>
public SimulateBuildResult BuildResult { private set; get; } = null;
#endregion
public DefaultEditorFileSystem() public DefaultEditorFileSystem()
{ {
@@ -54,7 +48,7 @@ namespace YooAsset
} }
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{ {
var operation = new DEFSLoadPackageManifestOperation(this); var operation = new DEFSLoadPackageManifestOperation(this, packageVersion);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -92,23 +86,17 @@ namespace YooAsset
public virtual void SetParameter(string name, object value) public virtual void SetParameter(string name, object value)
{ {
if (name == "SIMULATE_BUILD_RESULT") YooLogger.Warning($"Invalid parameter : {name}");
{
BuildResult = (SimulateBuildResult)value;
}
else
{
YooLogger.Warning($"Invalid parameter : {name}");
}
} }
public virtual void OnCreate(string packageName, string rootDirectory) public virtual void OnCreate(string packageName, string rootDirectory)
{ {
PackageName = packageName; PackageName = packageName;
if (string.IsNullOrEmpty(rootDirectory)) 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() public virtual void OnUpdate()
{ {
@@ -135,10 +123,30 @@ namespace YooAsset
return false; return false;
} }
#region public virtual byte[] ReadFileData(PackageBundle bundle)
protected string GetDefaultRoot()
{ {
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 #endregion
} }

View File

@@ -6,33 +6,61 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
LoadEditorPackageHash,
LoadEditorPackageManifest, LoadEditorPackageManifest,
Done, Done,
} }
private readonly DefaultEditorFileSystem _fileSystem; private readonly DefaultEditorFileSystem _fileSystem;
private readonly string _packageVersion;
private LoadEditorPackageHashOperation _loadEditorPackageHashOpe;
private LoadEditorPackageManifestOperation _loadEditorPackageManifestOp; private LoadEditorPackageManifestOperation _loadEditorPackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem) internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_packageVersion = packageVersion;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.LoadEditorPackageManifest; _steps = ESteps.LoadEditorPackageHash;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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 (_steps == ESteps.LoadEditorPackageManifest)
{ {
if (_loadEditorPackageManifestOp == null) if (_loadEditorPackageManifestOp == null)
{ {
_loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem); string packageHash = _loadEditorPackageHashOpe.PackageHash;
_loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageManifestOp); 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, None,
LoadFileData, LoadFileData,
VerifyFileData,
LoadManifest, LoadManifest,
Done, Done,
} }
private readonly DefaultEditorFileSystem _fileSystem; private readonly DefaultEditorFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly string _packageHash;
private DeserializeManifestOperation _deserializer; private DeserializeManifestOperation _deserializer;
private byte[] _fileData; private byte[] _fileData;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -23,9 +26,11 @@ namespace YooAsset
public PackageManifest Manifest { private set; get; } public PackageManifest Manifest { private set; get; }
internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem) internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion, string packageHash)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_packageVersion = packageVersion;
_packageHash = packageHash;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@@ -38,10 +43,10 @@ namespace YooAsset
if (_steps == ESteps.LoadFileData) if (_steps == ESteps.LoadFileData)
{ {
string manifestFilePath = _fileSystem.BuildResult.PackageManifestFilePath; string manifestFilePath = _fileSystem.GetEditorPackageManifestFilePath(_packageVersion);
if (File.Exists(manifestFilePath)) if (File.Exists(manifestFilePath))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.VerifyFileData;
_fileData = FileUtility.ReadAllBytes(manifestFilePath); _fileData = FileUtility.ReadAllBytes(manifestFilePath);
} }
else 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 (_steps == ESteps.LoadManifest)
{ {
if (_deserializer == null) if (_deserializer == null)
@@ -67,7 +87,7 @@ namespace YooAsset
if (_deserializer.Status == EOperationStatus.Succeed) if (_deserializer.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Manifest = _deserializer.Manifest; Manifest = _deserializer.Manifest;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
else else

View File

@@ -35,7 +35,7 @@ namespace YooAsset
if (_steps == ESteps.LoadVersion) if (_steps == ESteps.LoadVersion)
{ {
string versionFilePath = _fileSystem.BuildResult.PackageVersionFilePath; string versionFilePath = _fileSystem.GetEditorPackageVersionFilePath();
if (File.Exists(versionFilePath)) if (File.Exists(versionFilePath))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@@ -157,6 +157,15 @@ namespace YooAsset
return false; return false;
} }
public virtual byte[] ReadFileData(PackageBundle bundle)
{
throw new System.NotImplementedException();
}
public virtual string ReadFileText(PackageBundle bundle)
{
throw new System.NotImplementedException();
}
#region #region
protected string GetDefaultWebRoot() protected string GetDefaultWebRoot()
{ {
@@ -192,6 +201,11 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName); 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

@@ -32,6 +32,13 @@ namespace YooAsset
{ {
if (_loadCatalogFileOp == null) if (_loadCatalogFileOp == null)
{ {
#if UNITY_EDITOR
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
#endif
_loadCatalogFileOp = new LoadWebCatalogFileOperation(_fileSystem); _loadCatalogFileOp = new LoadWebCatalogFileOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp); OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp);
} }

View File

@@ -38,7 +38,7 @@ namespace YooAsset
/// 清空所有的文件 /// 清空所有的文件
/// </summary> /// </summary>
FSClearAllBundleFilesOperation ClearAllBundleFilesAsync(); FSClearAllBundleFilesOperation ClearAllBundleFilesAsync();
/// <summary> /// <summary>
/// 清空未使用的文件 /// 清空未使用的文件
/// </summary> /// </summary>
@@ -95,10 +95,21 @@ namespace YooAsset
/// 是否需要解压 /// 是否需要解压
/// </summary> /// </summary>
bool NeedUnpack(PackageBundle bundle); bool NeedUnpack(PackageBundle bundle);
/// <summary> /// <summary>
/// 是否需要导入 /// 是否需要导入
/// </summary> /// </summary>
bool NeedImport(PackageBundle bundle); 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) public static FileSystemParameters CreateDefaultEditorFileSystemParameters(SimulateBuildResult simulateBuildResult)
{ {
string fileSystemClass = typeof(DefaultEditorFileSystem).FullName; string fileSystemClass = typeof(DefaultEditorFileSystem).FullName;
var fileSystemParams = new FileSystemParameters(fileSystemClass, null); var fileSystemParams = new FileSystemParameters(fileSystemClass, simulateBuildResult.PackageRootDirectory);
fileSystemParams.AddParameter("SIMULATE_BUILD_RESULT", simulateBuildResult);
return fileSystemParams; return fileSystemParams;
} }

View File

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

View File

@@ -72,8 +72,7 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; return Provider.RawBundleObject.ReadFileData();
return FileUtility.ReadAllBytes(filePath);
} }
/// <summary> /// <summary>
@@ -83,8 +82,7 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; return Provider.RawBundleObject.ReadFileText();
return FileUtility.ReadAllText(filePath);
} }
/// <summary> /// <summary>
@@ -94,7 +92,7 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return string.Empty; return string.Empty;
return Provider.RawFilePath; return Provider.RawBundleObject.GetFilePath();
} }
} }
} }

View File

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

View File

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

View File

@@ -32,7 +32,7 @@ namespace YooAsset
return; return;
} }
if (LoadBundleFileOp.Result is string == false) if (LoadBundleFileOp.Result is RawBundle == false)
{ {
string error = "Try load AssetBundle file using load raw file method !"; string error = "Try load AssetBundle file using load raw file method !";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
@@ -45,7 +45,7 @@ namespace YooAsset
// 2. 检测加载结果 // 2. 检测加载结果
if (_steps == ESteps.Checking) if (_steps == ESteps.Checking)
{ {
RawFilePath = LoadBundleFileOp.Result as string; RawBundleObject = LoadBundleFileOp.Result as RawBundle;
InvokeCompletion(string.Empty, EOperationStatus.Succeed); InvokeCompletion(string.Empty, EOperationStatus.Succeed);
} }
} }

View File

@@ -53,7 +53,7 @@ namespace YooAsset
// 2. 检测加载结果 // 2. 检测加载结果
if (_steps == ESteps.Checking) if (_steps == ESteps.Checking)
{ {
RawFilePath = MainAssetInfo.AssetPath; RawBundleObject = new RawBundle(null, null, MainAssetInfo.AssetPath);
InvokeCompletion(string.Empty, EOperationStatus.Succeed); InvokeCompletion(string.Empty, EOperationStatus.Succeed);
} }
#endif #endif

View File

@@ -46,16 +46,16 @@ namespace YooAsset
/// </summary> /// </summary>
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; } public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
/// <summary>
/// 获取的原生对象
/// </summary>
public RawBundle RawBundleObject { protected set; get; }
/// <summary> /// <summary>
/// 加载的场景名称 /// 加载的场景名称
/// </summary> /// </summary>
public string SceneName { protected set; get; } public string SceneName { protected set; get; }
/// <summary>
/// 原生文件路径
/// </summary>
public string RawFilePath { protected set; get; }
/// <summary> /// <summary>
/// 引用计数 /// 引用计数
/// </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, None,
CreateFileSystem, CreateFileSystem,
InitFileSystem, InitFileSystem,
LoadManifestFile,
Done, Done,
} }
private readonly EditorSimulateModeImpl _impl; private readonly EditorSimulateModeImpl _impl;
private readonly EditorSimulateModeParameters _parameters; private readonly EditorSimulateModeParameters _parameters;
private FSInitializeFileSystemOperation _initFileSystemOp; private FSInitializeFileSystemOperation _initFileSystemOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters) internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters)
@@ -71,37 +69,15 @@ namespace YooAsset
return; return;
if (_initFileSystemOp.Status == EOperationStatus.Succeed) if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadManifestFile;
}
else
{ {
_steps = ESteps.Done; _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; Status = EOperationStatus.Succeed;
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _loadPackageManifestOp.Error; Error = _initFileSystemOp.Error;
} }
} }
} }
@@ -117,13 +93,13 @@ namespace YooAsset
None, None,
CreateFileSystem, CreateFileSystem,
InitFileSystem, InitFileSystem,
LoadManifestFile,
Done, Done,
} }
private readonly OfflinePlayModeImpl _impl; private readonly OfflinePlayModeImpl _impl;
private readonly OfflinePlayModeParameters _parameters; private readonly OfflinePlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initFileSystemOp; private FSInitializeFileSystemOperation _initFileSystemOp;
private FSRequestPackageVersionOperation _requestPackageVersionOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp; private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -173,37 +149,15 @@ namespace YooAsset
return; return;
if (_initFileSystemOp.Status == EOperationStatus.Succeed) if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadManifestFile;
}
else
{ {
_steps = ESteps.Done; _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; Status = EOperationStatus.Succeed;
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _loadPackageManifestOp.Error; Error = _initFileSystemOp.Error;
} }
} }
} }

View File

@@ -344,7 +344,7 @@ namespace YooAsset
if (string.IsNullOrEmpty(location) == false) if (string.IsNullOrEmpty(location) == false)
{ {
// 检查路径末尾是否有空格 // 检查路径末尾是否有空格
int index = location.LastIndexOf(" "); int index = location.LastIndexOf(' ');
if (index != -1) if (index != -1)
{ {
if (location.Length == index + 1) if (location.Length == index + 1)

View File

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

View File

@@ -1,9 +1,7 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO; using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text;
namespace YooAsset namespace YooAsset
{ {
@@ -29,7 +27,7 @@ namespace YooAsset
if (string.IsNullOrEmpty(str)) if (string.IsNullOrEmpty(str))
return str; return str;
int index = str.LastIndexOf("."); int index = str.LastIndexOf('.');
if (index == -1) if (index == -1)
return str; return str;
else else
@@ -121,7 +119,7 @@ namespace YooAsset
public static string ReadAllText(string filePath) public static string ReadAllText(string filePath)
{ {
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)
return string.Empty; return null;
return File.ReadAllText(filePath, Encoding.UTF8); return File.ReadAllText(filePath, Encoding.UTF8);
} }

View File

@@ -11,8 +11,10 @@ using UnityEditor;
public class ShaderVariantCollectionManifest public class ShaderVariantCollectionManifest
{ {
[Serializable] [Serializable]
public class ShaderVariantElement public class ShaderVariantElement : IComparable<ShaderVariantElement>
{ {
public string SortValue { private set; get; }
/// <summary> /// <summary>
/// Pass type to use in this variant. /// Pass type to use in this variant.
/// </summary> /// </summary>
@@ -22,11 +24,31 @@ public class ShaderVariantCollectionManifest
/// Array of shader keywords to use in this variant. /// Array of shader keywords to use in this variant.
/// </summary> /// </summary>
public string[] Keywords; 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] [Serializable]
public class ShaderVariantInfo : IComparable<ShaderVariantInfo> public class ShaderVariantInfo : IComparable<ShaderVariantInfo>
{ {
public string SortValue { private set; get; }
/// <summary> /// <summary>
/// 着色器资源路径. /// 着色器资源路径.
/// </summary> /// </summary>
@@ -47,11 +69,13 @@ public class ShaderVariantCollectionManifest
/// </summary> /// </summary>
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000); public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
public void MakeSortValue()
{
SortValue = AssetPath + "+" + ShaderName;
}
public int CompareTo(ShaderVariantInfo other) public int CompareTo(ShaderVariantInfo other)
{ {
string thisStr = AssetPath + "+" +ShaderName; return SortValue.CompareTo(other.SortValue);
string otherStr = other.AssetPath + "+" + other.ShaderName;
return thisStr.CompareTo(otherStr);
} }
} }
@@ -76,10 +100,15 @@ public class ShaderVariantCollectionManifest
/// </summary> /// </summary>
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords) 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); var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
ShaderVariantElement element = new ShaderVariantElement(); ShaderVariantElement element = new ShaderVariantElement();
element.PassType = passType; element.PassType = passType;
element.Keywords = keywords; element.Keywords = temper.ToArray();
element.MakeSortValue();
info.ShaderVariantElements.Add(element); info.ShaderVariantElements.Add(element);
info.ShaderVariantCount++; info.ShaderVariantCount++;
} }
@@ -91,6 +120,7 @@ public class ShaderVariantCollectionManifest
ShaderVariantInfo newInfo = new ShaderVariantInfo(); ShaderVariantInfo newInfo = new ShaderVariantInfo();
newInfo.AssetPath = assetPath; newInfo.AssetPath = assetPath;
newInfo.ShaderName = shaderName; newInfo.ShaderName = shaderName;
newInfo.MakeSortValue();
ShaderVariantInfos.Add(newInfo); ShaderVariantInfos.Add(newInfo);
return newInfo; return newInfo;
} }
@@ -150,6 +180,11 @@ public class ShaderVariantCollectionManifest
// 重新排序 // 重新排序
manifest.ShaderVariantInfos.Sort(); manifest.ShaderVariantInfos.Sort();
foreach (var shaderVariantInfo in manifest.ShaderVariantInfos)
{
shaderVariantInfo.ShaderVariantElements.Sort();
}
return manifest; return manifest;
} }
} }

View File

@@ -21,8 +21,8 @@ public static class ShaderVariantCollector
WaitingDone, WaitingDone,
} }
private const float WaitMilliseconds = 1000f; private const float WaitMilliseconds = 3000f;
private const float SleepMilliseconds = 2000f; private const float SleepMilliseconds = 3000f;
private static string _savePath; private static string _savePath;
private static string _packageName; private static string _packageName;
private static int _processMaxNum; private static int _processMaxNum;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
#if UNITY_WECHAT_GAME #if UNITY_WEBGL && WEIXINMINIGAME
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using YooAsset; using YooAsset;
@@ -52,12 +52,12 @@ internal class WechatFileSystem : IFileSystem
} }
} }
#region #region
/// <summary> /// <summary>
/// 自定义参数:远程服务接口 /// 自定义参数:远程服务接口
/// </summary> /// </summary>
public IRemoteServices RemoteServices { private set; get; } = null; public IRemoteServices RemoteServices { private set; get; } = null;
#endregion #endregion
public WechatFileSystem() public WechatFileSystem()
@@ -162,7 +162,16 @@ internal class WechatFileSystem : IFileSystem
return false; 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) private string GetWXFileLoadPath(PackageBundle bundle)
{ {
if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
@@ -172,6 +181,6 @@ internal class WechatFileSystem : IFileSystem
} }
return filePath; return filePath;
} }
#endregion #endregion
} }
#endif #endif

View File

@@ -100,12 +100,12 @@ public class BattleRoom
if (_startWaitTimer.Update(Time.deltaTime)) if (_startWaitTimer.Update(Time.deltaTime))
{ {
// 生成实体 // 生成实体
var handle = YooAssets.LoadAssetAsync<GameObject>("player_ship"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_ship");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(_roomRoot.transform); handle.InstantiateSync(_roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
_steps = ESteps.SpawnEnemy; _steps = ESteps.SpawnEnemy;
} }
} }
@@ -117,12 +117,12 @@ public class BattleRoom
Quaternion spawnRotation = Quaternion.identity; Quaternion spawnRotation = Quaternion.identity;
// 生成实体 // 生成实体
var handle = YooAssets.LoadAssetAsync<GameObject>(enemyLocation); var assetHandle = YooAssets.LoadAssetAsync<GameObject>(enemyLocation);
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(spawnPosition, spawnRotation, _roomRoot.transform); handle.InstantiateSync(spawnPosition, spawnRotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
_waveSpawnCount++; _waveSpawnCount++;
if (_waveSpawnCount >= EnemyCount) if (_waveSpawnCount >= EnemyCount)
@@ -166,12 +166,12 @@ public class BattleRoom
var msg = message as BattleEventDefine.PlayerDead; var msg = message as BattleEventDefine.PlayerDead;
// 创建爆炸效果 // 创建爆炸效果
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_player"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_player");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform); handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
_steps = ESteps.GameOver; _steps = ESteps.GameOver;
BattleEventDefine.GameOver.SendEventMessage(); BattleEventDefine.GameOver.SendEventMessage();
@@ -181,12 +181,12 @@ public class BattleRoom
var msg = message as BattleEventDefine.EnemyDead; var msg = message as BattleEventDefine.EnemyDead;
// 创建爆炸效果 // 创建爆炸效果
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_enemy"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_enemy");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform); handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
_totalScore += EnemyScore; _totalScore += EnemyScore;
BattleEventDefine.ScoreChange.SendEventMessage(_totalScore); BattleEventDefine.ScoreChange.SendEventMessage(_totalScore);
@@ -196,12 +196,12 @@ public class BattleRoom
var msg = message as BattleEventDefine.AsteroidExplosion; var msg = message as BattleEventDefine.AsteroidExplosion;
// 创建爆炸效果 // 创建爆炸效果
var handle = YooAssets.LoadAssetAsync<GameObject>("explosion_asteroid"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_asteroid");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform); handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
_totalScore += AsteroidScore; _totalScore += AsteroidScore;
BattleEventDefine.ScoreChange.SendEventMessage(_totalScore); BattleEventDefine.ScoreChange.SendEventMessage(_totalScore);
@@ -211,24 +211,24 @@ public class BattleRoom
var msg = message as BattleEventDefine.PlayerFireBullet; var msg = message as BattleEventDefine.PlayerFireBullet;
// 创建子弹实体 // 创建子弹实体
var handle = YooAssets.LoadAssetAsync<GameObject>("player_bullet"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_bullet");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform); handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
} }
else if (message is BattleEventDefine.EnemyFireBullet) else if (message is BattleEventDefine.EnemyFireBullet)
{ {
var msg = message as BattleEventDefine.EnemyFireBullet; var msg = message as BattleEventDefine.EnemyFireBullet;
// 创建子弹实体 // 创建子弹实体
var handle = YooAssets.LoadAssetAsync<GameObject>("enemy_bullet"); var assetHandle = YooAssets.LoadAssetAsync<GameObject>("enemy_bullet");
handle.Completed += (AssetHandle handle) => assetHandle.Completed += (AssetHandle handle) =>
{ {
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform); handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
}; };
_handles.Add(handle); _handles.Add(assetHandle);
} }
} }
} }

View File

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