Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b25f656372 | ||
|
|
cc1c8d6414 | ||
|
|
99a3abf697 | ||
|
|
023dc82f8e | ||
|
|
09a985fadb | ||
|
|
eb6b6e3aba | ||
|
|
89bde69417 | ||
|
|
6bb3c17f82 | ||
|
|
8be6d54f22 | ||
|
|
ea28d3e6e1 | ||
|
|
9fbce6a726 | ||
|
|
46467171ba | ||
|
|
d2d6d2ad14 | ||
|
|
f38d663e9d | ||
|
|
11e03c7a13 | ||
|
|
f466a02fd7 | ||
|
|
3bb4d5082b |
@@ -2,6 +2,26 @@
|
|||||||
|
|
||||||
All notable changes to this package will be documented in this file.
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [1.0.3] - 2022-04-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了AssetBundleDebugger窗口的BundleView视口下,Using列表显示不完整的问题。
|
||||||
|
- 修复了AssetBundleDebugger窗口的BundleView视口下,Bundle列表内元素重复的问题。
|
||||||
|
- 修复了特殊情况下依赖的资源包列表里包含主资源包的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 实例化GameObject的时候,如果没有传递坐标和角度则使用默认值。
|
||||||
|
- 优化了资源分组配置保存策略,修改为窗口关闭时保存。
|
||||||
|
- 简化了资源版本概念,降低学习成本,统一了CDN上的目录结构。
|
||||||
|
- 资源定位接口扩展,方便开发可寻址资产定位功能。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 离线运行模式支持WEBGL平台。
|
||||||
|
- 保留构建窗口界面的配置数据。
|
||||||
|
|
||||||
## [1.0.2] - 2022-04-07
|
## [1.0.2] - 2022-04-07
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -11,7 +31,7 @@ All notable changes to this package will be documented in this file.
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- StreamingAssets目录下增加了用于存放打包资源的总文件夹
|
- StreamingAssets目录下增加了用于存放打包资源的总文件夹。
|
||||||
|
|
||||||
## [1.0.1] - 2022-04-07
|
## [1.0.1] - 2022-04-07
|
||||||
|
|
||||||
|
|||||||
@@ -117,11 +117,11 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从输出目录加载补丁清单文件
|
/// 加载补丁清单文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static PatchManifest LoadPatchManifestFile(string fileDirectory)
|
internal static PatchManifest LoadPatchManifestFile(string fileDirectory, int resourceVersion)
|
||||||
{
|
{
|
||||||
string filePath = $"{fileDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
if (File.Exists(filePath) == false)
|
if (File.Exists(filePath) == false)
|
||||||
{
|
{
|
||||||
throw new System.Exception($"Not found patch manifest file : {filePath}");
|
throw new System.Exception($"Not found patch manifest file : {filePath}");
|
||||||
@@ -130,5 +130,16 @@ namespace YooAsset.Editor
|
|||||||
string jsonData = FileUtility.ReadFile(filePath);
|
string jsonData = FileUtility.ReadFile(filePath);
|
||||||
return PatchManifest.Deserialize(jsonData);
|
return PatchManifest.Deserialize(jsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取旧的补丁清单
|
||||||
|
/// </summary>
|
||||||
|
internal static PatchManifest GetOldPatchManifest(string pipelineOutputDirectory)
|
||||||
|
{
|
||||||
|
string staticVersionFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string staticVersionContent = FileUtility.ReadFile(staticVersionFilePath);
|
||||||
|
int staticVersion = int.Parse(staticVersionContent);
|
||||||
|
return LoadPatchManifestFile(pipelineOutputDirectory, staticVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleBuilderSetting : ScriptableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构建版本号
|
||||||
|
/// </summary>
|
||||||
|
public int BuildVersion = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压缩方式
|
||||||
|
/// </summary>
|
||||||
|
public ECompressOption CompressOption = ECompressOption.LZ4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密类名称
|
||||||
|
/// </summary>
|
||||||
|
public string EncyptionClassName = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 附加后缀格式
|
||||||
|
/// </summary>
|
||||||
|
public bool AppendExtension = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 强制构建
|
||||||
|
/// </summary>
|
||||||
|
public bool ForceRebuild = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置标签
|
||||||
|
/// </summary>
|
||||||
|
public string BuildTags = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 09788b4733bab2d4792fdd5d28e7653c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleBuilderSettingData
|
||||||
|
{
|
||||||
|
private static AssetBundleBuilderSetting _setting = null;
|
||||||
|
public static AssetBundleBuilderSetting Setting
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
return _setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载配置文件
|
||||||
|
/// </summary>
|
||||||
|
private static void LoadSettingData()
|
||||||
|
{
|
||||||
|
// 加载配置文件
|
||||||
|
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||||
|
if (_setting == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {EditorDefine.AssetBundleBuilderSettingFilePath}");
|
||||||
|
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
|
||||||
|
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||||
|
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储文件
|
||||||
|
/// </summary>
|
||||||
|
public static void SaveFile()
|
||||||
|
{
|
||||||
|
if (Setting != null)
|
||||||
|
{
|
||||||
|
EditorUtility.SetDirty(Setting);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 24698266f028e4a47bb88f091fd64547
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -61,23 +61,43 @@ namespace YooAsset.Editor
|
|||||||
_buildOutputTxt.SetEnabled(false);
|
_buildOutputTxt.SetEnabled(false);
|
||||||
|
|
||||||
// 构建版本
|
// 构建版本
|
||||||
var appVersion = new Version(Application.version);
|
|
||||||
_buildVersionField = root.Q<IntegerField>("BuildVersion");
|
_buildVersionField = root.Q<IntegerField>("BuildVersion");
|
||||||
_buildVersionField.SetValueWithoutNotify(appVersion.Revision);
|
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
|
||||||
|
_buildVersionField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 压缩方式
|
// 压缩方式
|
||||||
_compressionField = root.Q<EnumField>("Compression");
|
_compressionField = root.Q<EnumField>("Compression");
|
||||||
_compressionField.Init(ECompressOption.LZ4);
|
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
_compressionField.SetValueWithoutNotify(ECompressOption.LZ4);
|
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
_compressionField.style.width = 300;
|
_compressionField.style.width = 300;
|
||||||
|
_compressionField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 加密方法
|
// 加密方法
|
||||||
var encryptionContainer = root.Q("EncryptionContainer");
|
var encryptionContainer = root.Q("EncryptionContainer");
|
||||||
if (_encryptionServicesClassNames.Count > 0)
|
if (_encryptionServicesClassNames.Count > 0)
|
||||||
{
|
{
|
||||||
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, 0);
|
int defaultIndex = 0;
|
||||||
|
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
|
||||||
|
{
|
||||||
|
if (_encryptionServicesClassNames[index] == AssetBundleBuilderSettingData.Setting.EncyptionClassName)
|
||||||
|
{
|
||||||
|
defaultIndex = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
|
||||||
_encryptionField.label = "Encryption";
|
_encryptionField.label = "Encryption";
|
||||||
_encryptionField.style.width = 300;
|
_encryptionField.style.width = 300;
|
||||||
|
_encryptionField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
|
||||||
|
});
|
||||||
encryptionContainer.Add(_encryptionField);
|
encryptionContainer.Add(_encryptionField);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -90,18 +110,29 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 附加后缀格式
|
// 附加后缀格式
|
||||||
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
|
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
|
||||||
|
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
|
||||||
|
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 强制构建
|
// 强制构建
|
||||||
_forceRebuildToggle = root.Q<Toggle>("ForceRebuild");
|
_forceRebuildToggle = root.Q<Toggle>("ForceRebuild");
|
||||||
_forceRebuildToggle.SetValueWithoutNotify(true);
|
_forceRebuildToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.ForceRebuild);
|
||||||
_forceRebuildToggle.RegisterValueChangedCallback(evt =>
|
_forceRebuildToggle.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.ForceRebuild = _forceRebuildToggle.value;
|
||||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 内置标签
|
// 内置标签
|
||||||
_buildTagsTxt = root.Q<TextField>("BuildinTags");
|
_buildTagsTxt = root.Q<TextField>("BuildinTags");
|
||||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
||||||
|
_buildTagsTxt.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||||
|
_buildTagsTxt.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsTxt.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 构建按钮
|
// 构建按钮
|
||||||
var buildButton = root.Q<Button>("Build");
|
var buildButton = root.Q<Button>("Build");
|
||||||
@@ -112,6 +143,10 @@ namespace YooAsset.Editor
|
|||||||
Debug.LogError(e.ToString());
|
Debug.LogError(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void OnDestroy()
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
private void BuildButton_clicked()
|
private void BuildButton_clicked()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long SizeBytes;
|
public long SizeBytes;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件版本
|
|
||||||
/// </summary>
|
|
||||||
public int Version;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tags
|
/// Tags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -15,21 +15,20 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
// 注意:我们只有在强制重建的时候才会拷贝
|
// 注意:我们只有在强制重建的时候才会拷贝
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
if(buildParameters.Parameters.ForceRebuild)
|
if (buildParameters.Parameters.ForceRebuild)
|
||||||
{
|
{
|
||||||
// 清空流目录
|
// 清空流目录
|
||||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||||
|
|
||||||
// 拷贝内置文件
|
// 拷贝内置文件
|
||||||
var pipelineOutputDirectory = buildParameters.PipelineOutputDirectory;
|
CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
CopyBuildinFilesToStreaming(pipelineOutputDirectory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory)
|
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion)
|
||||||
{
|
{
|
||||||
// 加载补丁清单
|
// 加载补丁清单
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion);
|
||||||
|
|
||||||
// 拷贝文件列表
|
// 拷贝文件列表
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
@@ -45,15 +44,22 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 拷贝清单文件
|
// 拷贝清单文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝清单哈希文件
|
// 拷贝清单哈希文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝静态版本文件
|
||||||
|
{
|
||||||
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ namespace YooAsset.Editor
|
|||||||
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
|
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
|
||||||
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
||||||
{
|
{
|
||||||
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
|
|
||||||
// 创建新补丁清单
|
// 创建新补丁清单
|
||||||
PatchManifest patchManifest = new PatchManifest();
|
PatchManifest patchManifest = new PatchManifest();
|
||||||
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
|
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
@@ -32,15 +34,21 @@ namespace YooAsset.Editor
|
|||||||
patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
|
patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
|
||||||
|
|
||||||
// 创建补丁清单文件
|
// 创建补丁清单文件
|
||||||
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
UnityEngine.Debug.Log($"创建补丁清单文件:{manifestFilePath}");
|
UnityEngine.Debug.Log($"创建补丁清单文件:{manifestFilePath}");
|
||||||
PatchManifest.Serialize(manifestFilePath, patchManifest);
|
PatchManifest.Serialize(manifestFilePath, patchManifest);
|
||||||
|
|
||||||
// 创建补丁清单哈希文件
|
// 创建补丁清单哈希文件
|
||||||
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
string manifestHash = HashUtility.FileMD5(manifestFilePath);
|
string manifestHash = HashUtility.FileMD5(manifestFilePath);
|
||||||
UnityEngine.Debug.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
UnityEngine.Debug.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
||||||
FileUtility.CreateFile(manifestHashFilePath, manifestHash);
|
FileUtility.CreateFile(manifestHashFilePath, manifestHash);
|
||||||
|
|
||||||
|
// 创建静态版本文件
|
||||||
|
string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string staticVersion = resourceVersion.ToString();
|
||||||
|
UnityEngine.Debug.Log($"创建静态版本文件:{staticVersionFilePath}");
|
||||||
|
FileUtility.CreateFile(staticVersionFilePath, staticVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,19 +62,12 @@ namespace YooAsset.Editor
|
|||||||
// 内置标记列表
|
// 内置标记列表
|
||||||
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
||||||
|
|
||||||
// 加载旧补丁清单
|
|
||||||
PatchManifest oldPatchManifest = null;
|
|
||||||
if (buildParameters.Parameters.ForceRebuild == false)
|
|
||||||
{
|
|
||||||
oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
var bundleName = bundleInfo.BundleName;
|
var bundleName = bundleInfo.BundleName;
|
||||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||||
string hash = HashUtility.FileMD5(filePath);
|
string hash = HashUtility.FileMD5(filePath);
|
||||||
string crc = HashUtility.FileCRC32(filePath);
|
string crc32 = HashUtility.FileCRC32(filePath);
|
||||||
long size = FileUtility.GetFileSize(filePath);
|
long size = FileUtility.GetFileSize(filePath);
|
||||||
int version = buildParameters.Parameters.BuildVersion;
|
int version = buildParameters.Parameters.BuildVersion;
|
||||||
string[] tags = buildMapContext.GetAssetTags(bundleName);
|
string[] tags = buildMapContext.GetAssetTags(bundleName);
|
||||||
@@ -80,14 +81,7 @@ namespace YooAsset.Editor
|
|||||||
hash += bundleInfo.GetAppendExtension();
|
hash += bundleInfo.GetAppendExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:如果文件没有变化使用旧版本号
|
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags);
|
||||||
if (oldPatchManifest != null && oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle value))
|
|
||||||
{
|
|
||||||
if (value.Hash == hash)
|
|
||||||
version = value.Version;
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc, size, version, tags);
|
|
||||||
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
|
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
|
||||||
result.Add(patchBundle);
|
result.Add(patchBundle);
|
||||||
}
|
}
|
||||||
@@ -122,13 +116,13 @@ namespace YooAsset.Editor
|
|||||||
PatchAsset patchAsset = new PatchAsset();
|
PatchAsset patchAsset = new PatchAsset();
|
||||||
patchAsset.AssetPath = assetInfo.AssetPath;
|
patchAsset.AssetPath = assetInfo.AssetPath;
|
||||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
|
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
|
||||||
patchAsset.DependIDs = GetAssetBundleDependIDs(assetInfo, patchManifest);
|
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
||||||
result.Add(patchAsset);
|
result.Add(patchAsset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private int[] GetAssetBundleDependIDs(BuildAssetInfo assetInfo, PatchManifest patchManifest)
|
private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
List<int> result = new List<int>();
|
List<int> result = new List<int>();
|
||||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||||
@@ -136,8 +130,11 @@ namespace YooAsset.Editor
|
|||||||
if (dependAssetInfo.BundleNameIsValid() == false)
|
if (dependAssetInfo.BundleNameIsValid() == false)
|
||||||
continue;
|
continue;
|
||||||
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, patchManifest);
|
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, patchManifest);
|
||||||
if (result.Contains(bundleID) == false)
|
if (mainBundleID != bundleID)
|
||||||
result.Add(bundleID);
|
{
|
||||||
|
if (result.Contains(bundleID) == false)
|
||||||
|
result.Add(bundleID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,31 +19,40 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
|
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
|
||||||
{
|
{
|
||||||
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
string packageDirectory = buildParameters.GetPackageDirectory();
|
string packageDirectory = buildParameters.GetPackageDirectory();
|
||||||
UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
UnityEngine.Debug.Log($"准备开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
||||||
|
|
||||||
// 拷贝Report文件
|
// 拷贝Report文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝Report文件到:{destPath}");
|
UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝PatchManifest文件
|
// 拷贝补丁清单文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝PatchManifest文件到:{destPath}");
|
UnityEngine.Debug.Log($"拷贝补丁清单文件到:{destPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝PatchManifest哈希文件
|
// 拷贝补丁清单哈希文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝PatchManifest哈希文件到:{destPath}");
|
UnityEngine.Debug.Log($"拷贝补丁清单哈希文件到:{destPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝静态版本文件
|
||||||
|
{
|
||||||
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
UnityEngine.Debug.Log($"拷贝静态版本文件到:{destPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝UnityManifest序列化文件
|
// 拷贝UnityManifest序列化文件
|
||||||
@@ -62,20 +71,16 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝所有补丁文件
|
// 拷贝所有补丁文件
|
||||||
// 注意:拷贝的补丁文件都是需要玩家热更新的文件
|
|
||||||
int progressValue = 0;
|
int progressValue = 0;
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
int patchFileTotalCount = patchManifest.BundleList.Count;
|
int patchFileTotalCount = patchManifest.BundleList.Count;
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
if (patchBundle.Version == buildParameters.Parameters.BuildVersion)
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||||
{
|
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
|
UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}");
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
||||||
UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}");
|
|
||||||
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EditorTools.ClearProgressBar();
|
EditorTools.ClearProgressBar();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
||||||
{
|
{
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
BuildReport buildReport = new BuildReport();
|
BuildReport buildReport = new BuildReport();
|
||||||
buildParameters.StopWatch();
|
buildParameters.StopWatch();
|
||||||
|
|
||||||
@@ -79,7 +79,6 @@ namespace YooAsset.Editor
|
|||||||
reportBundleInfo.Hash = patchBundle.Hash;
|
reportBundleInfo.Hash = patchBundle.Hash;
|
||||||
reportBundleInfo.CRC = patchBundle.CRC;
|
reportBundleInfo.CRC = patchBundle.CRC;
|
||||||
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
|
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
|
||||||
reportBundleInfo.Version = patchBundle.Version;
|
|
||||||
reportBundleInfo.Tags = patchBundle.Tags;
|
reportBundleInfo.Tags = patchBundle.Tags;
|
||||||
reportBundleInfo.Flags = patchBundle.Flags;
|
reportBundleInfo.Flags = patchBundle.Flags;
|
||||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace YooAsset.Editor
|
|||||||
throw new Exception($"补丁包已经存在:{packageDirectory}");
|
throw new Exception($"补丁包已经存在:{packageDirectory}");
|
||||||
|
|
||||||
// 检测内置资源分类标签是否一致
|
// 检测内置资源分类标签是否一致
|
||||||
PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory);
|
||||||
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
|
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
|
||||||
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
|
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,16 +178,6 @@ namespace YooAsset.Editor
|
|||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
var label = new Label();
|
|
||||||
label.name = "Label2";
|
|
||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
label.style.marginLeft = 3f;
|
|
||||||
//label.style.flexGrow = 1f;
|
|
||||||
label.style.width = 100;
|
|
||||||
element.Add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
var label = new Label();
|
var label = new Label();
|
||||||
label.name = "Label3";
|
label.name = "Label3";
|
||||||
@@ -219,10 +209,6 @@ namespace YooAsset.Editor
|
|||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = bundleInfo.BundleName;
|
label1.text = bundleInfo.BundleName;
|
||||||
|
|
||||||
// Version
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Ref Count
|
// Ref Count
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.RefCount.ToString();
|
label3.text = bundleInfo.RefCount.ToString();
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
|
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
|
||||||
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||||
<uie:ToolbarButton text="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
<uie:ToolbarButton text="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
|
||||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
|
|||||||
private TemplateContainer _root;
|
private TemplateContainer _root;
|
||||||
|
|
||||||
private ListView _bundleListView;
|
private ListView _bundleListView;
|
||||||
private ListView _includeListView;
|
private ListView _usingListView;
|
||||||
private DebugReport _debugReport;
|
private DebugReport _debugReport;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -35,7 +35,7 @@ namespace YooAsset.Editor
|
|||||||
_root = _visualAsset.CloneTree();
|
_root = _visualAsset.CloneTree();
|
||||||
_root.style.flexGrow = 1f;
|
_root.style.flexGrow = 1f;
|
||||||
|
|
||||||
// 资源列表
|
// 资源包列表
|
||||||
_bundleListView = _root.Q<ListView>("TopListView");
|
_bundleListView = _root.Q<ListView>("TopListView");
|
||||||
_bundleListView.makeItem = MakeAssetListViewItem;
|
_bundleListView.makeItem = MakeAssetListViewItem;
|
||||||
_bundleListView.bindItem = BindAssetListViewItem;
|
_bundleListView.bindItem = BindAssetListViewItem;
|
||||||
@@ -45,10 +45,10 @@ namespace YooAsset.Editor
|
|||||||
#else
|
#else
|
||||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||||
#endif
|
#endif
|
||||||
// 依赖列表
|
// 使用列表
|
||||||
_includeListView = _root.Q<ListView>("BottomListView");
|
_usingListView = _root.Q<ListView>("BottomListView");
|
||||||
_includeListView.makeItem = MakeIncludeListViewItem;
|
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||||
_includeListView.bindItem = BindIncludeListViewItem;
|
_usingListView.bindItem = BindIncludeListViewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -62,7 +62,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||||
{
|
{
|
||||||
var result = new List<DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
Dictionary<string, DebugBundleInfo> result = new Dictionary<string, DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
||||||
foreach (var providerInfo in debugReport.ProviderInfos)
|
foreach (var providerInfo in debugReport.ProviderInfos)
|
||||||
{
|
{
|
||||||
foreach(var bundleInfo in providerInfo.BundleInfos)
|
foreach(var bundleInfo in providerInfo.BundleInfos)
|
||||||
@@ -72,10 +72,11 @@ namespace YooAsset.Editor
|
|||||||
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.Add(bundleInfo);
|
if(result.ContainsKey(bundleInfo.BundleName) == false)
|
||||||
|
result.Add(bundleInfo.BundleName, bundleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result.Values.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -111,16 +112,6 @@ namespace YooAsset.Editor
|
|||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
var label = new Label();
|
|
||||||
label.name = "Label2";
|
|
||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
label.style.marginLeft = 3f;
|
|
||||||
//label.style.flexGrow = 1f;
|
|
||||||
label.style.width = 100;
|
|
||||||
element.Add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
var label = new Label();
|
var label = new Label();
|
||||||
label.name = "Label3";
|
label.name = "Label3";
|
||||||
@@ -152,17 +143,13 @@ namespace YooAsset.Editor
|
|||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = bundleInfo.BundleName;
|
label1.text = bundleInfo.BundleName;
|
||||||
|
|
||||||
// Version
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Ref Count
|
// Ref Count
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.RefCount.ToString();
|
label3.text = bundleInfo.RefCount.ToString();
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
StyleColor textColor;
|
StyleColor textColor;
|
||||||
if (bundleInfo.Status == AssetBundleLoader.EStatus.Fail)
|
if (bundleInfo.Status == AssetBundleLoaderBase.EStatus.Failed)
|
||||||
textColor = new StyleColor(Color.yellow);
|
textColor = new StyleColor(Color.yellow);
|
||||||
else
|
else
|
||||||
textColor = label1.style.color;
|
textColor = label1.style.color;
|
||||||
@@ -175,7 +162,7 @@ namespace YooAsset.Editor
|
|||||||
foreach (var item in objs)
|
foreach (var item in objs)
|
||||||
{
|
{
|
||||||
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
||||||
FillIncludeListView(bundleInfo);
|
FillUsingListView(bundleInfo.BundleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +206,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
private void BindIncludeListViewItem(VisualElement element, int index)
|
private void BindIncludeListViewItem(VisualElement element, int index)
|
||||||
{
|
{
|
||||||
List<DebugProviderInfo> providers = _includeListView.itemsSource as List<DebugProviderInfo>;
|
List<DebugProviderInfo> providers = _usingListView.itemsSource as List<DebugProviderInfo>;
|
||||||
DebugProviderInfo providerInfo = providers[index];
|
DebugProviderInfo providerInfo = providers[index];
|
||||||
|
|
||||||
// Asset Path
|
// Asset Path
|
||||||
@@ -234,18 +221,24 @@ namespace YooAsset.Editor
|
|||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = providerInfo.Status.ToString();
|
label3.text = providerInfo.Status.ToString();
|
||||||
}
|
}
|
||||||
private void FillIncludeListView(DebugBundleInfo bundleInfo)
|
private void FillUsingListView(string bundleName)
|
||||||
{
|
{
|
||||||
_includeListView.Clear();
|
_usingListView.Clear();
|
||||||
_includeListView.ClearSelection();
|
_usingListView.ClearSelection();
|
||||||
|
|
||||||
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
||||||
foreach(var providerInfo in _debugReport.ProviderInfos)
|
foreach(var providerInfo in _debugReport.ProviderInfos)
|
||||||
{
|
{
|
||||||
if (providerInfo.BundleInfos.Contains(bundleInfo))
|
foreach(var bundleInfo in providerInfo.BundleInfos)
|
||||||
source.Add(providerInfo);
|
{
|
||||||
|
if (bundleInfo.BundleName == bundleName)
|
||||||
|
{
|
||||||
|
source.Add(providerInfo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_includeListView.itemsSource = source;
|
_usingListView.itemsSource = source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
|
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
|
||||||
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||||
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
|
||||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ namespace YooAsset.Editor
|
|||||||
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
||||||
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 配置数据是否被修改
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsDirty { private set; get; } = false;
|
||||||
|
|
||||||
|
|
||||||
private static AssetBundleGrouperSetting _setting = null;
|
private static AssetBundleGrouperSetting _setting = null;
|
||||||
public static AssetBundleGrouperSetting Setting
|
public static AssetBundleGrouperSetting Setting
|
||||||
@@ -147,8 +152,10 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (Setting != null)
|
if (Setting != null)
|
||||||
{
|
{
|
||||||
|
IsDirty = false;
|
||||||
EditorUtility.SetDirty(Setting);
|
EditorUtility.SetDirty(Setting);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
Debug.Log($"{nameof(AssetBundleGrouperSetting)}.asset is saved!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,42 +209,42 @@ namespace YooAsset.Editor
|
|||||||
// 着色器编辑相关
|
// 着色器编辑相关
|
||||||
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
|
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(shadersBundleName))
|
|
||||||
return;
|
|
||||||
Setting.AutoCollectShaders = isCollectAllShaders;
|
Setting.AutoCollectShaders = isCollectAllShaders;
|
||||||
Setting.ShadersBundleName = shadersBundleName;
|
Setting.ShadersBundleName = shadersBundleName;
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 资源分组编辑相关
|
// 资源分组编辑相关
|
||||||
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags, bool saveFile = true)
|
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags)
|
||||||
{
|
{
|
||||||
AssetBundleGrouper grouper = new AssetBundleGrouper();
|
AssetBundleGrouper grouper = new AssetBundleGrouper();
|
||||||
grouper.GrouperName = grouperName;
|
grouper.GrouperName = grouperName;
|
||||||
grouper.GrouperDesc = grouperDesc;
|
grouper.GrouperDesc = grouperDesc;
|
||||||
grouper.AssetTags = assetTags;
|
grouper.AssetTags = assetTags;
|
||||||
Setting.Groupers.Add(grouper);
|
Setting.Groupers.Add(grouper);
|
||||||
|
IsDirty = true;
|
||||||
if (saveFile)
|
|
||||||
SaveFile();
|
|
||||||
}
|
}
|
||||||
public static void RemoveGrouper(AssetBundleGrouper grouper)
|
public static void RemoveGrouper(AssetBundleGrouper grouper)
|
||||||
{
|
{
|
||||||
if (Setting.Groupers.Remove(grouper))
|
if (Setting.Groupers.Remove(grouper))
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed remove grouper : {grouper.GrouperName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ModifyGrouper(AssetBundleGrouper grouper)
|
public static void ModifyGrouper(AssetBundleGrouper grouper)
|
||||||
{
|
{
|
||||||
if (grouper != null)
|
if (grouper != null)
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 资源收集器编辑相关
|
// 资源收集器编辑相关
|
||||||
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList, bool saveFile = true)
|
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList)
|
||||||
{
|
{
|
||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
AssetBundleCollector collector = new AssetBundleCollector();
|
||||||
collector.CollectPath = collectPath;
|
collector.CollectPath = collectPath;
|
||||||
@@ -245,22 +252,24 @@ namespace YooAsset.Editor
|
|||||||
collector.FilterRuleName = filterRuleName;
|
collector.FilterRuleName = filterRuleName;
|
||||||
collector.NotWriteToAssetList = notWriteToAssetList;
|
collector.NotWriteToAssetList = notWriteToAssetList;
|
||||||
grouper.Collectors.Add(collector);
|
grouper.Collectors.Add(collector);
|
||||||
|
IsDirty = true;
|
||||||
if (saveFile)
|
|
||||||
SaveFile();
|
|
||||||
}
|
}
|
||||||
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
||||||
{
|
{
|
||||||
if (grouper.Collectors.Remove(collector))
|
if (grouper.Collectors.Remove(collector))
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
||||||
{
|
{
|
||||||
if (grouper != null && collector != null)
|
if (grouper != null && collector != null)
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,11 @@ namespace YooAsset.Editor
|
|||||||
Debug.LogError(e.ToString());
|
Debug.LogError(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void OnDestroy()
|
||||||
|
{
|
||||||
|
if (AssetBundleGrouperSettingData.IsDirty)
|
||||||
|
AssetBundleGrouperSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
// 刷新窗体
|
// 刷新窗体
|
||||||
private void RefreshWindow()
|
private void RefreshWindow()
|
||||||
@@ -222,7 +227,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
private void AddGrouperBtn_clicked()
|
private void AddGrouperBtn_clicked()
|
||||||
{
|
{
|
||||||
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty, true);
|
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty);
|
||||||
FillGrouperViewData();
|
FillGrouperViewData();
|
||||||
}
|
}
|
||||||
private void RemoveGrouperBtn_clicked()
|
private void RemoveGrouperBtn_clicked()
|
||||||
|
|||||||
@@ -149,16 +149,6 @@ namespace YooAsset.Editor
|
|||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
var label = new Label();
|
|
||||||
label.name = "Label4";
|
|
||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
label.style.marginLeft = 3f;
|
|
||||||
//label.style.flexGrow = 1f;
|
|
||||||
label.style.width = 60;
|
|
||||||
element.Add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
var label = new Label();
|
var label = new Label();
|
||||||
label.name = "Label5";
|
label.name = "Label5";
|
||||||
@@ -188,10 +178,6 @@ namespace YooAsset.Editor
|
|||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.Hash;
|
label3.text = bundleInfo.Hash;
|
||||||
|
|
||||||
// Version
|
|
||||||
var label4 = element.Q<Label>("Label4");
|
|
||||||
label4.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
var label5 = element.Q<Label>("Label5");
|
var label5 = element.Q<Label>("Label5");
|
||||||
label5.text = GetTagsString(bundleInfo.Tags);
|
label5.text = GetTagsString(bundleInfo.Tags);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||||
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 250px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 250px; -unity-text-align: middle-left;" />
|
||||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="TopBar4" style="width: 60px; -unity-text-align: middle-left;" />
|
|
||||||
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ namespace YooAsset.Editor
|
|||||||
public class EditorDefine
|
public class EditorDefine
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包收集工具的配置文件存储路径
|
/// 资源包构建工具的配置文件存储路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string AssetBundleCollectorSettingFilePath = "Assets/YooAssetSetting/AssetBundleCollectorSetting.asset";
|
public const string AssetBundleBuilderSettingFilePath = "Assets/YooAssetSetting/AssetBundleBuilderSetting.asset";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包分组工具的配置文件存储路径
|
/// 资源包分组工具的配置文件存储路径
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal static class AssetSystem
|
internal static class AssetSystem
|
||||||
{
|
{
|
||||||
private static readonly List<AssetBundleLoader> _loaders = new List<AssetBundleLoader>(1000);
|
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
|
||||||
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -90,12 +90,12 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
AssetBundleLoader loader = _loaders[i];
|
AssetBundleLoaderBase loader = _loaders[i];
|
||||||
loader.TryDestroyAllProviders();
|
loader.TryDestroyAllProviders();
|
||||||
}
|
}
|
||||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
AssetBundleLoader loader = _loaders[i];
|
AssetBundleLoaderBase loader = _loaders[i];
|
||||||
if (loader.CanDestroy())
|
if (loader.CanDestroy())
|
||||||
{
|
{
|
||||||
loader.Destroy(false);
|
loader.Destroy(false);
|
||||||
@@ -191,22 +191,22 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static AssetBundleLoader CreateOwnerAssetBundleLoader(string assetPath)
|
internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(string assetPath)
|
||||||
{
|
{
|
||||||
string bundleName = BundleServices.GetBundleName(assetPath);
|
string bundleName = BundleServices.GetBundleName(assetPath);
|
||||||
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
|
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
|
||||||
return CreateAssetBundleLoaderInternal(bundleInfo);
|
return CreateAssetBundleLoaderInternal(bundleInfo);
|
||||||
}
|
}
|
||||||
internal static List<AssetBundleLoader> CreateDependAssetBundleLoaders(string assetPath)
|
internal static List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(string assetPath)
|
||||||
{
|
{
|
||||||
List<AssetBundleLoader> result = new List<AssetBundleLoader>();
|
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>();
|
||||||
string[] depends = BundleServices.GetAllDependencies(assetPath);
|
string[] depends = BundleServices.GetAllDependencies(assetPath);
|
||||||
if (depends != null)
|
if (depends != null)
|
||||||
{
|
{
|
||||||
foreach (var dependBundleName in depends)
|
foreach (var dependBundleName in depends)
|
||||||
{
|
{
|
||||||
BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName);
|
BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName);
|
||||||
AssetBundleLoader dependLoader = CreateAssetBundleLoaderInternal(dependBundleInfo);
|
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(dependBundleInfo);
|
||||||
result.Add(dependLoader);
|
result.Add(dependLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,24 +220,29 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AssetBundleLoader CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
private static AssetBundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
||||||
{
|
{
|
||||||
// 如果加载器已经存在
|
// 如果加载器已经存在
|
||||||
AssetBundleLoader loader = TryGetAssetBundleLoader(bundleInfo.BundleName);
|
AssetBundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.BundleName);
|
||||||
if (loader != null)
|
if (loader != null)
|
||||||
return loader;
|
return loader;
|
||||||
|
|
||||||
// 新增下载需求
|
// 新增下载需求
|
||||||
loader = new AssetBundleLoader(bundleInfo);
|
#if UNITY_WEBGL
|
||||||
|
loader = new AssetBundleWebLoader(bundleInfo);
|
||||||
|
#else
|
||||||
|
loader = new AssetBundleFileLoader(bundleInfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
_loaders.Add(loader);
|
_loaders.Add(loader);
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
private static AssetBundleLoader TryGetAssetBundleLoader(string bundleName)
|
private static AssetBundleLoaderBase TryGetAssetBundleLoader(string bundleName)
|
||||||
{
|
{
|
||||||
AssetBundleLoader loader = null;
|
AssetBundleLoaderBase loader = null;
|
||||||
for (int i = 0; i < _loaders.Count; i++)
|
for (int i = 0; i < _loaders.Count; i++)
|
||||||
{
|
{
|
||||||
AssetBundleLoader temp = _loaders[i];
|
AssetBundleLoaderBase temp = _loaders[i];
|
||||||
if (temp.BundleFileInfo.BundleName.Equals(bundleName))
|
if (temp.BundleFileInfo.BundleName.Equals(bundleName))
|
||||||
{
|
{
|
||||||
loader = temp;
|
loader = temp;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace YooAsset
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public GameObject InstantiateSync(Transform parent = null)
|
public GameObject InstantiateSync(Transform parent = null)
|
||||||
{
|
{
|
||||||
return InstantiateSync(Vector3.zero, Quaternion.identity, parent);
|
return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -86,15 +86,7 @@ namespace YooAsset
|
|||||||
/// <param name="parent">父类对象</param>
|
/// <param name="parent">父类对象</param>
|
||||||
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
|
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
|
||||||
{
|
{
|
||||||
if (IsValid == false)
|
return InstantiateSyncInternal(position, rotation, parent, true);
|
||||||
return null;
|
|
||||||
if (_provider.AssetObject == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (parent == null)
|
|
||||||
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation);
|
|
||||||
else
|
|
||||||
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -103,7 +95,7 @@ namespace YooAsset
|
|||||||
/// <param name="parent">父类对象</param>
|
/// <param name="parent">父类对象</param>
|
||||||
public InstantiateOperation InstantiateAsync(Transform parent = null)
|
public InstantiateOperation InstantiateAsync(Transform parent = null)
|
||||||
{
|
{
|
||||||
return InstantiateAsync(Vector3.zero, Quaternion.identity, parent);
|
return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -114,7 +106,35 @@ namespace YooAsset
|
|||||||
/// <param name="parent">父类对象</param>
|
/// <param name="parent">父类对象</param>
|
||||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
|
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
|
||||||
{
|
{
|
||||||
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent);
|
return InstantiateAsyncInternal(position, rotation, parent, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||||
|
{
|
||||||
|
if (IsValid == false)
|
||||||
|
return null;
|
||||||
|
if (_provider.AssetObject == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (setPositionRotation)
|
||||||
|
{
|
||||||
|
if (parent == null)
|
||||||
|
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation);
|
||||||
|
else
|
||||||
|
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation, parent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (parent == null)
|
||||||
|
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject);
|
||||||
|
else
|
||||||
|
return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||||
|
{
|
||||||
|
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
|
||||||
OperationSystem.ProcessOperaiton(operation);
|
OperationSystem.ProcessOperaiton(operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal sealed class AssetBundleFileLoader : AssetBundleLoaderBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Download,
|
||||||
|
CheckDownload,
|
||||||
|
LoadFile,
|
||||||
|
CheckFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
private bool _isWaitForAsyncComplete = false;
|
||||||
|
private bool _isShowWaitForAsyncError = false;
|
||||||
|
private DownloaderBase _downloader;
|
||||||
|
private AssetBundleCreateRequest _cacheRequest;
|
||||||
|
|
||||||
|
|
||||||
|
public AssetBundleFileLoader(BundleInfo bundleInfo) : base(bundleInfo)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮询更新
|
||||||
|
/// </summary>
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.None)
|
||||||
|
{
|
||||||
|
// 检测加载地址是否为空
|
||||||
|
if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
|
||||||
|
_steps = ESteps.LoadFile;
|
||||||
|
else
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 从服务器下载
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
int failedTryAgain = int.MaxValue;
|
||||||
|
_downloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain);
|
||||||
|
_steps = ESteps.CheckDownload;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检测服务器下载结果
|
||||||
|
if (_steps == ESteps.CheckDownload)
|
||||||
|
{
|
||||||
|
if (_downloader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader.HasError())
|
||||||
|
{
|
||||||
|
_downloader.ReportError();
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 加载AssetBundle
|
||||||
|
if (_steps == ESteps.LoadFile)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||||
|
if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Load assetBundle file
|
||||||
|
if (BundleFileInfo.IsEncrypted)
|
||||||
|
{
|
||||||
|
if (AssetSystem.DecryptionServices == null)
|
||||||
|
throw new Exception($"{nameof(AssetBundleFileLoader)} need IDecryptServices : {BundleFileInfo.BundleName}");
|
||||||
|
|
||||||
|
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo);
|
||||||
|
if (_isWaitForAsyncComplete)
|
||||||
|
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset);
|
||||||
|
else
|
||||||
|
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_isWaitForAsyncComplete)
|
||||||
|
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath);
|
||||||
|
else
|
||||||
|
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath);
|
||||||
|
}
|
||||||
|
_steps = ESteps.CheckFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 检测AssetBundle加载结果
|
||||||
|
if (_steps == ESteps.CheckFile)
|
||||||
|
{
|
||||||
|
if (_cacheRequest != null)
|
||||||
|
{
|
||||||
|
if (_isWaitForAsyncComplete)
|
||||||
|
{
|
||||||
|
// 强制挂起主线程(注意:该操作会很耗时)
|
||||||
|
YooLogger.Warning("Suspend the main thread to load unity bundle.");
|
||||||
|
CacheBundle = _cacheRequest.assetBundle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_cacheRequest.isDone == false)
|
||||||
|
return;
|
||||||
|
CacheBundle = _cacheRequest.assetBundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check error
|
||||||
|
if (CacheBundle == null)
|
||||||
|
{
|
||||||
|
YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主线程等待异步操作完毕
|
||||||
|
/// </summary>
|
||||||
|
public override void WaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
_isWaitForAsyncComplete = true;
|
||||||
|
|
||||||
|
int frame = 1000;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// 保险机制
|
||||||
|
// 注意:如果需要从WEB端下载资源,可能会触发保险机制!
|
||||||
|
frame--;
|
||||||
|
if (frame == 0)
|
||||||
|
{
|
||||||
|
if (_isShowWaitForAsyncError == false)
|
||||||
|
{
|
||||||
|
_isShowWaitForAsyncError = true;
|
||||||
|
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 驱动流程
|
||||||
|
Update();
|
||||||
|
|
||||||
|
// 完成后退出
|
||||||
|
if (IsDone())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,301 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class AssetBundleLoader
|
|
||||||
{
|
|
||||||
public enum EStatus
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Download,
|
|
||||||
CheckDownload,
|
|
||||||
LoadFile,
|
|
||||||
CheckFile,
|
|
||||||
Success,
|
|
||||||
Fail,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源包文件信息
|
|
||||||
/// </summary>
|
|
||||||
public BundleInfo BundleFileInfo { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 引用计数
|
|
||||||
/// </summary>
|
|
||||||
public int RefCount { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载状态
|
|
||||||
/// </summary>
|
|
||||||
public EStatus Status { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已经销毁
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDestroyed { private set; get; } = false;
|
|
||||||
|
|
||||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
|
||||||
private bool _isWaitForAsyncComplete = false;
|
|
||||||
private bool _isShowWaitForAsyncError = false;
|
|
||||||
private DownloaderBase _downloader;
|
|
||||||
private AssetBundleCreateRequest _cacheRequest;
|
|
||||||
internal AssetBundle CacheBundle { private set; get; }
|
|
||||||
|
|
||||||
|
|
||||||
public AssetBundleLoader(BundleInfo bundleInfo)
|
|
||||||
{
|
|
||||||
BundleFileInfo = bundleInfo;
|
|
||||||
RefCount = 0;
|
|
||||||
Status = EStatus.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加附属的资源提供者
|
|
||||||
/// </summary>
|
|
||||||
public void AddProvider(ProviderBase provider)
|
|
||||||
{
|
|
||||||
if (_providers.Contains(provider) == false)
|
|
||||||
_providers.Add(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 引用(引用计数递加)
|
|
||||||
/// </summary>
|
|
||||||
public void Reference()
|
|
||||||
{
|
|
||||||
RefCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 释放(引用计数递减)
|
|
||||||
/// </summary>
|
|
||||||
public void Release()
|
|
||||||
{
|
|
||||||
RefCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 轮询更新
|
|
||||||
/// </summary>
|
|
||||||
public void Update()
|
|
||||||
{
|
|
||||||
// 如果资源文件加载完毕
|
|
||||||
if (IsDone())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Status == EStatus.None)
|
|
||||||
{
|
|
||||||
// 检测加载地址是否为空
|
|
||||||
if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
|
|
||||||
{
|
|
||||||
Status = EStatus.Fail;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
|
|
||||||
Status = EStatus.LoadFile;
|
|
||||||
else
|
|
||||||
Status = EStatus.Download;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 从服务器下载
|
|
||||||
if (Status == EStatus.Download)
|
|
||||||
{
|
|
||||||
int failedTryAgain = int.MaxValue;
|
|
||||||
_downloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain);
|
|
||||||
Status = EStatus.CheckDownload;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 检测服务器下载结果
|
|
||||||
if (Status == EStatus.CheckDownload)
|
|
||||||
{
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_downloader.HasError())
|
|
||||||
{
|
|
||||||
_downloader.ReportError();
|
|
||||||
Status = EStatus.Fail;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = EStatus.LoadFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 加载AssetBundle
|
|
||||||
if (Status == EStatus.LoadFile)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
|
||||||
if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
|
|
||||||
Status = EStatus.Fail;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Load assetBundle file
|
|
||||||
if (BundleFileInfo.IsEncrypted)
|
|
||||||
{
|
|
||||||
if (AssetSystem.DecryptionServices == null)
|
|
||||||
throw new Exception($"{nameof(AssetBundleLoader)} need IDecryptServices : {BundleFileInfo.BundleName}");
|
|
||||||
|
|
||||||
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo);
|
|
||||||
if (_isWaitForAsyncComplete)
|
|
||||||
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset);
|
|
||||||
else
|
|
||||||
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_isWaitForAsyncComplete)
|
|
||||||
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath);
|
|
||||||
else
|
|
||||||
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath);
|
|
||||||
}
|
|
||||||
Status = EStatus.CheckFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 检测AssetBundle加载结果
|
|
||||||
if (Status == EStatus.CheckFile)
|
|
||||||
{
|
|
||||||
if (_cacheRequest != null)
|
|
||||||
{
|
|
||||||
if (_isWaitForAsyncComplete)
|
|
||||||
{
|
|
||||||
// 强制挂起主线程(注意:该操作会很耗时)
|
|
||||||
YooLogger.Warning("Suspend the main thread to load unity bundle.");
|
|
||||||
CacheBundle = _cacheRequest.assetBundle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_cacheRequest.isDone == false)
|
|
||||||
return;
|
|
||||||
CacheBundle = _cacheRequest.assetBundle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check error
|
|
||||||
if (CacheBundle == null)
|
|
||||||
{
|
|
||||||
YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
|
|
||||||
Status = EStatus.Fail;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = EStatus.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 销毁
|
|
||||||
/// </summary>
|
|
||||||
public void Destroy(bool forceDestroy)
|
|
||||||
{
|
|
||||||
IsDestroyed = true;
|
|
||||||
|
|
||||||
// Check fatal
|
|
||||||
if (forceDestroy == false)
|
|
||||||
{
|
|
||||||
if (RefCount > 0)
|
|
||||||
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}");
|
|
||||||
if (IsDone() == false)
|
|
||||||
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CacheBundle != null)
|
|
||||||
{
|
|
||||||
CacheBundle.Unload(true);
|
|
||||||
CacheBundle = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否完毕(无论成功或失败)
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDone()
|
|
||||||
{
|
|
||||||
return Status == EStatus.Success || Status == EStatus.Fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否可以销毁
|
|
||||||
/// </summary>
|
|
||||||
public bool CanDestroy()
|
|
||||||
{
|
|
||||||
if (IsDone() == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return RefCount <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 在满足条件的前提下,销毁所有资源提供者
|
|
||||||
/// </summary>
|
|
||||||
public void TryDestroyAllProviders()
|
|
||||||
{
|
|
||||||
if (IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 注意:必须等待所有Provider可以销毁的时候,才可以释放Bundle文件。
|
|
||||||
foreach (var provider in _providers)
|
|
||||||
{
|
|
||||||
if (provider.CanDestroy() == false)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 除了自己没有其它引用
|
|
||||||
if (RefCount > _providers.Count)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 销毁所有Providers
|
|
||||||
foreach (var provider in _providers)
|
|
||||||
{
|
|
||||||
provider.Destory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从列表里移除Providers
|
|
||||||
AssetSystem.RemoveBundleProviders(_providers);
|
|
||||||
_providers.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 主线程等待异步操作完毕
|
|
||||||
/// </summary>
|
|
||||||
public void WaitForAsyncComplete()
|
|
||||||
{
|
|
||||||
_isWaitForAsyncComplete = true;
|
|
||||||
|
|
||||||
int frame = 1000;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// 保险机制
|
|
||||||
// 注意:如果需要从WEB端下载资源,可能会触发保险机制!
|
|
||||||
frame--;
|
|
||||||
if (frame == 0)
|
|
||||||
{
|
|
||||||
if (_isShowWaitForAsyncError == false)
|
|
||||||
{
|
|
||||||
_isShowWaitForAsyncError = true;
|
|
||||||
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 驱动流程
|
|
||||||
Update();
|
|
||||||
|
|
||||||
// 完成后退出
|
|
||||||
if (IsDone())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal abstract class AssetBundleLoaderBase
|
||||||
|
{
|
||||||
|
public enum EStatus
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Succeed,
|
||||||
|
Failed
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包文件信息
|
||||||
|
/// </summary>
|
||||||
|
public BundleInfo BundleFileInfo { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 引用计数
|
||||||
|
/// </summary>
|
||||||
|
public int RefCount { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载状态
|
||||||
|
/// </summary>
|
||||||
|
public EStatus Status { protected set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已经销毁
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDestroyed { private set; get; } = false;
|
||||||
|
|
||||||
|
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
||||||
|
internal AssetBundle CacheBundle { set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public AssetBundleLoaderBase(BundleInfo bundleInfo)
|
||||||
|
{
|
||||||
|
BundleFileInfo = bundleInfo;
|
||||||
|
RefCount = 0;
|
||||||
|
Status = EStatus.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加附属的资源提供者
|
||||||
|
/// </summary>
|
||||||
|
public void AddProvider(ProviderBase provider)
|
||||||
|
{
|
||||||
|
if (_providers.Contains(provider) == false)
|
||||||
|
_providers.Add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 引用(引用计数递加)
|
||||||
|
/// </summary>
|
||||||
|
public void Reference()
|
||||||
|
{
|
||||||
|
RefCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放(引用计数递减)
|
||||||
|
/// </summary>
|
||||||
|
public void Release()
|
||||||
|
{
|
||||||
|
RefCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮询更新
|
||||||
|
/// </summary>
|
||||||
|
public abstract void Update();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销毁
|
||||||
|
/// </summary>
|
||||||
|
public void Destroy(bool forceDestroy)
|
||||||
|
{
|
||||||
|
IsDestroyed = true;
|
||||||
|
|
||||||
|
// Check fatal
|
||||||
|
if (forceDestroy == false)
|
||||||
|
{
|
||||||
|
if (RefCount > 0)
|
||||||
|
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}");
|
||||||
|
if (IsDone() == false)
|
||||||
|
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CacheBundle != null)
|
||||||
|
{
|
||||||
|
CacheBundle.Unload(true);
|
||||||
|
CacheBundle = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否完毕(无论成功或失败)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDone()
|
||||||
|
{
|
||||||
|
return Status == EStatus.Succeed || Status == EStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否可以销毁
|
||||||
|
/// </summary>
|
||||||
|
public bool CanDestroy()
|
||||||
|
{
|
||||||
|
if (IsDone() == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return RefCount <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 在满足条件的前提下,销毁所有资源提供者
|
||||||
|
/// </summary>
|
||||||
|
public void TryDestroyAllProviders()
|
||||||
|
{
|
||||||
|
if (IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 注意:必须等待所有Provider可以销毁的时候,才可以释放Bundle文件。
|
||||||
|
foreach (var provider in _providers)
|
||||||
|
{
|
||||||
|
if (provider.CanDestroy() == false)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 除了自己没有其它引用
|
||||||
|
if (RefCount > _providers.Count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 销毁所有Providers
|
||||||
|
foreach (var provider in _providers)
|
||||||
|
{
|
||||||
|
provider.Destory();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从列表里移除Providers
|
||||||
|
AssetSystem.RemoveBundleProviders(_providers);
|
||||||
|
_providers.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主线程等待异步操作完毕
|
||||||
|
/// </summary>
|
||||||
|
public abstract void WaitForAsyncComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8aaabc43e74af14d8eb3c7c85e19cda
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal sealed class AssetBundleWebLoader : AssetBundleLoaderBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
LoadFile,
|
||||||
|
CheckFile,
|
||||||
|
TryLoad,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
private float _tryTimer = 0;
|
||||||
|
private string _webURL;
|
||||||
|
private UnityWebRequest _webRequest;
|
||||||
|
|
||||||
|
|
||||||
|
public AssetBundleWebLoader(BundleInfo bundleInfo) : base(bundleInfo)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮询更新
|
||||||
|
/// </summary>
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.None)
|
||||||
|
{
|
||||||
|
// 检测加载地址是否为空
|
||||||
|
if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
|
||||||
|
_webURL = BundleFileInfo.LocalPath;
|
||||||
|
else
|
||||||
|
_webURL = BundleFileInfo.RemoteMainURL;
|
||||||
|
_steps = ESteps.LoadFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 从服务器或缓存中获取AssetBundle文件
|
||||||
|
if (_steps == ESteps.LoadFile)
|
||||||
|
{
|
||||||
|
string hash = StringUtility.RemoveExtension(BundleFileInfo.Hash);
|
||||||
|
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
|
||||||
|
_webRequest.SendWebRequest();
|
||||||
|
_steps = ESteps.CheckFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检测获取的AssetBundle文件
|
||||||
|
if (_steps == ESteps.CheckFile)
|
||||||
|
{
|
||||||
|
if (_webRequest.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#if UNITY_2020_1_OR_NEWER
|
||||||
|
if (_webRequest.result != UnityWebRequest.Result.Success)
|
||||||
|
#else
|
||||||
|
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed to get asset bundle form web : {_webURL} Error : {_webRequest.error}");
|
||||||
|
_steps = ESteps.TryLoad;
|
||||||
|
_tryTimer = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CacheBundle = DownloadHandlerAssetBundle.GetContent(_webRequest);
|
||||||
|
if (CacheBundle == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Get asset bundle error : {_webRequest.error}");
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 如果获取失败,重新尝试
|
||||||
|
if (_steps == ESteps.TryLoad)
|
||||||
|
{
|
||||||
|
_tryTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryTimer > 1f)
|
||||||
|
{
|
||||||
|
_webRequest.Dispose();
|
||||||
|
_webRequest = null;
|
||||||
|
_steps = ESteps.LoadFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主线程等待异步操作完毕
|
||||||
|
/// </summary>
|
||||||
|
public override void WaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException($"WebGL platform not support {nameof(WaitForAsyncComplete)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bd1ad395c62c5804589ec9b267ea0484
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -9,7 +9,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源包加载器列表
|
/// 依赖的资源包加载器列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<AssetBundleLoader> _dependBundles;
|
private readonly List<AssetBundleLoaderBase> _dependBundles;
|
||||||
|
|
||||||
public DependAssetBundleGrouper(string assetPath)
|
public DependAssetBundleGrouper(string assetPath)
|
||||||
{
|
{
|
||||||
@@ -72,7 +72,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
var bundleInfo = new DebugBundleInfo();
|
var bundleInfo = new DebugBundleInfo();
|
||||||
bundleInfo.BundleName = loader.BundleFileInfo.BundleName;
|
bundleInfo.BundleName = loader.BundleFileInfo.BundleName;
|
||||||
bundleInfo.Version = loader.BundleFileInfo.Version;
|
|
||||||
bundleInfo.RefCount = loader.RefCount;
|
bundleInfo.RefCount = loader.RefCount;
|
||||||
bundleInfo.Status = loader.Status;
|
bundleInfo.Status = loader.Status;
|
||||||
output.Add(bundleInfo);
|
output.Add(bundleInfo);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace YooAsset
|
|||||||
private readonly Vector3 _position;
|
private readonly Vector3 _position;
|
||||||
private readonly Quaternion _rotation;
|
private readonly Quaternion _rotation;
|
||||||
private readonly Transform _parent;
|
private readonly Transform _parent;
|
||||||
|
private readonly bool _setPositionRotation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,12 +24,13 @@ namespace YooAsset
|
|||||||
public GameObject Result = null;
|
public GameObject Result = null;
|
||||||
|
|
||||||
|
|
||||||
internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent)
|
internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||||
{
|
{
|
||||||
_handle = handle;
|
_handle = handle;
|
||||||
_position = position;
|
_position = position;
|
||||||
_rotation = rotation;
|
_rotation = rotation;
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
_setPositionRotation = setPositionRotation;
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
@@ -54,10 +56,20 @@ namespace YooAsset
|
|||||||
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
|
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_parent == null)
|
if(_setPositionRotation)
|
||||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
|
{
|
||||||
|
if (_parent == null)
|
||||||
|
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
|
||||||
|
else
|
||||||
|
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
|
{
|
||||||
|
if (_parent == null)
|
||||||
|
Result = Object.Instantiate(_handle.AssetObject as GameObject);
|
||||||
|
else
|
||||||
|
Result = Object.Instantiate(_handle.AssetObject as GameObject, _parent);
|
||||||
|
}
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal abstract class BundledProvider : ProviderBase
|
internal abstract class BundledProvider : ProviderBase
|
||||||
{
|
{
|
||||||
protected AssetBundleLoader OwnerBundle { private set; get; }
|
protected AssetBundleLoaderBase OwnerBundle { private set; get; }
|
||||||
protected DependAssetBundleGrouper DependBundles { private set; get; }
|
protected DependAssetBundleGrouper DependBundles { private set; get; }
|
||||||
|
|
||||||
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType)
|
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType)
|
||||||
@@ -40,7 +40,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
var bundleInfo = new DebugBundleInfo();
|
var bundleInfo = new DebugBundleInfo();
|
||||||
bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
|
bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
|
||||||
bundleInfo.Version = OwnerBundle.BundleFileInfo.Version;
|
|
||||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||||
bundleInfo.Status = OwnerBundle.Status;
|
bundleInfo.Status = OwnerBundle.Status;
|
||||||
output.Add(bundleInfo);
|
output.Add(bundleInfo);
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string BundleName { set; get; }
|
public string BundleName { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源版本
|
|
||||||
/// </summary>
|
|
||||||
public int Version { set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引用计数
|
/// 引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,6 +16,6 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载状态
|
/// 加载状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetBundleLoader.EStatus Status { set; get; }
|
public AssetBundleLoaderBase.EStatus Status { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,20 +67,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源版本
|
|
||||||
/// </summary>
|
|
||||||
public int Version
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_patchBundle == null)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return _patchBundle.Version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否为加密文件
|
/// 是否为加密文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -34,15 +34,13 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadAppManifest,
|
Update,
|
||||||
CheckAppManifest,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private OfflinePlayModeImpl _impl;
|
private readonly OfflinePlayModeImpl _impl;
|
||||||
|
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
private string _downloadURL;
|
|
||||||
|
|
||||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
||||||
{
|
{
|
||||||
@@ -50,41 +48,32 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
_steps = ESteps.LoadAppManifest;
|
_steps = ESteps.Update;
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.LoadAppManifest)
|
if (_steps == ESteps.Update)
|
||||||
{
|
{
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
_appManifestLoader.Update();
|
||||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
if (_appManifestLoader.IsDone() == false)
|
||||||
_downloader = new UnityWebDataRequester();
|
|
||||||
_downloader.SendRequest(_downloadURL);
|
|
||||||
_steps = ESteps.CheckAppManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckAppManifest)
|
|
||||||
{
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloader.HasError())
|
if (_appManifestLoader.Result == null)
|
||||||
{
|
{
|
||||||
Error = _downloader.GetError();
|
|
||||||
_downloader.Dispose();
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
throw new System.Exception($"Fatal error : Failed load application patch manifest file : {_downloadURL}");
|
Error = _appManifestLoader.Error;
|
||||||
|
throw new System.Exception($"FATAL : {_appManifestLoader.Error}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
_impl.AppPatchManifest = _appManifestLoader.Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析APP里的补丁清单
|
|
||||||
_impl.AppPatchManifest = PatchManifest.Deserialize(_downloader.GetText());
|
|
||||||
_downloader.Dispose();
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,16 +87,13 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
InitCache,
|
InitCache,
|
||||||
LoadAppManifest,
|
Update,
|
||||||
CheckAppManifest,
|
|
||||||
LoadSandboxManifest,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
|
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
private string _downloadURL;
|
|
||||||
|
|
||||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
||||||
{
|
{
|
||||||
@@ -137,60 +123,137 @@ namespace YooAsset
|
|||||||
SandboxHelper.DeleteSandboxCacheFolder();
|
SandboxHelper.DeleteSandboxCacheFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除清单文件
|
|
||||||
SandboxHelper.DeleteSandboxPatchManifestFile();
|
|
||||||
// 更新缓存文件
|
// 更新缓存文件
|
||||||
PatchCache.UpdateCache();
|
PatchCache.UpdateCache();
|
||||||
}
|
}
|
||||||
_steps = ESteps.LoadAppManifest;
|
_steps = ESteps.Update;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Update)
|
||||||
|
{
|
||||||
|
_appManifestLoader.Update();
|
||||||
|
if (_appManifestLoader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_appManifestLoader.Result == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _appManifestLoader.Error;
|
||||||
|
throw new System.Exception($"FATAL : {_appManifestLoader.Error}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
_impl.AppPatchManifest = _appManifestLoader.Result;
|
||||||
|
_impl.LocalPatchManifest = _appManifestLoader.Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置补丁清单加载器
|
||||||
|
/// </summary>
|
||||||
|
internal class AppManifestLoader
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
LoadStaticVersion,
|
||||||
|
CheckStaticVersion,
|
||||||
|
LoadAppManifest,
|
||||||
|
CheckAppManifest,
|
||||||
|
Succeed,
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
|
private ESteps _steps = ESteps.LoadStaticVersion;
|
||||||
|
private UnityWebDataRequester _downloader1;
|
||||||
|
private UnityWebDataRequester _downloader2;
|
||||||
|
private int _staticVersion = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 错误日志
|
||||||
|
/// </summary>
|
||||||
|
public string Error { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 补丁清单
|
||||||
|
/// </summary>
|
||||||
|
public PatchManifest Result { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已经完成
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDone()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.Succeed || _steps == ESteps.Failed)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (IsDone())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadStaticVersion)
|
||||||
|
{
|
||||||
|
YooLogger.Log($"Load application static version.");
|
||||||
|
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettings.VersionFileName);
|
||||||
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
|
_downloader1 = new UnityWebDataRequester();
|
||||||
|
_downloader1.SendRequest(url);
|
||||||
|
_steps = ESteps.CheckStaticVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckStaticVersion)
|
||||||
|
{
|
||||||
|
if (_downloader1.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader1.HasError())
|
||||||
|
{
|
||||||
|
Error = _downloader1.GetError();
|
||||||
|
_steps = ESteps.Failed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_staticVersion = int.Parse(_downloader1.GetText());
|
||||||
|
_steps = ESteps.LoadAppManifest;
|
||||||
|
}
|
||||||
|
_downloader1.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadAppManifest)
|
if (_steps == ESteps.LoadAppManifest)
|
||||||
{
|
{
|
||||||
// 加载APP内的补丁清单
|
|
||||||
YooLogger.Log($"Load application patch manifest.");
|
YooLogger.Log($"Load application patch manifest.");
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
||||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
_downloader = new UnityWebDataRequester();
|
_downloader2 = new UnityWebDataRequester();
|
||||||
_downloader.SendRequest(_downloadURL);
|
_downloader2.SendRequest(url);
|
||||||
_steps = ESteps.CheckAppManifest;
|
_steps = ESteps.CheckAppManifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.CheckAppManifest)
|
if (_steps == ESteps.CheckAppManifest)
|
||||||
{
|
{
|
||||||
if (_downloader.IsDone() == false)
|
if (_downloader2.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloader.HasError())
|
if (_downloader2.HasError())
|
||||||
{
|
{
|
||||||
Error = _downloader.GetError();
|
Error = _downloader2.GetError();
|
||||||
_downloader.Dispose();
|
_steps = ESteps.Failed;
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
throw new System.Exception($"Fatal error : Failed load application patch manifest file : {_downloadURL}");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// 解析补丁清单
|
|
||||||
string jsonData = _downloader.GetText();
|
|
||||||
_impl.AppPatchManifest = PatchManifest.Deserialize(jsonData);
|
|
||||||
_impl.LocalPatchManifest = _impl.AppPatchManifest;
|
|
||||||
_downloader.Dispose();
|
|
||||||
_steps = ESteps.LoadSandboxManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.LoadSandboxManifest)
|
|
||||||
{
|
|
||||||
// 加载沙盒内的补丁清单
|
|
||||||
if (SandboxHelper.CheckSandboxPatchManifestFileExist())
|
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Load sandbox patch manifest.");
|
// 解析APP里的补丁清单
|
||||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
Result = PatchManifest.Deserialize(_downloader2.GetText());
|
||||||
string jsonData = File.ReadAllText(filePath);
|
_steps = ESteps.Succeed;
|
||||||
_impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData);
|
|
||||||
}
|
}
|
||||||
|
_downloader2.Dispose();
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int RequestCount = 0;
|
private static int RequestCount = 0;
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly int _updateResourceVersion;
|
private readonly int _updateResourceVersion;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
@@ -78,15 +77,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
RequestCount++;
|
RequestCount++;
|
||||||
_steps = ESteps.LoadWebManifestHash;
|
_steps = ESteps.LoadWebManifestHash;
|
||||||
|
|
||||||
if (_impl.IgnoreResourceVersion && _updateResourceVersion > 0)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Update resource version {_updateResourceVersion} is invalid when ignore resource version.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Update patch manifest : update resource version is {_updateResourceVersion}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
@@ -95,7 +85,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.LoadWebManifestHash)
|
if (_steps == ESteps.LoadWebManifestHash)
|
||||||
{
|
{
|
||||||
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, YooAssetSettingsData.Setting.PatchManifestHashFileName);
|
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_updateResourceVersion));
|
||||||
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
||||||
_downloaderHash = new UnityWebDataRequester();
|
_downloaderHash = new UnityWebDataRequester();
|
||||||
_downloaderHash.SendRequest(webURL, _timeout);
|
_downloaderHash.SendRequest(webURL, _timeout);
|
||||||
@@ -107,37 +97,36 @@ namespace YooAsset
|
|||||||
if (_downloaderHash.IsDone() == false)
|
if (_downloaderHash.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check fatal
|
// Check error
|
||||||
if (_downloaderHash.HasError())
|
if (_downloaderHash.HasError())
|
||||||
{
|
{
|
||||||
Error = _downloaderHash.GetError();
|
|
||||||
_downloaderHash.Dispose();
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
return;
|
Error = _downloaderHash.GetError();
|
||||||
}
|
|
||||||
|
|
||||||
// 获取补丁清单文件的哈希值
|
|
||||||
string webManifestHash = _downloaderHash.GetText();
|
|
||||||
_downloaderHash.Dispose();
|
|
||||||
|
|
||||||
// 如果补丁清单文件的哈希值相同
|
|
||||||
string currentFileHash = SandboxHelper.GetSandboxPatchManifestFileHash();
|
|
||||||
if (currentFileHash == webManifestHash)
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
|
||||||
_steps = ESteps.InitPrepareCache;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {currentFileHash}");
|
string webManifestHash = _downloaderHash.GetText();
|
||||||
_steps = ESteps.LoadWebManifest;
|
string cachedManifestHash = GetSandboxPatchManifestFileHash(_updateResourceVersion);
|
||||||
|
|
||||||
|
// 如果补丁清单文件的哈希值相同
|
||||||
|
if (cachedManifestHash == webManifestHash)
|
||||||
|
{
|
||||||
|
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
||||||
|
_steps = ESteps.InitPrepareCache;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
|
||||||
|
_steps = ESteps.LoadWebManifest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_downloaderHash.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadWebManifest)
|
if (_steps == ESteps.LoadWebManifest)
|
||||||
{
|
{
|
||||||
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, YooAssetSettingsData.Setting.PatchManifestFileName);
|
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_updateResourceVersion));
|
||||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||||
_downloaderManifest = new UnityWebDataRequester();
|
_downloaderManifest = new UnityWebDataRequester();
|
||||||
_downloaderManifest.SendRequest(webURL, _timeout);
|
_downloaderManifest.SendRequest(webURL, _timeout);
|
||||||
@@ -149,20 +138,28 @@ namespace YooAsset
|
|||||||
if (_downloaderManifest.IsDone() == false)
|
if (_downloaderManifest.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check fatal
|
// Check error
|
||||||
if (_downloaderManifest.HasError())
|
if (_downloaderManifest.HasError())
|
||||||
{
|
{
|
||||||
Error = _downloaderManifest.GetError();
|
|
||||||
_downloaderManifest.Dispose();
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
return;
|
Error = _downloaderManifest.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 解析补丁清单
|
||||||
|
if (ParseAndSaveRemotePatchManifest(_updateResourceVersion, _downloaderManifest.GetText()))
|
||||||
|
{
|
||||||
|
_steps = ESteps.InitPrepareCache;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析补丁清单
|
|
||||||
ParseAndSaveRemotePatchManifest(_downloaderManifest.GetText());
|
|
||||||
_downloaderManifest.Dispose();
|
_downloaderManifest.Dispose();
|
||||||
_steps = ESteps.InitPrepareCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitPrepareCache)
|
if (_steps == ESteps.InitPrepareCache)
|
||||||
@@ -184,30 +181,47 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetPatchManifestRequestURL(int updateResourceVersion, string fileName)
|
private string GetPatchManifestRequestURL(string fileName)
|
||||||
{
|
{
|
||||||
string url;
|
|
||||||
|
|
||||||
// 轮流返回请求地址
|
// 轮流返回请求地址
|
||||||
if (RequestCount % 2 == 0)
|
if (RequestCount % 2 == 0)
|
||||||
url = _impl.GetPatchDownloadFallbackURL(updateResourceVersion, fileName);
|
return _impl.GetPatchDownloadFallbackURL(fileName);
|
||||||
else
|
else
|
||||||
url = _impl.GetPatchDownloadMainURL(updateResourceVersion, fileName);
|
return _impl.GetPatchDownloadMainURL(fileName);
|
||||||
|
|
||||||
// 注意:在URL末尾添加时间戳
|
|
||||||
if (_impl.IgnoreResourceVersion)
|
|
||||||
url = $"{url}?{System.DateTime.UtcNow.Ticks}";
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
private void ParseAndSaveRemotePatchManifest(string content)
|
|
||||||
{
|
|
||||||
_impl.LocalPatchManifest = PatchManifest.Deserialize(content);
|
|
||||||
|
|
||||||
// 注意:这里会覆盖掉沙盒内的补丁清单文件
|
/// <summary>
|
||||||
YooLogger.Log("Save remote patch manifest file.");
|
/// 解析并保存远端请求的补丁清单
|
||||||
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
/// </summary>
|
||||||
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
|
private bool ParseAndSaveRemotePatchManifest(int updateResourceVersion, string content)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_impl.LocalPatchManifest = PatchManifest.Deserialize(content);
|
||||||
|
|
||||||
|
YooLogger.Log("Save remote patch manifest file.");
|
||||||
|
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||||
|
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
YooLogger.Warning(e.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取沙盒内补丁清单文件的哈希值
|
||||||
|
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
|
||||||
|
/// </summary>
|
||||||
|
private string GetSandboxPatchManifestFileHash(int updateResourceVersion)
|
||||||
|
{
|
||||||
|
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
return HashUtility.FileMD5(filePath);
|
||||||
|
else
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 多线程相关
|
#region 多线程相关
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 更新静态版本操作
|
||||||
|
/// </summary>
|
||||||
|
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源版本号
|
||||||
|
/// </summary>
|
||||||
|
public int ResourceVersion { protected set; get; } = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器下模拟运行的更新静态版本操作
|
||||||
|
/// </summary>
|
||||||
|
internal class EditorModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||||
|
{
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 离线模式的更新静态版本操作
|
||||||
|
/// </summary>
|
||||||
|
internal class OfflinePlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||||
|
{
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 网络模式的更新静态版本操作
|
||||||
|
/// </summary>
|
||||||
|
internal class HostPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadStaticVersion,
|
||||||
|
CheckStaticVersion,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int RequestCount = 0;
|
||||||
|
private readonly HostPlayModeImpl _impl;
|
||||||
|
private readonly int _timeout;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
private UnityWebDataRequester _downloader;
|
||||||
|
|
||||||
|
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, int timeout)
|
||||||
|
{
|
||||||
|
_impl = impl;
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
RequestCount++;
|
||||||
|
_steps = ESteps.LoadStaticVersion;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadStaticVersion)
|
||||||
|
{
|
||||||
|
string webURL = GetStaticVersionRequestURL(YooAssetSettings.VersionFileName);
|
||||||
|
YooLogger.Log($"Beginning to request static version : {webURL}");
|
||||||
|
_downloader = new UnityWebDataRequester();
|
||||||
|
_downloader.SendRequest(webURL, _timeout);
|
||||||
|
_steps = ESteps.CheckStaticVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckStaticVersion)
|
||||||
|
{
|
||||||
|
if (_downloader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (int.TryParse(_downloader.GetText(), out int value))
|
||||||
|
{
|
||||||
|
ResourceVersion = value;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_downloader.URL} Error : static version content is invalid.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_downloader.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetStaticVersionRequestURL(string fileName)
|
||||||
|
{
|
||||||
|
string url;
|
||||||
|
|
||||||
|
// 轮流返回请求地址
|
||||||
|
if (RequestCount % 2 == 0)
|
||||||
|
url = _impl.GetPatchDownloadFallbackURL(fileName);
|
||||||
|
else
|
||||||
|
url = _impl.GetPatchDownloadMainURL(fileName);
|
||||||
|
|
||||||
|
// 注意:在URL末尾添加时间戳
|
||||||
|
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 60bb21def73049e4f83a108d0e741301
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -26,11 +26,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long SizeBytes;
|
public long SizeBytes;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件版本
|
|
||||||
/// </summary>
|
|
||||||
public int Version;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tags
|
/// Tags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,13 +54,12 @@ namespace YooAsset
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, int version, string[] tags)
|
public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, string[] tags)
|
||||||
{
|
{
|
||||||
BundleName = bundleName;
|
BundleName = bundleName;
|
||||||
Hash = hash;
|
Hash = hash;
|
||||||
CRC = crc;
|
CRC = crc;
|
||||||
SizeBytes = sizeBytes;
|
SizeBytes = sizeBytes;
|
||||||
Version = version;
|
|
||||||
Tags = tags;
|
Tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,15 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (SandboxHelper.CheckSandboxCacheFileExist())
|
if (SandboxHelper.CheckSandboxCacheFileExist())
|
||||||
{
|
{
|
||||||
YooLogger.Log("Load patch cache from disk.");
|
|
||||||
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
||||||
string jsonData = FileUtility.ReadFile(filePath);
|
string jsonData = FileUtility.ReadFile(filePath);
|
||||||
return JsonUtility.FromJson<PatchCache>(jsonData);
|
var patchCache = JsonUtility.FromJson<PatchCache>(jsonData);
|
||||||
|
YooLogger.Log($"Load cache file : {patchCache.CacheAppVersion}");
|
||||||
|
return patchCache;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Create patch cache to disk : {Application.version}");
|
YooLogger.Log($"Create cache file : {Application.version}");
|
||||||
PatchCache cache = new PatchCache();
|
PatchCache cache = new PatchCache();
|
||||||
cache.CacheAppVersion = Application.version;
|
cache.CacheAppVersion = Application.version;
|
||||||
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
||||||
|
|||||||
@@ -12,18 +12,15 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 参数相关
|
// 参数相关
|
||||||
internal bool ClearCacheWhenDirty { private set; get; }
|
internal bool ClearCacheWhenDirty { private set; get; }
|
||||||
internal bool IgnoreResourceVersion { private set; get; }
|
|
||||||
private string _defaultHostServer;
|
private string _defaultHostServer;
|
||||||
private string _fallbackHostServer;
|
private string _fallbackHostServer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public InitializationOperation InitializeAsync(bool clearCacheWhenDirty, bool ignoreResourceVersion,
|
public InitializationOperation InitializeAsync(bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
|
||||||
string defaultHostServer, string fallbackHostServer)
|
|
||||||
{
|
{
|
||||||
ClearCacheWhenDirty = clearCacheWhenDirty;
|
ClearCacheWhenDirty = clearCacheWhenDirty;
|
||||||
IgnoreResourceVersion = ignoreResourceVersion;
|
|
||||||
_defaultHostServer = defaultHostServer;
|
_defaultHostServer = defaultHostServer;
|
||||||
_fallbackHostServer = fallbackHostServer;
|
_fallbackHostServer = fallbackHostServer;
|
||||||
|
|
||||||
@@ -32,6 +29,16 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步更新资源版本号
|
||||||
|
/// </summary>
|
||||||
|
public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout);
|
||||||
|
OperationSystem.ProcessOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步更新补丁清单
|
/// 异步更新补丁清单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -166,19 +173,13 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WEB相关
|
// WEB相关
|
||||||
public string GetPatchDownloadMainURL(int resourceVersion, string fileName)
|
public string GetPatchDownloadMainURL(string fileName)
|
||||||
{
|
{
|
||||||
if (IgnoreResourceVersion)
|
return $"{_defaultHostServer}/{fileName}";
|
||||||
return $"{_defaultHostServer}/{fileName}";
|
|
||||||
else
|
|
||||||
return $"{_defaultHostServer}/{resourceVersion}/{fileName}";
|
|
||||||
}
|
}
|
||||||
public string GetPatchDownloadFallbackURL(int resourceVersion, string fileName)
|
public string GetPatchDownloadFallbackURL(string fileName)
|
||||||
{
|
{
|
||||||
if (IgnoreResourceVersion)
|
return $"{_fallbackHostServer}/{fileName}";
|
||||||
return $"{_fallbackHostServer}/{fileName}";
|
|
||||||
else
|
|
||||||
return $"{_fallbackHostServer}/{resourceVersion}/{fileName}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载相关
|
// 下载相关
|
||||||
@@ -196,8 +197,8 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
// 注意:资源版本号只用于确定下载路径
|
// 注意:资源版本号只用于确定下载路径
|
||||||
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||||
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash);
|
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash);
|
||||||
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
|
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Hash);
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
/*
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class WebPlayModeImpl : IBundleServices
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03baa90d8f534834c9c31d469a507f66
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/YooAsset/Runtime/Services.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bf4cc5f446778bc428a69fdcd183e447
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
11
Assets/YooAsset/Runtime/Services/AddressLocationServices.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
public class AddressLocationServices : ILocationServices
|
||||||
|
{
|
||||||
|
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException("该功能暂未支持!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a8d6592eded144142afcf85c79cf1ce4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
77
Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
public class DefaultLocationServices : ILocationServices
|
||||||
|
{
|
||||||
|
private readonly string _resourceRoot;
|
||||||
|
|
||||||
|
public DefaultLocationServices(string resourceRoot)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(resourceRoot) == false)
|
||||||
|
_resourceRoot = PathHelper.GetRegularPath(resourceRoot);
|
||||||
|
}
|
||||||
|
public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
|
||||||
|
{
|
||||||
|
if (playMode == YooAssets.EPlayMode.EditorPlayMode)
|
||||||
|
{
|
||||||
|
string filePath = CombineAssetPath(_resourceRoot, location);
|
||||||
|
return FindDatabaseAssetPath(filePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return CombineAssetPath(_resourceRoot, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 合并资源路径
|
||||||
|
/// </summary>
|
||||||
|
private static string CombineAssetPath(string root, string location)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(root))
|
||||||
|
return location;
|
||||||
|
else
|
||||||
|
return $"{root}/{location}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取AssetDatabase的加载路径
|
||||||
|
/// </summary>
|
||||||
|
private static string FindDatabaseAssetPath(string filePath)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
return filePath;
|
||||||
|
|
||||||
|
// AssetDatabase加载资源需要提供文件后缀格式,然而资源定位地址并没有文件格式信息。
|
||||||
|
// 所以我们通过查找该文件所在文件夹内同名的首个文件来确定AssetDatabase的加载路径。
|
||||||
|
// 注意:AssetDatabase.FindAssets() 返回文件内包括递归文件夹内所有资源的GUID
|
||||||
|
string fileName = Path.GetFileName(filePath);
|
||||||
|
string directory = PathHelper.GetDirectory(filePath);
|
||||||
|
string[] guids = UnityEditor.AssetDatabase.FindAssets(string.Empty, new[] { directory });
|
||||||
|
for (int i = 0; i < guids.Length; i++)
|
||||||
|
{
|
||||||
|
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||||
|
|
||||||
|
if (UnityEditor.AssetDatabase.IsValidFolder(assetPath))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string assetDirectory = PathHelper.GetDirectory(assetPath);
|
||||||
|
if (assetDirectory != directory)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string assetName = Path.GetFileNameWithoutExtension(assetPath);
|
||||||
|
if (assetName == fileName)
|
||||||
|
return assetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 没有找到同名的资源文件
|
||||||
|
YooLogger.Warning($"Not found asset : {filePath}");
|
||||||
|
return filePath;
|
||||||
|
#else
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8d996937ba73c9b4bb942b8ba6f43398
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
11
Assets/YooAsset/Runtime/Services/ILocationServices.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
public interface ILocationServices
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 定位地址转换为资源路径
|
||||||
|
/// </summary>
|
||||||
|
string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/YooAsset/Runtime/Services/ILocationServices.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cfc81e18e5b5f6f4b821c7427b34d349
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -18,12 +18,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建输出的补丁清单文件名称
|
/// 构建输出的补丁清单文件名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PatchManifestFileName = "PatchManifest.bytes";
|
public string PatchManifestFileName = "PatchManifest";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构建输出的补丁清单哈希文件名称
|
|
||||||
/// </summary>
|
|
||||||
public string PatchManifestHashFileName = "PatchManifestHash.bytes";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建输出的Unity清单文件名称
|
/// 构建输出的Unity清单文件名称
|
||||||
@@ -34,5 +29,10 @@ namespace YooAsset
|
|||||||
/// 构建输出的报告文件
|
/// 构建输出的报告文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string ReportFileName = "BuildReport.json";
|
public const string ReportFileName = "BuildReport.json";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 静态版本文件
|
||||||
|
/// </summary>
|
||||||
|
public const string VersionFileName = "StaticVersion.bytes";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,5 +31,21 @@ namespace YooAsset
|
|||||||
YooLogger.Log("YooAsset use custom settings.");
|
YooLogger.Log("YooAsset use custom settings.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取补丁清单文件完整名称
|
||||||
|
/// </summary>
|
||||||
|
public static string GetPatchManifestFileName(int resourceVersion)
|
||||||
|
{
|
||||||
|
return $"{Setting.PatchManifestFileName}_{resourceVersion}.bytes";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取补丁清单哈希文件完整名称
|
||||||
|
/// </summary>
|
||||||
|
public static string GetPatchManifestHashFileName(int resourceVersion)
|
||||||
|
{
|
||||||
|
return $"{Setting.PatchManifestFileName}_{resourceVersion}.hash";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ConvertToWWWPath(string path)
|
public static string ConvertToWWWPath(string path)
|
||||||
{
|
{
|
||||||
// 注意:WWW加载方式,必须要在路径前面加file://
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
return StringUtility.Format("file:///{0}", path);
|
return StringUtility.Format("file:///{0}", path);
|
||||||
#elif UNITY_IPHONE
|
#elif UNITY_IPHONE
|
||||||
@@ -70,56 +69,8 @@ namespace YooAsset
|
|||||||
return path;
|
return path;
|
||||||
#elif UNITY_STANDALONE
|
#elif UNITY_STANDALONE
|
||||||
return StringUtility.Format("file:///{0}", path);
|
return StringUtility.Format("file:///{0}", path);
|
||||||
#endif
|
#elif UNITY_WEBGL
|
||||||
}
|
return path;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 合并资源路径
|
|
||||||
/// </summary>
|
|
||||||
public static string CombineAssetPath(string root, string location)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(root))
|
|
||||||
return location;
|
|
||||||
else
|
|
||||||
return $"{root}/{location}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取AssetDatabase的加载路径
|
|
||||||
/// </summary>
|
|
||||||
public static string FindDatabaseAssetPath(string filePath)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
return filePath;
|
|
||||||
|
|
||||||
// AssetDatabase加载资源需要提供文件后缀格式,然而资源定位地址并没有文件格式信息。
|
|
||||||
// 所以我们通过查找该文件所在文件夹内同名的首个文件来确定AssetDatabase的加载路径。
|
|
||||||
// 注意:AssetDatabase.FindAssets() 返回文件内包括递归文件夹内所有资源的GUID
|
|
||||||
string fileName = Path.GetFileName(filePath);
|
|
||||||
string directory = GetDirectory(filePath);
|
|
||||||
string[] guids = UnityEditor.AssetDatabase.FindAssets(string.Empty, new[] { directory });
|
|
||||||
for (int i = 0; i < guids.Length; i++)
|
|
||||||
{
|
|
||||||
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
|
|
||||||
|
|
||||||
if (UnityEditor.AssetDatabase.IsValidFolder(assetPath))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string assetDirectory = GetDirectory(assetPath);
|
|
||||||
if (assetDirectory != directory)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string assetName = Path.GetFileNameWithoutExtension(assetPath);
|
|
||||||
if (assetName == fileName)
|
|
||||||
return assetPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 没有找到同名的资源文件
|
|
||||||
YooLogger.Warning($"Not found asset : {filePath}");
|
|
||||||
return filePath;
|
|
||||||
#else
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,16 +93,6 @@ namespace YooAsset
|
|||||||
Directory.Delete(directoryPath, true);
|
Directory.Delete(directoryPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除沙盒内补丁清单文件
|
|
||||||
/// </summary>
|
|
||||||
public static void DeleteSandboxPatchManifestFile()
|
|
||||||
{
|
|
||||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
File.Delete(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除沙盒内的缓存文件
|
/// 删除沙盒内的缓存文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -190,29 +131,6 @@ namespace YooAsset
|
|||||||
return File.Exists(filePath);
|
return File.Exists(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测沙盒内补丁清单文件是否存在
|
|
||||||
/// </summary>
|
|
||||||
public static bool CheckSandboxPatchManifestFileExist()
|
|
||||||
{
|
|
||||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
|
||||||
return File.Exists(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取沙盒内补丁清单文件的哈希值
|
|
||||||
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string GetSandboxPatchManifestFileHash()
|
|
||||||
{
|
|
||||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.Setting.PatchManifestFileName);
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
return HashUtility.FileMD5(filePath);
|
|
||||||
else
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取缓存文件的存储路径
|
/// 获取缓存文件的存储路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 运行模式
|
/// 运行模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private enum EPlayMode
|
public enum EPlayMode
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编辑器下模拟运行模式
|
/// 编辑器下模拟运行模式
|
||||||
@@ -28,16 +28,18 @@ namespace YooAsset
|
|||||||
HostPlayMode,
|
HostPlayMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化参数
|
||||||
|
/// </summary>
|
||||||
public abstract class CreateParameters
|
public abstract class CreateParameters
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源定位的根路径
|
/// 资源定位服务接口
|
||||||
/// 例如:Assets/MyResource
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string LocationRoot;
|
public ILocationServices LocationServices = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件解密接口
|
/// 文件解密服务接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDecryptionServices DecryptionServices = null;
|
public IDecryptionServices DecryptionServices = null;
|
||||||
|
|
||||||
@@ -82,11 +84,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ClearCacheWhenDirty;
|
public bool ClearCacheWhenDirty;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 忽略资源版本号
|
|
||||||
/// </summary>
|
|
||||||
public bool IgnoreResourceVersion;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 默认的资源服务器下载地址
|
/// 默认的资源服务器下载地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,9 +102,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
|
|
||||||
private static bool _isInitialize = false;
|
private static bool _isInitialize = false;
|
||||||
private static string _locationRoot;
|
|
||||||
private static EPlayMode _playMode;
|
private static EPlayMode _playMode;
|
||||||
private static IBundleServices _bundleServices;
|
private static IBundleServices _bundleServices;
|
||||||
|
private static ILocationServices _locationServices;
|
||||||
private static EditorPlayModeImpl _editorPlayModeImpl;
|
private static EditorPlayModeImpl _editorPlayModeImpl;
|
||||||
private static OfflinePlayModeImpl _offlinePlayModeImpl;
|
private static OfflinePlayModeImpl _offlinePlayModeImpl;
|
||||||
private static HostPlayModeImpl _hostPlayModeImpl;
|
private static HostPlayModeImpl _hostPlayModeImpl;
|
||||||
@@ -124,6 +121,11 @@ namespace YooAsset
|
|||||||
if (parameters == null)
|
if (parameters == null)
|
||||||
throw new Exception($"YooAsset create parameters is null.");
|
throw new Exception($"YooAsset create parameters is null.");
|
||||||
|
|
||||||
|
if (parameters.LocationServices == null)
|
||||||
|
throw new Exception($"{nameof(IBundleServices)} is null.");
|
||||||
|
else
|
||||||
|
_locationServices = parameters.LocationServices;
|
||||||
|
|
||||||
#if !UNITY_EDITOR
|
#if !UNITY_EDITOR
|
||||||
if (parameters is EditorPlayModeParameters)
|
if (parameters is EditorPlayModeParameters)
|
||||||
throw new Exception($"Editor play mode only support unity editor.");
|
throw new Exception($"Editor play mode only support unity editor.");
|
||||||
@@ -154,9 +156,6 @@ namespace YooAsset
|
|||||||
YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 33 milliseconds");
|
YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 33 milliseconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(parameters.LocationRoot) == false)
|
|
||||||
_locationRoot = PathHelper.GetRegularPath(parameters.LocationRoot);
|
|
||||||
|
|
||||||
if (parameters.AutoReleaseInterval > 0)
|
if (parameters.AutoReleaseInterval > 0)
|
||||||
_releaseCD = parameters.AutoReleaseInterval;
|
_releaseCD = parameters.AutoReleaseInterval;
|
||||||
|
|
||||||
@@ -176,8 +175,12 @@ namespace YooAsset
|
|||||||
// 初始化下载系统
|
// 初始化下载系统
|
||||||
if (_playMode == EPlayMode.HostPlayMode)
|
if (_playMode == EPlayMode.HostPlayMode)
|
||||||
{
|
{
|
||||||
|
#if UNITY_WEBGL
|
||||||
|
throw new Exception($"{EPlayMode.HostPlayMode} not supports WebGL platform !");
|
||||||
|
#else
|
||||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||||
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize);
|
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化资源系统
|
// 初始化资源系统
|
||||||
@@ -203,7 +206,6 @@ namespace YooAsset
|
|||||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||||
return _hostPlayModeImpl.InitializeAsync(
|
return _hostPlayModeImpl.InitializeAsync(
|
||||||
hostPlayModeParameters.ClearCacheWhenDirty,
|
hostPlayModeParameters.ClearCacheWhenDirty,
|
||||||
hostPlayModeParameters.IgnoreResourceVersion,
|
|
||||||
hostPlayModeParameters.DefaultHostServer,
|
hostPlayModeParameters.DefaultHostServer,
|
||||||
hostPlayModeParameters.FallbackHostServer);
|
hostPlayModeParameters.FallbackHostServer);
|
||||||
}
|
}
|
||||||
@@ -213,6 +215,37 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 向网络端请求静态资源版本号
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60)
|
||||||
|
{
|
||||||
|
if (_playMode == EPlayMode.EditorPlayMode)
|
||||||
|
{
|
||||||
|
var operation = new EditorModeUpdateStaticVersionOperation();
|
||||||
|
OperationSystem.ProcessOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModeUpdateStaticVersionOperation();
|
||||||
|
OperationSystem.ProcessOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else if (_playMode == EPlayMode.HostPlayMode)
|
||||||
|
{
|
||||||
|
if (_hostPlayModeImpl == null)
|
||||||
|
throw new Exception("YooAsset is not initialized.");
|
||||||
|
return _hostPlayModeImpl.UpdateStaticVersionAsync(timeout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 向网络端请求并更新补丁清单
|
/// 向网络端请求并更新补丁清单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -278,7 +311,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static BundleInfo GetBundleInfo(string location)
|
public static BundleInfo GetBundleInfo(string location)
|
||||||
{
|
{
|
||||||
string assetPath = ConvertLocationToAssetPath(location);
|
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
string bundleName = _bundleServices.GetBundleName(assetPath);
|
string bundleName = _bundleServices.GetBundleName(assetPath);
|
||||||
return _bundleServices.GetBundleInfo(bundleName);
|
return _bundleServices.GetBundleInfo(bundleName);
|
||||||
}
|
}
|
||||||
@@ -321,7 +354,7 @@ namespace YooAsset
|
|||||||
/// <param name="priority">优先级</param>
|
/// <param name="priority">优先级</param>
|
||||||
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
|
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
|
||||||
{
|
{
|
||||||
string scenePath = ConvertLocationToAssetPath(location);
|
string scenePath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority);
|
var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@@ -333,7 +366,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static RawFileOperation LoadRawFileAsync(string location, string savePath)
|
public static RawFileOperation LoadRawFileAsync(string location, string savePath)
|
||||||
{
|
{
|
||||||
string assetPath = ConvertLocationToAssetPath(location);
|
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
return AssetSystem.LoadRawFileAsync(assetPath, savePath);
|
return AssetSystem.LoadRawFileAsync(assetPath, savePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +455,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
private static AssetOperationHandle LoadAssetInternal(string location, System.Type assetType, bool waitForAsyncComplete)
|
private static AssetOperationHandle LoadAssetInternal(string location, System.Type assetType, bool waitForAsyncComplete)
|
||||||
{
|
{
|
||||||
string assetPath = ConvertLocationToAssetPath(location);
|
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
var handle = AssetSystem.LoadAssetAsync(assetPath, assetType);
|
var handle = AssetSystem.LoadAssetAsync(assetPath, assetType);
|
||||||
if (waitForAsyncComplete)
|
if (waitForAsyncComplete)
|
||||||
handle.WaitForAsyncComplete();
|
handle.WaitForAsyncComplete();
|
||||||
@@ -430,7 +463,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
private static SubAssetsOperationHandle LoadSubAssetsInternal(string location, System.Type assetType, bool waitForAsyncComplete)
|
private static SubAssetsOperationHandle LoadSubAssetsInternal(string location, System.Type assetType, bool waitForAsyncComplete)
|
||||||
{
|
{
|
||||||
string assetPath = ConvertLocationToAssetPath(location);
|
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
var handle = AssetSystem.LoadSubAssetsAsync(assetPath, assetType);
|
var handle = AssetSystem.LoadSubAssetsAsync(assetPath, assetType);
|
||||||
if (waitForAsyncComplete)
|
if (waitForAsyncComplete)
|
||||||
handle.WaitForAsyncComplete();
|
handle.WaitForAsyncComplete();
|
||||||
@@ -510,7 +543,7 @@ namespace YooAsset
|
|||||||
List<string> assetPaths = new List<string>(locations.Length);
|
List<string> assetPaths = new List<string>(locations.Length);
|
||||||
foreach (var location in locations)
|
foreach (var location in locations)
|
||||||
{
|
{
|
||||||
string assetPath = ConvertLocationToAssetPath(location);
|
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
|
||||||
assetPaths.Add(assetPath);
|
assetPaths.Add(assetPath);
|
||||||
}
|
}
|
||||||
return _hostPlayModeImpl.CreateDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain);
|
return _hostPlayModeImpl.CreateDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain);
|
||||||
@@ -613,22 +646,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 定位地址转换为资源路径
|
|
||||||
/// </summary>
|
|
||||||
private static string ConvertLocationToAssetPath(string location)
|
|
||||||
{
|
|
||||||
if (_playMode == EPlayMode.EditorPlayMode)
|
|
||||||
{
|
|
||||||
string filePath = PathHelper.CombineAssetPath(_locationRoot, location);
|
|
||||||
return PathHelper.FindDatabaseAssetPath(filePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return PathHelper.CombineAssetPath(_locationRoot, location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.tuyoogame.yooasset",
|
"name": "com.tuyoogame.yooasset",
|
||||||
"displayName": "YooAsset",
|
"displayName": "YooAsset",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"unity": "2019.4",
|
"unity": "2019.4",
|
||||||
"description": "unity3d resources management system",
|
"description": "unity3d resources management system",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
@@ -4,23 +4,19 @@
|
|||||||
|
|
||||||
如果是本地测试,可以在本地创建一个WEB服务器,然后将补丁包拷贝到WEB服务器下。
|
如果是本地测试,可以在本地创建一个WEB服务器,然后将补丁包拷贝到WEB服务器下。
|
||||||
|
|
||||||
**按照补丁版本目录部署**
|
|
||||||
|
|
||||||
````
|
|
||||||
CDN
|
|
||||||
└─android
|
|
||||||
├─100
|
|
||||||
├─101
|
|
||||||
└─102
|
|
||||||
````
|
|
||||||
|
|
||||||
**按照游戏版本目录部署**
|
**按照游戏版本目录部署**
|
||||||
|
|
||||||
|
在业务开发过程中,每个游戏版本实际都会创建一个SVN分支,该分支工程内每次构建的补丁包上传到对应的CDN目录下即可。
|
||||||
|
|
||||||
````
|
````
|
||||||
CDN
|
CDN
|
||||||
└─android
|
└─android
|
||||||
├─v1.0
|
├─v1.0
|
||||||
├─v1.1
|
├─v1.1
|
||||||
└─v2.0
|
└─v2.0
|
||||||
|
└─iphone
|
||||||
|
├─v1.0
|
||||||
|
├─v1.1
|
||||||
|
└─v2.0
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ YooAssets.InitializeAsync(CreateParameters parameters);
|
|||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.EditorPlayModeParameters();
|
var createParameters = new YooAssets.EditorPlayModeParameters();
|
||||||
createParameters.LocationRoot = "Assets/GameRes";
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
yield return YooAssets.InitializeAsync(createParameters);
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
@@ -32,7 +32,7 @@ private IEnumerator InitializeYooAsset()
|
|||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.OfflinePlayModeParameters();
|
var createParameters = new YooAssets.OfflinePlayModeParameters();
|
||||||
createParameters.LocationRoot = "Assets/GameRes";
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
yield return YooAssets.InitializeAsync(createParameters);
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
@@ -43,10 +43,12 @@ private IEnumerator InitializeYooAsset()
|
|||||||
|
|
||||||
注意:该模式需要构建资源包
|
注意:该模式需要构建资源包
|
||||||
|
|
||||||
- LocationRoot : 资源定位的根路径,所有通过代码加载的资源文件都需要放在资源定位的根路径下。
|
- LocationServices : 资源定位的实例类。
|
||||||
|
1. 默认的资源定位服务类(DefaultLocationServices)
|
||||||
|
2. 可寻址的资源定位服务类(AdressLocationServices)
|
||||||
|
3. 开发者自定义的资源定位服务类,需要提供实现ILocationServices接口的实例类。
|
||||||
- DecryptionServices : 如果资源包在构建的时候有加密,需要提供实现IDecryptionServices接口的实例类。
|
- DecryptionServices : 如果资源包在构建的时候有加密,需要提供实现IDecryptionServices接口的实例类。
|
||||||
- ClearCacheWhenDirty : 安装包在覆盖安装的时候,是否清空沙盒缓存文件夹。
|
- ClearCacheWhenDirty : 安装包在覆盖安装的时候,是否清空沙盒缓存文件夹。
|
||||||
- IgnoreResourceVersion : 是否忽略资源版本号,请参考进阶教程。
|
|
||||||
- DefaultHostServer : 默认的资源服务器IP地址。
|
- DefaultHostServer : 默认的资源服务器IP地址。
|
||||||
- FallbackHostServer : 备用的资源服务器IP地址。
|
- FallbackHostServer : 备用的资源服务器IP地址。
|
||||||
|
|
||||||
@@ -54,10 +56,9 @@ private IEnumerator InitializeYooAsset()
|
|||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.HostPlayModeParameters();
|
var createParameters = new YooAssets.HostPlayModeParameters();
|
||||||
createParameters.LocationRoot = "Assets/GameRes";
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
createParameters.DecryptionServices = null;
|
createParameters.DecryptionServices = null;
|
||||||
createParameters.ClearCacheWhenDirty = false;
|
createParameters.ClearCacheWhenDirty = false;
|
||||||
createParameters.IgnoreResourceVersion = false;
|
|
||||||
createParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android";
|
createParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android";
|
||||||
createParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android";
|
createParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android";
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
yield return YooAssets.InitializeAsync(createParameters);
|
||||||
|
|||||||
@@ -1,18 +1,39 @@
|
|||||||
# 资源更新
|
# 资源更新
|
||||||
|
|
||||||
|
**获取资源版本**
|
||||||
|
|
||||||
|
对于联机运行模式,在更新补丁清单之前,需要获取一个资源版本号。
|
||||||
|
|
||||||
|
该资源版本号,可以通过YooAssets提供的接口来更新,也可以通过HTTP访问游戏服务器来获取。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
private IEnumerator UpdateStaticVersion()
|
||||||
|
{
|
||||||
|
UpdateStaticVersionOperation operation = YooAssets.UpdateStaticVersionAsync();
|
||||||
|
yield return operation;
|
||||||
|
|
||||||
|
if (operation.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
//更新成功
|
||||||
|
int resourceVersion = operation.ResourceVersion;
|
||||||
|
Debug.Log($"Update resource Version : {resourceVersion}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//更新失败
|
||||||
|
Debug.LogError(operation.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
**更新补丁清单**
|
**更新补丁清单**
|
||||||
|
|
||||||
对于联机运行模式,在初始化资源系统之后,需要立刻更新资源清单。
|
对于联机运行模式,在获取到资源版本号之后,就可以更新资源清单了。
|
||||||
|
|
||||||
**注意**:在初始化资源系统的时候,可以选择是否忽略资源版本号,这会影响到我们的更新步骤。
|
|
||||||
|
|
||||||
- 没有忽略资源版本号:在更新之前先获取更新的资源版本号,一般通过HTTP访问游戏服务器来获取。
|
|
||||||
- 忽略资源版本号:在更新的时候,资源版本号可以设置为0。
|
|
||||||
|
|
||||||
````c#
|
````c#
|
||||||
private IEnumerator UpdatePatchManifest()
|
private IEnumerator UpdatePatchManifest()
|
||||||
{
|
{
|
||||||
UpdateManifestOperation operation = YooAssets.UpdateManifestAsync(updateResourceVersion);
|
UpdateManifestOperation operation = YooAssets.UpdateManifestAsync(resourceVersion);
|
||||||
yield return operation;
|
yield return operation;
|
||||||
|
|
||||||
if (operation.Status == EOperationStatus.Succeed)
|
if (operation.Status == EOperationStatus.Succeed)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# 资源加载
|
# 资源加载
|
||||||
|
|
||||||
在加载资源对象的时候只需要提供相对路径,统一约定该相对路径名称为:location
|
|
||||||
|
|
||||||
加载接口:
|
加载接口:
|
||||||
|
|
||||||
- YooAssets.LoadAssetSync() 同步加载资源对象接口
|
- YooAssets.LoadAssetSync() 同步加载资源对象接口
|
||||||
@@ -11,6 +9,8 @@
|
|||||||
- YooAssets.LoadSceneAsync() 异步加载场景接口
|
- YooAssets.LoadSceneAsync() 异步加载场景接口
|
||||||
- YooAssets.LoadRawFileAsync() 异步读取原生文件接口
|
- YooAssets.LoadRawFileAsync() 异步读取原生文件接口
|
||||||
|
|
||||||
|
统一约定:location为资源的定位地址,也是加载资源对象的唯一标识符。
|
||||||
|
|
||||||
**加载路径的匹配方式**
|
**加载路径的匹配方式**
|
||||||
|
|
||||||
````C#
|
````C#
|
||||||
|
|||||||
12
Docs/Contributor.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 感谢所有支持YooAsset的小伙伴们!
|
||||||
|
|
||||||
|
**特别感谢以下QQ社区的小伙伴**
|
||||||
|
|
||||||
|
他们帮忙协助解决了很多BUG以及提出了很多宝贵的意见!
|
||||||
|
|
||||||
|
- 黄色幻想
|
||||||
|
|
||||||
|
- 新乞丐王子
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 180 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 147 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 27 KiB |
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
- **Asset Bundle File Variant** : AssetBundle资源包后缀名
|
- **Asset Bundle File Variant** : AssetBundle资源包后缀名
|
||||||
- **Raw File Variant** : 原生资源包后缀名
|
- **Raw File Variant** : 原生资源包后缀名
|
||||||
- **Patch Manifest File Name** : 补丁清单文件名
|
- **Patch Manifest File Name** : 补丁清单文件名称
|
||||||
- **Patch Manifest Hash File Name** : 补丁清单哈希文件名
|
|
||||||
- **Unity Manifest File Name** : Unity构建的清单名称
|
- **Unity Manifest File Name** : Unity构建的清单名称
|
||||||
|
|
||||||
|
|||||||
16
README.md
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
它可以满足商业化游戏的各类需求,并且经历多款百万DAU游戏产品的验证。
|
它可以满足商业化游戏的各类需求,并且经历多款百万DAU游戏产品的验证。
|
||||||
|
|
||||||
### 系统特点
|
## 系统特点
|
||||||
- **安全高效的分包方案**
|
- **安全高效的分包方案**
|
||||||
|
|
||||||
基于资源对象的标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
|
基于资源对象的标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
|
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
|
||||||
|
|
||||||
### 入门教程
|
## 入门教程
|
||||||
1. [快速开始](https://github.com/tuyoogame/YooAsset/blob/master/Docs/QuickStart.md)
|
1. [快速开始](https://github.com/tuyoogame/YooAsset/blob/master/Docs/QuickStart.md)
|
||||||
2. [全局配置](https://github.com/tuyoogame/YooAsset/blob/master/Docs/Settings.md)
|
2. [全局配置](https://github.com/tuyoogame/YooAsset/blob/master/Docs/Settings.md)
|
||||||
3. [资源配置](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetGrouper.md)
|
3. [资源配置](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetGrouper.md)
|
||||||
@@ -50,21 +50,21 @@
|
|||||||
5. [构建报告](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetReporter.md)
|
5. [构建报告](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetReporter.md)
|
||||||
5. [调试器](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDebugger.md)
|
5. [调试器](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDebugger.md)
|
||||||
|
|
||||||
### 代码教程
|
## 代码教程
|
||||||
1. [初始化](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial1.md)
|
1. [初始化](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial1.md)
|
||||||
2. [资源更新](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial2.md)
|
2. [资源更新](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial2.md)
|
||||||
3. [资源加载](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial3.md)
|
3. [资源加载](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial3.md)
|
||||||
|
|
||||||
### 视频教程
|
## 视频教程
|
||||||
|
|
||||||
Coming soon...
|
Coming soon...
|
||||||
|
|
||||||
### 社区
|
## 社区
|
||||||
|
|
||||||
**QQ群:963240451**
|
QQ群:963240451
|
||||||
|
|
||||||
|
[致谢名单](https://github.com/tuyoogame/YooAsset/blob/master/Docs/Contributor.md)👯
|
||||||
|
|
||||||
|
## 友情链接
|
||||||
### 友情链接
|
|
||||||
|
|
||||||
[huatuo](https://github.com/focus-creative-games/huatuo):华佗是一个**特性完整、零成本、高性能、低内存**的近乎完美的c#热更新方案。
|
[huatuo](https://github.com/focus-creative-games/huatuo):华佗是一个**特性完整、零成本、高性能、低内存**的近乎完美的c#热更新方案。
|
||||||
|
|||||||