mirror of https://github.com/tuyoogame/YooAsset
Merge 0b4f6d6639
into 4d2df5b705
commit
e984d69c48
|
@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||||
{
|
{
|
||||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||||
|
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace YooAsset.Editor
|
||||||
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||||
{
|
{
|
||||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||||
|
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||||
{
|
{
|
||||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||||
|
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置资源清单目录
|
/// 内置资源清单目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DefaultBuildinFileCatalog : ScriptableObject
|
[Serializable]
|
||||||
|
internal class DefaultBuildinFileCatalog
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class FileWrapper
|
public class FileWrapper
|
||||||
|
|
|
@ -338,8 +338,8 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
public string GetCatalogFileLoadPath()
|
public string GetCatalogFileLoadPath()
|
||||||
{
|
{
|
||||||
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
string fileName = DefaultBuildinFileSystemDefine.BuildinCatalogFileName;
|
||||||
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
|
return PathUtility.Combine(YooAssetSettingsData.GetRequestYooDefaultBuildinRoot(), PackageName, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -5,22 +5,16 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
public class DefaultBuildinFileSystemBuild
|
||||||
{
|
{
|
||||||
public int callbackOrder { get { return 0; } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在构建应用程序前自动生成内置资源目录文件。
|
/// 输出包裹的内置资源目录文件
|
||||||
/// 原理:搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入文件,并存储在Resources目录下。
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
/// <exception cref="System.Exception"></exception>
|
||||||
|
public static void ExportBuildinCatalogFile()
|
||||||
{
|
{
|
||||||
YooLogger.Log("Begin to create catalog file !");
|
YooLogger.Log("Begin to create catalog file !");
|
||||||
|
|
||||||
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
|
|
||||||
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
|
|
||||||
UnityEditor.AssetDatabase.Refresh();
|
|
||||||
|
|
||||||
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||||
if (rootDirectory.Exists == false)
|
if (rootDirectory.Exists == false)
|
||||||
|
@ -87,7 +81,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建内置清单实例
|
// 创建内置清单实例
|
||||||
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>();
|
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||||
buildinFileCatalog.PackageName = packageName;
|
buildinFileCatalog.PackageName = packageName;
|
||||||
buildinFileCatalog.PackageVersion = packageVersion;
|
buildinFileCatalog.PackageVersion = packageVersion;
|
||||||
|
|
||||||
|
@ -111,6 +105,8 @@ namespace YooAsset
|
||||||
continue;
|
continue;
|
||||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
|
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
|
||||||
continue;
|
continue;
|
||||||
|
if (fileInfo.Name == DefaultBuildinFileSystemDefine.BuildinCatalogFileName)
|
||||||
|
continue;
|
||||||
|
|
||||||
string fileName = fileInfo.Name;
|
string fileName = fileInfo.Name;
|
||||||
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
|
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
|
||||||
|
@ -125,18 +121,13 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建输出目录
|
// 创建输出目录
|
||||||
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
|
string fullPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||||
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||||
FileUtility.CreateFileDirectory(saveFilePath);
|
FileUtility.CreateFileDirectory(saveFilePath);
|
||||||
|
|
||||||
// 创建输出文件
|
// 创建输出文件
|
||||||
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
|
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
|
||||||
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
|
UnityEditor.AssetDatabase.Refresh();
|
||||||
#if UNITY_2019
|
|
||||||
UnityEditor.AssetDatabase.SaveAssets();
|
|
||||||
#else
|
|
||||||
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6,6 +6,6 @@ namespace YooAsset
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置清单文件名称
|
/// 内置清单文件名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string BuildinCatalogFileName = "BuildinCatalog.asset";
|
public const string BuildinCatalogFileName = "BuildinCatalog.json";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
@ -8,9 +9,11 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadCatalog,
|
LoadCatalog,
|
||||||
|
WaitForRequest,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UnityWebRequest _request;
|
||||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
@ -28,12 +31,39 @@ namespace YooAsset
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||||
|
|
||||||
if (_steps == ESteps.LoadCatalog)
|
if (_steps == ESteps.LoadCatalog)
|
||||||
{
|
{
|
||||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
_request = UnityWebRequest.Get(catalogFilePath);
|
||||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
_request.SendWebRequest();
|
||||||
|
_steps = ESteps.WaitForRequest;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.WaitForRequest)
|
||||||
|
{
|
||||||
|
// 等待请求完成
|
||||||
|
if (!_request.isDone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Failed to load catalog file: {_request.error}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 JSON
|
||||||
|
string jsonText = _request.downloadHandler.text;
|
||||||
|
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||||
if (catalog == null)
|
if (catalog == null)
|
||||||
{
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed to load catalog file : {catalogFilePath}";
|
Error = $"Failed to load catalog file : {catalogFilePath}";
|
||||||
|
@ -42,6 +72,8 @@ namespace YooAsset
|
||||||
|
|
||||||
if (catalog.PackageName != _fileSystem.PackageName)
|
if (catalog.PackageName != _fileSystem.PackageName)
|
||||||
{
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||||
|
@ -55,6 +87,8 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
@ -12,9 +13,11 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadCatalog,
|
LoadCatalog,
|
||||||
|
WaitForRequest,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UnityWebRequest _request;
|
||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
@ -36,12 +39,39 @@ namespace YooAsset
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||||
|
|
||||||
if (_steps == ESteps.LoadCatalog)
|
if (_steps == ESteps.LoadCatalog)
|
||||||
{
|
{
|
||||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
_request = UnityWebRequest.Get(catalogFilePath);
|
||||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
_request.SendWebRequest();
|
||||||
|
_steps = ESteps.WaitForRequest;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.WaitForRequest)
|
||||||
|
{
|
||||||
|
// 等待请求完成
|
||||||
|
if (!_request.isDone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Failed to load web server catalog file: {_request.error}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 JSON
|
||||||
|
string jsonText = _request.downloadHandler.text;
|
||||||
|
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||||
if (catalog == null)
|
if (catalog == null)
|
||||||
{
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed to load web server catalog file : {catalogFilePath}";
|
Error = $"Failed to load web server catalog file : {catalogFilePath}";
|
||||||
|
@ -50,6 +80,8 @@ namespace YooAsset
|
||||||
|
|
||||||
if (catalog.PackageName != _fileSystem.PackageName)
|
if (catalog.PackageName != _fileSystem.PackageName)
|
||||||
{
|
{
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||||
|
@ -64,6 +96,8 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
||||||
|
_request.Dispose();
|
||||||
|
_request = null;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,6 +220,26 @@ namespace YooAsset
|
||||||
else
|
else
|
||||||
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
|
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string GetRequestYooDefaultBuildinRoot()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
|
||||||
|
return GetRequestStreamingAssetsPath();
|
||||||
|
else
|
||||||
|
return PathUtility.Combine(GetRequestStreamingAssetsPath(), Setting.DefaultYooFolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取UnityWebRequest StreamingAssets的路径 (OSX and iOS 需要加 file://)
|
||||||
|
/// </summary>
|
||||||
|
internal static string GetRequestStreamingAssetsPath()
|
||||||
|
{
|
||||||
|
#if UNITY_STANDALONE_OSX || UNITY_IOS
|
||||||
|
return $"file://{Application.streamingAssetsPath}";
|
||||||
|
#else
|
||||||
|
return Application.streamingAssetsPath;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue