mirror of https://github.com/tuyoogame/YooAsset
fix #507
parent
6155256fb6
commit
8556e071fa
|
@ -1,13 +1,14 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置资源清单目录
|
||||
/// </summary>
|
||||
internal class DefaultBuildinFileCatalog : ScriptableObject
|
||||
[Serializable]
|
||||
internal class DefaultBuildinFileCatalog
|
||||
{
|
||||
[Serializable]
|
||||
public class FileWrapper
|
||||
|
|
|
@ -338,8 +338,7 @@ namespace YooAsset
|
|||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
|
||||
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -17,10 +17,6 @@ namespace YooAsset
|
|||
{
|
||||
YooLogger.Log("Begin to create catalog file !");
|
||||
|
||||
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
|
@ -87,10 +83,23 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>();
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
// 创建白名单查询集合
|
||||
HashSet<string> whiteFileList = new HashSet<string>
|
||||
{
|
||||
"link.xml",
|
||||
"buildlogtep.json",
|
||||
$"{packageName}.version",
|
||||
$"{packageName}_{packageVersion}.bytes",
|
||||
$"{packageName}_{packageVersion}.hash",
|
||||
$"{packageName}_{packageVersion}.json",
|
||||
$"{packageName}_{packageVersion}.report",
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogFileName
|
||||
};
|
||||
|
||||
// 记录所有内置资源文件
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
|
||||
FileInfo[] fileInfos = rootDirectory.GetFiles();
|
||||
|
@ -99,17 +108,7 @@ namespace YooAsset
|
|||
if (fileInfo.Extension == ".meta")
|
||||
continue;
|
||||
|
||||
if (fileInfo.Name == "link.xml" || fileInfo.Name == "buildlogtep.json")
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}.version")
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.bytes")
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.hash")
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.json")
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
|
||||
if (whiteFileList.Contains(fileInfo.Name))
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
|
@ -125,18 +124,13 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
// 创建输出目录
|
||||
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||
FileUtility.CreateFileDirectory(saveFilePath);
|
||||
|
||||
string saveFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||
if (File.Exists(saveFilePath))
|
||||
File.Delete(saveFilePath);
|
||||
|
||||
// 创建输出文件
|
||||
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
|
||||
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
|
||||
#if UNITY_2019
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#else
|
||||
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
|
||||
#endif
|
||||
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||
return true;
|
||||
|
|
|
@ -6,6 +6,6 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 内置清单文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.asset";
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.json";
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
|
@ -7,12 +8,15 @@ namespace YooAsset
|
|||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestData,
|
||||
LoadCatalog,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private string _textData = null;
|
||||
|
||||
|
||||
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
|
||||
|
@ -21,42 +25,78 @@ namespace YooAsset
|
|||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_steps = ESteps.RequestData;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestData)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_textData = _webTextRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
if (catalog == null)
|
||||
if (string.IsNullOrEmpty(_textData))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file : {catalogFilePath}";
|
||||
Error = $"Buildin catalog file content is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
try
|
||||
{
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(_textData);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
Error = $"Failed to load catalog file : {e.Message}";
|
||||
}
|
||||
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,8 +200,7 @@ namespace YooAsset
|
|||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
|
||||
return PathUtility.Combine(_webPackageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -11,17 +11,15 @@ namespace YooAsset
|
|||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestData,
|
||||
LoadCatalog,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 内置清单版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
private string _textData = null;
|
||||
|
||||
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
|
||||
{
|
||||
|
@ -29,43 +27,78 @@ namespace YooAsset
|
|||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_steps = ESteps.RequestData;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestData)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_textData = _webTextRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
if (catalog == null)
|
||||
if (string.IsNullOrEmpty(_textData))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load web server catalog file : {catalogFilePath}";
|
||||
Error = $"Buildin catalog file content is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
try
|
||||
{
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(_textData);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
Error = $"Failed to load catalog file : {e.Message}";
|
||||
}
|
||||
|
||||
PackageVersion = catalog.PackageVersion;
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,28 +106,6 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
#region 路径相关
|
||||
/// <summary>
|
||||
/// 获取YOO的Resources目录的加载路径
|
||||
/// </summary>
|
||||
internal static string GetYooResourcesLoadPath(string packageName, string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
|
||||
return PathUtility.Combine(packageName, fileName);
|
||||
else
|
||||
return PathUtility.Combine(Setting.DefaultYooFolderName, packageName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取YOO的Resources目录的全路径
|
||||
/// </summary>
|
||||
internal static string GetYooResourcesFullPath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
|
||||
return $"Assets/Resources";
|
||||
else
|
||||
return $"Assets/Resources/{Setting.DefaultYooFolderName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取YOO的编辑器下缓存文件根目录
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue