Compare commits

...

23 Commits

Author SHA1 Message Date
hevinci
5197d42807 Update CHANGELOG.md 2022-12-04 20:27:27 +08:00
hevinci
7a0f4caa9b Update package.json 2022-12-04 20:27:13 +08:00
hevinci
5bf1d29edc update utility 2022-12-04 20:14:02 +08:00
hevinci
2687466ed4 Update editor file 2022-12-03 23:16:39 +08:00
hevinci
14512d6470 Update samples 2022-12-03 23:16:16 +08:00
hevinci
32268f5a4a Update editor logic
资源收集界面规则选项显示别名
2022-12-03 23:16:04 +08:00
何冠峰
81401ca0b8 Merge pull request #53 from ZensYue/main
[add]Add ShowEditorAlias 添加显示编辑器名字
2022-12-03 20:12:31 +08:00
hevinci
688cc271d5 Update runtime logic
UpdatePackageVersionAsync()方法增加appendTimeTicks参数
2022-12-03 20:03:10 +08:00
hevinci
a290353cfa Update runtime logic
在初始化失败的时候,销毁YooAssets会报异常。
2022-12-03 19:48:17 +08:00
hevinci
6038e7acd6 Update asset system 2022-12-03 19:13:11 +08:00
何冠峰
4abec5a389 Merge pull request #52 from gaozhou/main
为handle 添加 using 支持
2022-12-03 19:00:44 +08:00
hevinci
a2b51a8044 Update samples 2022-12-03 18:49:05 +08:00
hevinci
19cb239746 Update logic code
优化补丁清单格式为二进制。
2022-12-03 18:48:51 +08:00
hevinci
7aab610be5 Add binary buffer class 2022-12-03 18:42:28 +08:00
hevinci
4ec5a126ac Remove BitMask files 2022-12-03 18:07:52 +08:00
zensyue
32643caf51 Merge pull request #1 from ZensYue/dev
Dev
2022-12-02 20:46:13 +08:00
ZensYue
114ebab6ae [bugfix]Convert the show name to the type name 把显示名字转换成类型名字 2022-12-02 20:39:28 +08:00
gaozhou
d1463e1fc6 为handle 添加 using 支持 2022-12-02 14:23:58 +08:00
ZensYue
aa49980231 [add]Add ShowEditorAlias 添加显示编辑器名字 2022-12-02 12:31:15 +08:00
hevinci
2696da092d update samples 2022-11-29 11:07:38 +08:00
hevinci
5415d95f36 Fix #46
修复资源包初始化失败之后,再次初始化提示异常的问题。
2022-11-29 11:06:24 +08:00
hevinci
efa71c8bb7 Update FAQ.md 2022-11-28 22:24:36 +08:00
hevinci
d59df4c561 update document 2022-11-27 15:40:09 +08:00
64 changed files with 1094 additions and 446 deletions

View File

@@ -2,6 +2,19 @@
All notable changes to this package will be documented in this file.
## [1.4.0-preview] - 2022-12-04
### Fixed
- (#46)修复了资源包初始化失败之后,再次初始化发生异常的问题。
- 修复了在初始化失败的之后销毁YooAssets会报异常的问题。
### Changed
- 优化了资源收集界面,可以选择显示中文别名。
- **优化了补丁清单序列化方式,由文本数据修改为二进制数据。**
- 资源操作句柄增加using支持。
## [1.3.7] - 2022-11-26
全新的太空战机Demo !

View File

@@ -23,7 +23,7 @@ namespace YooAsset.Editor
var buildResult = builder.Run(buildParameters);
if (buildResult.Success)
{
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string manifestFileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
return manifestFilePath;
}

View File

@@ -182,13 +182,14 @@ namespace YooAsset.Editor
/// </summary>
internal PatchBundle CreatePatchBundle()
{
string fileHash = PatchInfo.PatchFileHash;
string fileCRC = PatchInfo.PatchFileCRC;
long fileSize = PatchInfo.PatchFileSize;
bool isRawFile = IsRawFile;
byte loadMethod = (byte)LoadMethod;
string[] tags = GetBundleTags();
PatchBundle patchBundle = new PatchBundle(BundleName, fileHash, fileCRC, fileSize, isRawFile, loadMethod, tags);
PatchBundle patchBundle = new PatchBundle();
patchBundle.BundleName = BundleName;
patchBundle.FileHash = PatchInfo.PatchFileHash;
patchBundle.FileCRC = PatchInfo.PatchFileCRC;
patchBundle.FileSize = PatchInfo.PatchFileSize;
patchBundle.IsRawFile = IsRawFile;
patchBundle.LoadMethod = (byte)LoadMethod;
patchBundle.Tags = GetBundleTags();
return patchBundle;
}
}

View File

@@ -45,7 +45,7 @@ namespace YooAsset.Editor
// 拷贝补丁清单文件
{
string fileName = YooAssetSettingsData.GetPatchManifestFileName(buildPackageName, buildPackageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildPackageName, buildPackageVersion);
string sourcePath = $"{packageOutputDirectory}/{fileName}";
string destPath = $"{streamingAssetsDirectory}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true);

View File

@@ -51,18 +51,26 @@ namespace YooAsset.Editor
}
}
// 创建补丁清单文件
// 创建补丁清单文本文
{
string fileName = YooAssetSettingsData.GetPatchManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}";
PatchManifest.SerializeToJson(filePath, patchManifest);
BuildRunner.Log($"创建补丁清单文件:{filePath}");
}
// 创建补丁清单二进制文件
string packageHash;
{
string fileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}";
PatchManifest.Serialize(filePath, patchManifest);
PatchManifest.SerializeToBinary(filePath, patchManifest);
packageHash = HashUtility.FileMD5(filePath);
BuildRunner.Log($"创建补丁清单文件:{filePath}");
var patchManifestContext = new PatchManifestContext();
string jsonData = FileUtility.ReadFile(filePath);
patchManifestContext.Manifest = PatchManifest.Deserialize(jsonData);
PatchManifestContext patchManifestContext = new PatchManifestContext();
byte[] bytesData = FileUtility.ReadAllBytes(filePath);
patchManifestContext.Manifest = PatchManifest.DeserializeFromBinary(bytesData);
context.SetContextObject(patchManifestContext);
}

View File

@@ -10,13 +10,14 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorConfig
{
public const string ConfigVersion = "2.1";
public const string ConfigVersion = "2.2";
public const string XmlVersion = "Version";
public const string XmlCommon = "Common";
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlUniqueBundleName = "UniqueBundleName";
public const string XmlShowPackageView = "ShowPackageView";
public const string XmlShowEditorAlias = "ShowEditorAlias";
public const string XmlPackage = "Package";
public const string XmlPackageName = "PackageName";
@@ -65,6 +66,7 @@ namespace YooAsset.Editor
bool enableAddressable = false;
bool uniqueBundleName = false;
bool showPackageView = false;
bool showEditorAlias = false;
var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (commonNodeList.Count > 0)
{
@@ -75,10 +77,13 @@ namespace YooAsset.Editor
throw new Exception($"Not found attribute {XmlUniqueBundleName} in {XmlCommon}");
if (commonElement.HasAttribute(XmlShowPackageView) == false)
throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}");
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
throw new Exception($"Not found attribute {XmlShowEditorAlias} in {XmlCommon}");
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
}
// 读取包裹配置
@@ -153,6 +158,7 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
AssetBundleCollectorSettingData.SaveFile();
Debug.Log($"导入配置完毕!");
@@ -183,6 +189,7 @@ namespace YooAsset.Editor
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
root.AppendChild(commonElement);
// 设置Package配置
@@ -296,6 +303,23 @@ namespace YooAsset.Editor
return UpdateXmlConfig(xmlDoc);
}
// 2.1 -> 2.2
if (configVersion == "2.1")
{
// 添加公共元素属性
var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (commonNodeList.Count > 0)
{
XmlElement commonElement = commonNodeList[0] as XmlElement;
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
commonElement.SetAttribute(XmlShowEditorAlias, "False");
}
// 更新版本
root.SetAttribute(XmlVersion, "2.2");
return UpdateXmlConfig(xmlDoc);
}
return false;
}
}

View File

@@ -23,6 +23,12 @@ namespace YooAsset.Editor
/// </summary>
public bool UniqueBundleName = false;
/// <summary>
/// 是否显示编辑器别名
/// </summary>
public bool ShowEditorAlias = false;
/// <summary>
/// 包裹列表
/// </summary>

View File

@@ -38,92 +38,6 @@ namespace YooAsset.Editor
}
}
public static List<string> GetActiveRuleNames()
{
if (_setting == null)
LoadSettingData();
List<string> names = new List<string>();
foreach (var pair in _cacheActiveRuleTypes)
{
names.Add(pair.Key);
}
return names;
}
public static List<string> GetAddressRuleNames()
{
if (_setting == null)
LoadSettingData();
List<string> names = new List<string>();
foreach (var pair in _cacheAddressRuleTypes)
{
names.Add(pair.Key);
}
return names;
}
public static List<string> GetPackRuleNames()
{
if (_setting == null)
LoadSettingData();
List<string> names = new List<string>();
foreach (var pair in _cachePackRuleTypes)
{
names.Add(pair.Key);
}
return names;
}
public static List<string> GetFilterRuleNames()
{
if (_setting == null)
LoadSettingData();
List<string> names = new List<string>();
foreach (var pair in _cacheFilterRuleTypes)
{
names.Add(pair.Key);
}
return names;
}
public static bool HasActiveRuleName(string ruleName)
{
foreach (var pair in _cacheActiveRuleTypes)
{
if (pair.Key == ruleName)
return true;
}
return false;
}
public static bool HasAddressRuleName(string ruleName)
{
foreach (var pair in _cacheAddressRuleTypes)
{
if (pair.Key == ruleName)
return true;
}
return false;
}
public static bool HasPackRuleName(string ruleName)
{
foreach (var pair in _cachePackRuleTypes)
{
if (pair.Key == ruleName)
return true;
}
return false;
}
public static bool HasFilterRuleName(string ruleName)
{
foreach (var pair in _cacheFilterRuleTypes)
{
if (pair.Key == ruleName)
return true;
}
return false;
}
/// <summary>
/// 加载配置文件
/// </summary>
@@ -146,6 +60,7 @@ namespace YooAsset.Editor
typeof(PackCollector),
typeof(PackGroup),
typeof(PackRawFile),
typeof(PackShaderVariants)
};
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
@@ -266,7 +181,92 @@ namespace YooAsset.Editor
SaveFile();
}
// 实例类相关
public static List<RuleDisplayName> GetActiveRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheActiveRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetAddressRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheAddressRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetPackRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cachePackRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetFilterRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheFilterRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
private static string GetRuleDisplayName(string name, Type type)
{
var attribute = EditorAttribute.GetAttribute<DisplayNameAttribute>(type);
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
return attribute.DisplayName;
else
return name;
}
public static bool HasActiveRuleName(string ruleName)
{
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
}
public static bool HasAddressRuleName(string ruleName)
{
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
}
public static bool HasPackRuleName(string ruleName)
{
return _cachePackRuleTypes.Keys.Contains(ruleName);
}
public static bool HasFilterRuleName(string ruleName)
{
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
}
public static IActiveRule GetActiveRuleInstance(string ruleName)
{
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
@@ -352,6 +352,11 @@ namespace YooAsset.Editor
Setting.UniqueBundleName = uniqueBundleName;
IsDirty = true;
}
public static void ModifyShowEditorAlias(bool showAlias)
{
Setting.ShowEditorAlias = showAlias;
IsDirty = true;
}
// 资源包裹编辑相关
public static AssetBundleCollectorPackage CreatePackage(string packageName)

View File

@@ -20,14 +20,15 @@ namespace YooAsset.Editor
private Button _saveButton;
private List<string> _collectorTypeList;
private List<string> _activeRuleList;
private List<string> _addressRuleList;
private List<string> _packRuleList;
private List<string> _filterRuleList;
private List<RuleDisplayName> _activeRuleList;
private List<RuleDisplayName> _addressRuleList;
private List<RuleDisplayName> _packRuleList;
private List<RuleDisplayName> _filterRuleList;
private Toggle _showPackageToogle;
private Toggle _enableAddressableToogle;
private Toggle _uniqueBundleNameToogle;
private Toggle _showEditorAliasToggle;
private VisualElement _packageContainer;
private ListView _packageListView;
@@ -42,7 +43,7 @@ namespace YooAsset.Editor
private VisualElement _collectorContainer;
private ScrollView _collectorScrollView;
private PopupField<string> _activeRulePopupField;
private PopupField<RuleDisplayName> _activeRulePopupField;
private int _lastModifyPackageIndex = 0;
private int _lastModifyGroupIndex = 0;
@@ -95,6 +96,13 @@ namespace YooAsset.Editor
RefreshWindow();
});
_showEditorAliasToggle = root.Q<Toggle>("ShowEditorAlias");
_showEditorAliasToggle.RegisterValueChangedCallback(evt =>
{
AssetBundleCollectorSettingData.ModifyShowEditorAlias(evt.newValue);
RefreshWindow();
});
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
fixBtn.clicked += FixBtn_clicked;
@@ -236,21 +244,23 @@ namespace YooAsset.Editor
// 分组激活规则
var activeRuleContainer = root.Q("ActiveRuleContainer");
{
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
_activeRulePopupField = new PopupField<RuleDisplayName>("Active Rule", _activeRuleList, 0);
_activeRulePopupField.name = "ActiveRuleMaskField";
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
activeRuleContainer.Add(_activeRulePopupField);
_activeRulePopupField.formatListItemCallback = FormatListItemCallback;
_activeRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
_activeRulePopupField.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectPackage != null && selectGroup != null)
{
selectGroup.ActiveRuleName = evt.newValue;
selectGroup.ActiveRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
FillGroupViewData();
}
});
activeRuleContainer.Add(_activeRulePopupField);
}
// 刷新窗体
@@ -290,6 +300,9 @@ namespace YooAsset.Editor
{
_showPackageToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowPackageView);
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
_groupContainer.visible = false;
_collectorContainer.visible = false;
@@ -321,6 +334,20 @@ namespace YooAsset.Editor
{
AssetBundleCollectorSettingData.SaveFile();
}
private string FormatListItemCallback(RuleDisplayName ruleDisplayName)
{
if (_showEditorAliasToggle.value)
return ruleDisplayName.DisplayName;
else
return ruleDisplayName.ClassName;
}
private string FormatSelectedValueCallback(RuleDisplayName ruleDisplayName)
{
if (_showEditorAliasToggle.value)
return ruleDisplayName.DisplayName;
else
return ruleDisplayName.ClassName;
}
// 包裹列表相关
private void FillPackageViewData()
@@ -334,7 +361,7 @@ namespace YooAsset.Editor
{
_packageListView.selectedIndex = _lastModifyPackageIndex;
}
if (_showPackageToogle.value)
_packageContainer.style.display = DisplayStyle.Flex;
else
@@ -410,7 +437,7 @@ namespace YooAsset.Editor
_groupListView.itemsSource = selectPackage.Groups;
_groupListView.Rebuild();
if(_lastModifyGroupIndex >=0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
if (_lastModifyGroupIndex >= 0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
{
_groupListView.selectedIndex = _lastModifyGroupIndex;
}
@@ -460,7 +487,7 @@ namespace YooAsset.Editor
_collectorContainer.visible = true;
_lastModifyGroupIndex = _groupListView.selectedIndex;
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
_activeRulePopupField.SetValueWithoutNotify(GetActiveRuleIndex(selectGroup.ActiveRuleName));
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
@@ -564,21 +591,21 @@ namespace YooAsset.Editor
}
if (_enableAddressableToogle.value)
{
var popupField = new PopupField<string>(_addressRuleList, 0);
var popupField = new PopupField<RuleDisplayName>(_addressRuleList, 0);
popupField.name = "PopupField1";
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
popupField.style.width = 200;
elementBottom.Add(popupField);
}
{
var popupField = new PopupField<string>(_packRuleList, 0);
var popupField = new PopupField<RuleDisplayName>(_packRuleList, 0);
popupField.name = "PopupField2";
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
popupField.style.width = 150;
popupField.style.width = 230;
elementBottom.Add(popupField);
}
{
var popupField = new PopupField<string>(_filterRuleList, 0);
var popupField = new PopupField<RuleDisplayName>(_filterRuleList, 0);
popupField.name = "PopupField3";
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
popupField.style.width = 150;
@@ -676,13 +703,15 @@ namespace YooAsset.Editor
});
// Address Rule
var popupField1 = element.Q<PopupField<string>>("PopupField1");
var popupField1 = element.Q<PopupField<RuleDisplayName>>("PopupField1");
if (popupField1 != null)
{
popupField1.index = GetAddressRuleIndex(collector.AddressRuleName);
popupField1.formatListItemCallback = FormatListItemCallback;
popupField1.formatSelectedValueCallback = FormatSelectedValueCallback;
popupField1.RegisterValueChangedCallback(evt =>
{
collector.AddressRuleName = evt.newValue;
collector.AddressRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value)
{
@@ -692,11 +721,13 @@ namespace YooAsset.Editor
}
// Pack Rule
var popupField2 = element.Q<PopupField<string>>("PopupField2");
var popupField2 = element.Q<PopupField<RuleDisplayName>>("PopupField2");
popupField2.index = GetPackRuleIndex(collector.PackRuleName);
popupField2.formatListItemCallback = FormatListItemCallback;
popupField2.formatSelectedValueCallback = FormatSelectedValueCallback;
popupField2.RegisterValueChangedCallback(evt =>
{
collector.PackRuleName = evt.newValue;
collector.PackRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value)
{
@@ -705,11 +736,13 @@ namespace YooAsset.Editor
});
// Filter Rule
var popupField3 = element.Q<PopupField<string>>("PopupField3");
var popupField3 = element.Q<PopupField<RuleDisplayName>>("PopupField3");
popupField3.index = GetFilterRuleIndex(collector.FilterRuleName);
popupField3.formatListItemCallback = FormatListItemCallback;
popupField3.formatSelectedValueCallback = FormatSelectedValueCallback;
popupField3.RegisterValueChangedCallback(evt =>
{
collector.FilterRuleName = evt.newValue;
collector.FilterRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value)
{
@@ -815,7 +848,7 @@ namespace YooAsset.Editor
{
for (int i = 0; i < _addressRuleList.Count; i++)
{
if (_addressRuleList[i] == ruleName)
if (_addressRuleList[i].ClassName == ruleName)
return i;
}
return 0;
@@ -824,7 +857,7 @@ namespace YooAsset.Editor
{
for (int i = 0; i < _packRuleList.Count; i++)
{
if (_packRuleList[i] == ruleName)
if (_packRuleList[i].ClassName == ruleName)
return i;
}
return 0;
@@ -833,11 +866,20 @@ namespace YooAsset.Editor
{
for (int i = 0; i < _filterRuleList.Count; i++)
{
if (_filterRuleList[i] == ruleName)
if (_filterRuleList[i].ClassName == ruleName)
return i;
}
return 0;
}
private RuleDisplayName GetActiveRuleIndex(string ruleName)
{
for (int i = 0; i < _activeRuleList.Count; i++)
{
if (_activeRuleList[i].ClassName == ruleName)
return _activeRuleList[i];
}
return _activeRuleList[0];
}
}
}
#endif

View File

@@ -1,4 +1,4 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
@@ -7,6 +7,7 @@
</uie:Toolbar>
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Show Editor Alias" name="ShowEditorAlias" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement>

View File

@@ -1,9 +1,7 @@

namespace YooAsset.Editor
{
/// <summary>
/// 启用分组
/// </summary>
[DisplayName("启用分组")]
public class EnableGroup : IActiveRule
{
public bool IsActiveGroup()
@@ -12,9 +10,7 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 禁用分组
/// </summary>
[DisplayName("禁用分组")]
public class DisableGroup : IActiveRule
{
public bool IsActiveGroup()

View File

@@ -2,9 +2,7 @@
namespace YooAsset.Editor
{
/// <summary>
/// 以文件名为定位地址
/// </summary>
[DisplayName("以文件名称为定位地址")]
public class AddressByFileName : IAddressRule
{
string IAddressRule.GetAssetAddress(AddressRuleData data)
@@ -13,9 +11,7 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 以组名+文件名为定位地址
/// </summary>
[DisplayName("以分组名称+文件名称为定位地址")]
public class AddressByGroupAndFileName : IAddressRule
{
string IAddressRule.GetAssetAddress(AddressRuleData data)
@@ -25,9 +21,7 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 以收集器名+文件名为定位地址
/// </summary>
[DisplayName("以收集器名称+文件名称为定位地址")]
public class AddressByCollectorAndFileName : IAddressRule
{
string IAddressRule.GetAssetAddress(AddressRuleData data)

View File

@@ -4,9 +4,7 @@ using System.IO;
namespace YooAsset.Editor
{
/// <summary>
/// 收集所有资源
/// </summary>
[DisplayName("收集所有资源")]
public class CollectAll : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
@@ -15,9 +13,7 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 只收集场景
/// </summary>
[DisplayName("收集场景")]
public class CollectScene : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
@@ -25,10 +21,8 @@ namespace YooAsset.Editor
return Path.GetExtension(data.AssetPath) == ".unity";
}
}
/// <summary>
/// 只收集预制体
/// </summary>
[DisplayName("收集预制体")]
public class CollectPrefab : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
@@ -37,15 +31,13 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 只收集精灵类型的资源
/// </summary>
[DisplayName("收集精灵类型的纹理")]
public class CollectSprite : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
{
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
if(mainAssetType == typeof(Texture2D))
if (mainAssetType == typeof(Texture2D))
{
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
@@ -60,9 +52,7 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 只收集着色器变种收集文件
/// </summary>
[DisplayName("收集着色器变种集合")]
public class CollectShaderVariants : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)

View File

@@ -10,6 +10,7 @@ namespace YooAsset.Editor
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
/// </summary>
[DisplayName("以文件路径作为资源包名")]
public class PackSeparately : IPackRule
{
string IPackRule.GetBundleName(PackRuleData data)
@@ -25,6 +26,7 @@ namespace YooAsset.Editor
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
/// </summary>
[DisplayName("以父类文件夹路径作为资源包名")]
public class PackDirectory : IPackRule
{
public static PackDirectory StaticPackRule = new PackDirectory();
@@ -43,6 +45,7 @@ namespace YooAsset.Editor
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
/// </summary>
[DisplayName("以收集器路径下顶级文件夹为资源包名")]
public class PackTopDirectory : IPackRule
{
string IPackRule.GetBundleName(PackRuleData data)
@@ -68,6 +71,7 @@ namespace YooAsset.Editor
/// 以收集器路径作为资源包名
/// 注意:收集的所有文件打进一个资源包
/// </summary>
[DisplayName("以收集器路径作为资源包名")]
public class PackCollector : IPackRule
{
string IPackRule.GetBundleName(PackRuleData data)
@@ -90,6 +94,7 @@ namespace YooAsset.Editor
/// 以分组名称作为资源包名
/// 注意:收集的所有文件打进一个资源包
/// </summary>
[DisplayName("以分组名称作为资源包名")]
public class PackGroup : IPackRule
{
string IPackRule.GetBundleName(PackRuleData data)
@@ -99,9 +104,10 @@ namespace YooAsset.Editor
}
/// <summary>
/// 原生文件打包模式
/// 打包原生文件
/// 注意:原生文件打包支持:图片,音频,视频,文本
/// </summary>
[DisplayName("打包原生文件")]
public class PackRawFile : IPackRule
{
string IPackRule.GetBundleName(PackRuleData data)
@@ -126,8 +132,9 @@ namespace YooAsset.Editor
}
/// <summary>
/// 着色器变种收集文件
/// 打包着色器变种集合
/// </summary>
[DisplayName("打包着色器变种集合")]
public class PackShaderVariants : IPackRule
{
public string GetBundleName(PackRuleData data)

View File

@@ -0,0 +1,9 @@

namespace YooAsset.Editor
{
public class RuleDisplayName
{
public string ClassName;
public string DisplayName;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 60c7594328ef976408edadfdf2b9aa3d
guid: df712711c3830af419b7ada8fee53dda
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -109,7 +109,7 @@ namespace YooAsset.Editor
return;
_reportFilePath = selectFilePath;
string jsonData = FileUtility.ReadFile(_reportFilePath);
string jsonData = FileUtility.ReadAllText(_reportFilePath);
_buildReport = BuildReport.Deserialize(jsonData);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);

View File

@@ -0,0 +1,36 @@
using System;
using System.Reflection;
namespace YooAsset.Editor
{
/// <summary>
/// 编辑器显示名字
/// </summary>
public class DisplayNameAttribute : Attribute
{
public string DisplayName;
public DisplayNameAttribute(string name)
{
this.DisplayName = name;
}
}
public static class EditorAttribute
{
internal static T GetAttribute<T>(Type type) where T : Attribute
{
return (T)type.GetCustomAttribute(typeof(T), false);
}
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
{
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
}
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
{
return (T)field.GetCustomAttribute(typeof(T), false);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 6b03684bc5163694ab3983243512b4cc
guid: 92d5f73b21059af43b7f56165b7acd63
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -73,15 +73,15 @@ namespace YooAsset
{
provider.Destroy();
}
_providers.Clear();
foreach (var loader in _loaders)
{
loader.Destroy(true);
}
_providers.Clear();
_loaders.Clear();
ClearSceneHandle();
ClearSceneHandle();
DecryptionServices = null;
BundleServices = null;
}
@@ -298,19 +298,21 @@ namespace YooAsset
internal void ClearSceneHandle()
{
// 释放资源包下的所有场景
string packageName = BundleServices.GetPackageName();
List<string> removeList = new List<string>();
foreach (var valuePair in _sceneHandles)
if (BundleServices.IsServicesValid())
{
if (valuePair.Value.PackageName == packageName)
string packageName = BundleServices.GetPackageName();
List<string> removeList = new List<string>();
foreach (var valuePair in _sceneHandles)
{
removeList.Add(valuePair.Key);
if (valuePair.Value.PackageName == packageName)
{
removeList.Add(valuePair.Key);
}
}
foreach (var key in removeList)
{
_sceneHandles.Remove(key);
}
}
foreach (var key in removeList)
{
_sceneHandles.Remove(key);
}
}

View File

@@ -1,9 +1,10 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
public sealed class AssetOperationHandle : OperationHandleBase
public sealed class AssetOperationHandle : OperationHandleBase, IDisposable
{
private System.Action<AssetOperationHandle> _callback;
@@ -37,6 +38,33 @@ namespace YooAsset
}
}
/// <summary>
/// 等待异步执行完毕
/// </summary>
public void WaitForAsyncComplete()
{
if (IsValidWithWarning == false)
return;
Provider.WaitForAsyncComplete();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Release()
{
this.ReleaseInternal();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Dispose()
{
this.ReleaseInternal();
}
/// <summary>
/// 资源对象
/// </summary>
@@ -61,25 +89,6 @@ namespace YooAsset
return Provider.AssetObject as TAsset;
}
/// <summary>
/// 等待异步执行完毕
/// </summary>
public void WaitForAsyncComplete()
{
if (IsValidWithWarning == false)
return;
Provider.WaitForAsyncComplete();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Release()
{
this.ReleaseInternal();
}
/// <summary>
/// 同步初始化游戏对象
/// </summary>

View File

@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
namespace YooAsset
{
@@ -14,7 +15,6 @@ namespace YooAsset
}
internal abstract void InvokeCallback();
/// <summary>
/// 获取资源信息
/// </summary>

View File

@@ -1,9 +1,10 @@
using System.IO;
using System;
using System.IO;
using System.Text;
namespace YooAsset
{
public class RawFileOperationHandle : OperationHandleBase
public class RawFileOperationHandle : OperationHandleBase, IDisposable
{
private System.Action<RawFileOperationHandle> _callback;
@@ -54,7 +55,15 @@ namespace YooAsset
{
this.ReleaseInternal();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Dispose()
{
this.ReleaseInternal();
}
/// <summary>
/// 获取原生文件的二进制数据

View File

@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace YooAsset
{
public sealed class SubAssetsOperationHandle : OperationHandleBase
public sealed class SubAssetsOperationHandle : OperationHandleBase, IDisposable
{
private System.Action<SubAssetsOperationHandle> _callback;
@@ -36,19 +37,6 @@ namespace YooAsset
}
}
/// <summary>
/// 子资源对象集合
/// </summary>
public UnityEngine.Object[] AllAssetObjects
{
get
{
if (IsValidWithWarning == false)
return null;
return Provider.AllAssetObjects;
}
}
/// <summary>
/// 等待异步执行完毕
/// </summary>
@@ -67,6 +55,27 @@ namespace YooAsset
this.ReleaseInternal();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Dispose()
{
this.ReleaseInternal();
}
/// <summary>
/// 子资源对象集合
/// </summary>
public UnityEngine.Object[] AllAssetObjects
{
get
{
if (IsValidWithWarning == false)
return null;
return Provider.AllAssetObjects;
}
}
/// <summary>
/// 获取子资源对象

View File

@@ -78,6 +78,9 @@ namespace YooAsset
/// </summary>
public InitializationOperation InitializeAsync(InitializeParameters parameters)
{
// 注意WebGL平台因为网络原因可能会初始化失败
ResetInitializeAfterFailed();
// 检测初始化参数合法性
CheckInitializeParameters(parameters);
@@ -127,6 +130,20 @@ namespace YooAsset
initializeOperation.Completed += InitializeOperation_Completed;
return initializeOperation;
}
private void ResetInitializeAfterFailed()
{
if (_isInitialize && _initializeStatus == EOperationStatus.Failed)
{
_isInitialize = false;
_initializeStatus = EOperationStatus.None;
_initializeError = string.Empty;
_bundleServices = null;
_assetSystemImpl = null;
_editorSimulateModeImpl = null;
_offlinePlayModeImpl = null;
_hostPlayModeImpl = null;
}
}
private void CheckInitializeParameters(InitializeParameters parameters)
{
if (_isInitialize)
@@ -185,7 +202,8 @@ namespace YooAsset
/// 向网络端请求最新的资源版本
/// </summary>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageVersionOperation UpdatePackageVersionAsync(int timeout = 60)
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
public UpdatePackageVersionOperation UpdatePackageVersionAsync(int timeout = 60, bool appendTimeTicks = true)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorSimulateMode)
@@ -202,7 +220,7 @@ namespace YooAsset
}
else if (_playMode == EPlayMode.HostPlayMode)
{
return _hostPlayModeImpl.UpdatePackageVersionAsync(PackageName, timeout);
return _hostPlayModeImpl.UpdatePackageVersionAsync(PackageName, timeout, appendTimeTicks);
}
else
{

View File

@@ -105,7 +105,7 @@ namespace YooAsset
if (_steps == ESteps.LoadWebManifest)
{
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetPatchManifestRequestURL(fileName);
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloader = new UnityWebDataRequester();
@@ -131,7 +131,8 @@ namespace YooAsset
// 解析补丁清单
try
{
_remotePatchManifest = PatchManifest.Deserialize(_downloader.GetText());
byte[] bytesData = _downloader.GetData();
_remotePatchManifest = PatchManifest.DeserializeFromBinary(bytesData);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}

View File

@@ -56,8 +56,8 @@ namespace YooAsset
try
{
YooLogger.Log($"Load simulation manifest file : {_simulatePatchManifestPath}");
string jsonContent = FileUtility.ReadFile(_simulatePatchManifestPath);
var manifest = PatchManifest.Deserialize(jsonContent);
byte[] bytesData = FileUtility.ReadAllBytes(_simulatePatchManifestPath);
var manifest = PatchManifest.DeserializeFromBinary(bytesData);
InitializedPackageVersion = manifest.PackageVersion;
_impl.SetSimulatePatchManifest(manifest);
_steps = ESteps.Done;
@@ -491,7 +491,7 @@ namespace YooAsset
if (_steps == ESteps.LoadAppManifest)
{
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
@@ -513,7 +513,8 @@ namespace YooAsset
// 解析APP里的补丁清单
try
{
Manifest = PatchManifest.Deserialize(_downloader.GetText());
byte[] bytesData = _downloader.GetData();
Manifest = PatchManifest.DeserializeFromBinary(bytesData);
}
catch (System.Exception e)
{
@@ -590,7 +591,7 @@ namespace YooAsset
if (_steps == ESteps.CopyAppManifest)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName);
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebFileRequester();

View File

@@ -171,7 +171,7 @@ namespace YooAsset
if (_steps == ESteps.LoadWebManifest)
{
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageVersion);
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetPatchManifestRequestURL(fileName);
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloader2 = new UnityWebDataRequester();
@@ -194,8 +194,8 @@ namespace YooAsset
{
try
{
string content = _downloader2.GetText();
var manifest = PersistentHelper.SaveCacheManifestFile(_packageName, content);
byte[] bytesData = _downloader2.GetData();
var manifest = PersistentHelper.SaveCacheManifestFile(_packageName, bytesData);
_impl.SetLocalPatchManifest(manifest);
FoundNewManifest = true;
_steps = ESteps.InitVerifyingCache;

View File

@@ -60,14 +60,16 @@ namespace YooAsset
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly int _timeout;
private readonly bool _appendTimeTicks;
private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloader;
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, int timeout, bool appendTimeTicks)
{
_impl = impl;
_packageName = packageName;
_timeout = timeout;
_appendTimeTicks = appendTimeTicks;
}
internal override void Start()
{
@@ -130,8 +132,11 @@ namespace YooAsset
else
url = _impl.GetPatchDownloadMainURL(fileName);
// 注意:在URL末尾添加时间戳
return $"{url}?{System.DateTime.UtcNow.Ticks}";
// 在URL末尾添加时间戳
if (_appendTimeTicks)
return $"{url}?{System.DateTime.UtcNow.Ticks}";
else
return url;
}
}
}

View File

@@ -109,15 +109,8 @@ namespace YooAsset
}
public PatchBundle(string bundleName, string fileHash, string fileCRC, long fileSize, bool isRawFile, byte loadMethod, string[] tags)
public PatchBundle()
{
BundleName = bundleName;
FileHash = fileHash;
FileCRC = fileCRC;
FileSize = fileSize;
IsRawFile = isRawFile;
LoadMethod = loadMethod;
Tags = tags;
}
/// <summary>

View File

@@ -266,48 +266,147 @@ namespace YooAsset
/// <summary>
/// 序列化
/// 序列化JSON文件
/// </summary>
public static void Serialize(string savePath, PatchManifest patchManifest)
public static void SerializeToJson(string savePath, PatchManifest manifest)
{
string json = JsonUtility.ToJson(patchManifest);
string json = JsonUtility.ToJson(manifest, true);
FileUtility.CreateFile(savePath, json);
}
/// <summary>
/// 序列化
/// 序列化(二进制文件)
/// </summary>
public static PatchManifest Deserialize(string jsonData)
public static void SerializeToBinary(string savePath, PatchManifest patchManifest)
{
PatchManifest patchManifest = JsonUtility.FromJson<PatchManifest>(jsonData);
if (patchManifest == null)
throw new System.Exception($"{nameof(PatchManifest)} deserialize object is null !");
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
BufferWriter buffer = new BufferWriter(YooAssetSettings.PatchManifestFileMaxSize);
// 检测文件版本
if (patchManifest.FileVersion != YooAssetSettings.PatchManifestFileVersion)
throw new Exception($"The manifest file version are not compatible : {patchManifest.FileVersion} != {YooAssetSettings.PatchManifestFileVersion}");
// 写入文件标记
buffer.WriteUInt32(YooAssetSettings.PatchManifestFileSign);
// 写入文件版本
buffer.WriteUTF8(patchManifest.FileVersion);
// 写入文件头信息
buffer.WriteBool(patchManifest.EnableAddressable);
buffer.WriteInt32(patchManifest.OutputNameStyle);
buffer.WriteUTF8(patchManifest.PackageName);
buffer.WriteUTF8(patchManifest.PackageVersion);
// 写入资源列表
buffer.WriteInt32(patchManifest.AssetList.Count);
for (int i = 0; i < patchManifest.AssetList.Count; i++)
{
var patchAsset = patchManifest.AssetList[i];
buffer.WriteUTF8(patchAsset.Address);
buffer.WriteUTF8(patchAsset.AssetPath);
buffer.WriteUTF8Array(patchAsset.AssetTags);
buffer.WriteInt32(patchAsset.BundleID);
buffer.WriteInt32Array(patchAsset.DependIDs);
}
// 写入资源包列表
buffer.WriteInt32(patchManifest.BundleList.Count);
for (int i = 0; i < patchManifest.BundleList.Count; i++)
{
var patchBundle = patchManifest.BundleList[i];
buffer.WriteUTF8(patchBundle.BundleName);
buffer.WriteUTF8(patchBundle.FileHash);
buffer.WriteUTF8(patchBundle.FileCRC);
buffer.WriteInt64(patchBundle.FileSize);
buffer.WriteBool(patchBundle.IsRawFile);
buffer.WriteByte(patchBundle.LoadMethod);
buffer.WriteUTF8Array(patchBundle.Tags);
}
// 写入文件流
buffer.WriteToStream(fs);
fs.Flush();
}
}
/// <summary>
/// 反序列化(二进制文件)
/// </summary>
public static PatchManifest DeserializeFromBinary(byte[] binaryData)
{
// 创建缓存器
BufferReader buffer = new BufferReader(binaryData);
// 读取文件标记
uint fileSign = buffer.ReadUInt32();
if (fileSign != YooAssetSettings.PatchManifestFileSign)
throw new Exception("Invalid manifest file !");
PatchManifest manifest = new PatchManifest();
{
// 读取文件版本
manifest.FileVersion = buffer.ReadUTF8();
if (manifest.FileVersion != YooAssetSettings.PatchManifestFileVersion)
throw new Exception($"The manifest file version are not compatible : {manifest.FileVersion} != {YooAssetSettings.PatchManifestFileVersion}");
// 读取文件头信息
manifest.EnableAddressable = buffer.ReadBool();
manifest.OutputNameStyle = buffer.ReadInt32();
manifest.PackageName = buffer.ReadUTF8();
manifest.PackageVersion = buffer.ReadUTF8();
// 读取资源列表
int patchAssetCount = buffer.ReadInt32();
manifest.AssetList = new List<PatchAsset>(patchAssetCount);
for (int i = 0; i < patchAssetCount; i++)
{
var patchAsset = new PatchAsset();
patchAsset.Address = buffer.ReadUTF8();
patchAsset.AssetPath = buffer.ReadUTF8();
patchAsset.AssetTags = buffer.ReadUTF8Array();
patchAsset.BundleID = buffer.ReadInt32();
patchAsset.DependIDs = buffer.ReadInt32Array();
manifest.AssetList.Add(patchAsset);
}
// 读取资源包列表
int patchBundleCount = buffer.ReadInt32();
manifest.BundleList = new List<PatchBundle>(patchBundleCount);
for (int i = 0; i < patchBundleCount; i++)
{
var patchBundle = new PatchBundle();
patchBundle.BundleName = buffer.ReadUTF8();
patchBundle.FileHash = buffer.ReadUTF8();
patchBundle.FileCRC = buffer.ReadUTF8();
patchBundle.FileSize = buffer.ReadInt64();
patchBundle.IsRawFile = buffer.ReadBool();
patchBundle.LoadMethod = buffer.ReadByte();
patchBundle.Tags = buffer.ReadUTF8Array();
manifest.BundleList.Add(patchBundle);
}
}
// BundleList
foreach (var patchBundle in patchManifest.BundleList)
foreach (var patchBundle in manifest.BundleList)
{
patchBundle.ParseBundle(patchManifest.PackageName, patchManifest.OutputNameStyle);
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
patchBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle);
manifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
}
// AssetList
foreach (var patchAsset in patchManifest.AssetList)
foreach (var patchAsset in manifest.AssetList)
{
// 注意:我们不允许原始路径存在重名
string assetPath = patchAsset.AssetPath;
if (patchManifest.AssetDic.ContainsKey(assetPath))
if (manifest.AssetDic.ContainsKey(assetPath))
throw new Exception($"AssetPath have existed : {assetPath}");
else
patchManifest.AssetDic.Add(assetPath, patchAsset);
manifest.AssetDic.Add(assetPath, patchAsset);
}
return patchManifest;
return manifest;
}
/// <summary>
/// 生成Bundle文件的正式名称
/// </summary>

View File

@@ -78,6 +78,10 @@ namespace YooAsset
{
return _simulatePatchManifest.IsIncludeBundleFile(fileName);
}
bool IBundleServices.IsServicesValid()
{
return _simulatePatchManifest != null;
}
#endregion
}
}

View File

@@ -44,9 +44,9 @@ namespace YooAsset
/// <summary>
/// 异步更新资源版本号
/// </summary>
public UpdatePackageVersionOperation UpdatePackageVersionAsync(string packageName, int timeout)
public UpdatePackageVersionOperation UpdatePackageVersionAsync(string packageName, int timeout, bool appendTimeTicks)
{
var operation = new HostPlayModeUpdatePackageVersionOperation(this, packageName, timeout);
var operation = new HostPlayModeUpdatePackageVersionOperation(this, packageName, timeout, appendTimeTicks);
OperationSystem.StartOperation(operation);
return operation;
}
@@ -428,6 +428,10 @@ namespace YooAsset
{
return LocalPatchManifest.IsIncludeBundleFile(fileName);
}
bool IBundleServices.IsServicesValid()
{
return LocalPatchManifest != null;
}
#endregion
}
}

View File

@@ -129,6 +129,10 @@ namespace YooAsset
{
return _appPatchManifest.IsIncludeBundleFile(fileName);
}
bool IBundleServices.IsServicesValid()
{
return _appPatchManifest != null;
}
#endregion
}
}

View File

@@ -2,7 +2,7 @@
namespace YooAsset
{
internal interface IBundleServices
{
{
/// <summary>
/// 获取资源包信息
/// </summary>
@@ -42,5 +42,10 @@ namespace YooAsset
/// 是否包含资源文件
/// </summary>
bool IsIncludeBundleFile(string fileName);
/// <summary>
/// 服务接口是否有效
/// </summary>
bool IsServicesValid();
}
}

View File

@@ -16,13 +16,23 @@ namespace YooAsset
public string RawFileVariant = "rawfile";
/// <summary>
/// 补丁清单文件名称
/// 清单文件名称
/// </summary>
public string PatchManifestFileName = "PatchManifest";
/// <summary>
/// 补丁清单文件格式版本
/// 清单文件头标记
/// </summary>
public const uint PatchManifestFileSign = 0x594F4F;
/// <summary>
/// 清单文件极限大小100MB
/// </summary>
public const int PatchManifestFileMaxSize = 104857600;
/// <summary>
/// 清单文件格式版本
/// </summary>
public const string PatchManifestFileVersion = "1.3.4";

View File

@@ -51,11 +51,19 @@ namespace YooAsset
/// <summary>
/// 获取补丁清单文件完整名称
/// </summary>
public static string GetPatchManifestFileName(string packageName, string packageVersion)
public static string GetPatchManifestBinaryFileName(string packageName, string packageVersion)
{
return $"{Setting.PatchManifestFileName}_{packageName}_{packageVersion}.bytes";
}
/// <summary>
/// 获取补丁清单文件完整名称
/// </summary>
public static string GetPatchManifestJsonFileName(string packageName, string packageVersion)
{
return $"{Setting.PatchManifestFileName}_{packageName}_{packageVersion}.json";
}
/// <summary>
/// 获取补丁清单哈希文件完整名称
/// </summary>

View File

@@ -1,69 +0,0 @@
using System;
namespace YooAsset
{
internal struct BitMask32
{
private int _mask;
public static implicit operator int(BitMask32 mask) { return mask._mask; }
public static implicit operator BitMask32(int mask) { return new BitMask32(mask); }
public BitMask32(int mask)
{
_mask = mask;
}
/// <summary>
/// 打开位
/// </summary>
public void Open(int bit)
{
if (bit < 0 || bit > 31)
throw new ArgumentOutOfRangeException();
else
_mask |= 1 << bit;
}
/// <summary>
/// 关闭位
/// </summary>
public void Close(int bit)
{
if (bit < 0 || bit > 31)
throw new ArgumentOutOfRangeException();
else
_mask &= ~(1 << bit);
}
/// <summary>
/// 位取反
/// </summary>
public void Reverse(int bit)
{
if (bit < 0 || bit > 31)
throw new ArgumentOutOfRangeException();
else
_mask ^= 1 << bit;
}
/// <summary>
/// 所有位取反
/// </summary>
public void Inverse()
{
_mask = ~_mask;
}
/// <summary>
/// 比对位值
/// </summary>
public bool Test(int bit)
{
if (bit < 0 || bit > 31)
throw new ArgumentOutOfRangeException();
else
return (_mask & (1 << bit)) != 0;
}
}
}

View File

@@ -1,69 +0,0 @@
using System;
namespace YooAsset
{
internal struct BitMask64
{
private long _mask;
public static implicit operator long(BitMask64 mask) { return mask._mask; }
public static implicit operator BitMask64(long mask) { return new BitMask64(mask); }
public BitMask64(long mask)
{
_mask = mask;
}
/// <summary>
/// 打开位
/// </summary>
public void Open(int bit)
{
if (bit < 0 || bit > 63)
throw new ArgumentOutOfRangeException();
else
_mask |= 1L << bit;
}
/// <summary>
/// 关闭位
/// </summary>
public void Close(int bit)
{
if (bit < 0 || bit > 63)
throw new ArgumentOutOfRangeException();
else
_mask &= ~(1L << bit);
}
/// <summary>
/// 位取反
/// </summary>
public void Reverse(int bit)
{
if (bit < 0 || bit > 63)
throw new ArgumentOutOfRangeException();
else
_mask ^= 1L << bit;
}
/// <summary>
/// 所有位取反
/// </summary>
public void Inverse()
{
_mask = ~_mask;
}
/// <summary>
/// 比对位值
/// </summary>
public bool Test(int bit)
{
if (bit < 0 || bit > 63)
throw new ArgumentOutOfRangeException();
else
return (_mask & (1L << bit)) != 0;
}
}
}

View File

@@ -0,0 +1,160 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace YooAsset
{
internal class BufferReader
{
private readonly byte[] _buffer;
private int _index = 0;
public BufferReader(byte[] data)
{
_buffer = data;
}
/// <summary>
/// 缓冲区容量
/// </summary>
public int Capacity
{
get { return _buffer.Length; }
}
public byte[] ReadBytes(int count)
{
CheckReaderIndex(count);
var data = new byte[count];
Buffer.BlockCopy(_buffer, _index, data, 0, count);
_index += count;
return data;
}
public byte ReadByte()
{
CheckReaderIndex(1);
return _buffer[_index++];
}
public bool ReadBool()
{
CheckReaderIndex(1);
return _buffer[_index++] == 1;
}
public short ReadInt16()
{
CheckReaderIndex(2);
if (BitConverter.IsLittleEndian)
{
short value = (short)((_buffer[_index]) | (_buffer[_index + 1] << 8));
_index += 2;
return value;
}
else
{
short value = (short)((_buffer[_index] << 8) | (_buffer[_index + 1]));
_index += 2;
return value;
}
}
public ushort ReadUInt16()
{
return (ushort)ReadInt16();
}
public int ReadInt32()
{
CheckReaderIndex(4);
if (BitConverter.IsLittleEndian)
{
int value = (_buffer[_index]) | (_buffer[_index + 1] << 8) | (_buffer[_index + 2] << 16) | (_buffer[_index + 3] << 24);
_index += 4;
return value;
}
else
{
int value = (_buffer[_index] << 24) | (_buffer[_index + 1] << 16) | (_buffer[_index + 2] << 8) | (_buffer[_index + 3]);
_index += 4;
return value;
}
}
public uint ReadUInt32()
{
return (uint)ReadInt32();
}
public long ReadInt64()
{
CheckReaderIndex(8);
if (BitConverter.IsLittleEndian)
{
int i1 = (_buffer[_index]) | (_buffer[_index + 1] << 8) | (_buffer[_index + 2] << 16) | (_buffer[_index + 3] << 24);
int i2 = (_buffer[_index + 4]) | (_buffer[_index + 5] << 8) | (_buffer[_index + 6] << 16) | (_buffer[_index + 7] << 24);
_index += 8;
return (uint)i1 | ((long)i2 << 32);
}
else
{
int i1 = (_buffer[_index] << 24) | (_buffer[_index + 1] << 16) | (_buffer[_index + 2] << 8) | (_buffer[_index + 3]);
int i2 = (_buffer[_index + 4] << 24) | (_buffer[_index + 5] << 16) | (_buffer[_index + 6] << 8) | (_buffer[_index + 7]);
_index += 8;
return (uint)i2 | ((long)i1 << 32);
}
}
public ulong ReadUInt64()
{
return (ulong)ReadInt64();
}
public string ReadUTF8()
{
ushort count = ReadUInt16();
if (count == 0)
return string.Empty;
CheckReaderIndex(count);
string value = Encoding.UTF8.GetString(_buffer, _index, count);
_index += count;
return value;
}
public int[] ReadInt32Array()
{
ushort count = ReadUInt16();
int[] values = new int[count];
for (int i = 0; i < count; i++)
{
values[i] = ReadInt32();
}
return values;
}
public long[] ReadInt64Array()
{
ushort count = ReadUInt16();
long[] values = new long[count];
for (int i = 0; i < count; i++)
{
values[i] = ReadInt64();
}
return values;
}
public string[] ReadUTF8Array()
{
ushort count = ReadUInt16();
string[] values = new string[count];
for (int i = 0; i < count; i++)
{
values[i] = ReadUTF8();
}
return values;
}
[Conditional("DEBUG")]
private void CheckReaderIndex(int length)
{
if (_index + length > Capacity)
{
throw new IndexOutOfRangeException();
}
}
}
}

View File

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

View File

@@ -0,0 +1,179 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace YooAsset
{
/// <summary>
/// 数据存储以小端字节序为标准
/// </summary>
internal class BufferWriter
{
private readonly byte[] _buffer;
private int _index = 0;
public BufferWriter(int capacity)
{
_buffer = new byte[capacity];
}
/// <summary>
/// 缓冲区容量
/// </summary>
public int Capacity
{
get { return _buffer.Length; }
}
/// <summary>
/// 将有效数据写入文件流
/// </summary>
public void WriteToStream(FileStream fileStream)
{
fileStream.Write(_buffer, 0, _index);
}
public void WriteBytes(byte[] data)
{
int count = data.Length;
CheckWriterIndex(count);
Buffer.BlockCopy(data, 0, _buffer, _index, count);
_index += count;
}
public void WriteByte(byte value)
{
CheckWriterIndex(1);
_buffer[_index++] = value;
}
public void WriteBool(bool value)
{
WriteByte((byte)(value ? 1 : 0));
}
public void WriteInt16(short value)
{
WriteUInt16((ushort)value);
}
public void WriteUInt16(ushort value)
{
CheckWriterIndex(2);
_buffer[_index++] = (byte)value;
_buffer[_index++] = (byte)(value >> 8);
}
public void WriteInt32(int value)
{
WriteUInt32((uint)value);
}
public void WriteUInt32(uint value)
{
CheckWriterIndex(4);
_buffer[_index++] = (byte)value;
_buffer[_index++] = (byte)(value >> 8);
_buffer[_index++] = (byte)(value >> 16);
_buffer[_index++] = (byte)(value >> 24);
}
public void WriteInt64(long value)
{
WriteUInt64((ulong)value);
}
public void WriteUInt64(ulong value)
{
CheckWriterIndex(8);
_buffer[_index++] = (byte)value;
_buffer[_index++] = (byte)(value >> 8);
_buffer[_index++] = (byte)(value >> 16);
_buffer[_index++] = (byte)(value >> 24);
_buffer[_index++] = (byte)(value >> 32);
_buffer[_index++] = (byte)(value >> 40);
_buffer[_index++] = (byte)(value >> 48);
_buffer[_index++] = (byte)(value >> 56);
}
public void WriteUTF8(string value)
{
if (string.IsNullOrEmpty(value))
{
WriteUInt16(0);
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(value);
int count = bytes.Length;
if (count > ushort.MaxValue)
throw new FormatException($"Write string length cannot be greater than {ushort.MaxValue} !");
WriteUInt16(Convert.ToUInt16(count));
WriteBytes(bytes);
}
}
public void WriteInt32Array(int[] values)
{
if (values == null)
{
WriteUInt16(0);
}
else
{
int count = values.Length;
if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !");
WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++)
{
WriteInt32(values[i]);
}
}
}
public void WriteInt64Array(long[] values)
{
if (values == null)
{
WriteUInt16(0);
}
else
{
int count = values.Length;
if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !");
WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++)
{
WriteInt64(values[i]);
}
}
}
public void WriteUTF8Array(string[] values)
{
if (values == null)
{
WriteUInt16(0);
}
else
{
int count = values.Length;
if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !");
WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++)
{
WriteUTF8(values[i]);
}
}
}
[Conditional("DEBUG")]
private void CheckWriterIndex(int length)
{
if (_index + length > Capacity)
{
throw new IndexOutOfRangeException();
}
}
}
}

View File

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

View File

@@ -128,19 +128,19 @@ namespace YooAsset
{
YooLogger.Log($"Load sandbox patch manifest file : {packageName}");
string filePath = GetCacheManifestFilePath(packageName);
string jsonData = File.ReadAllText(filePath);
return PatchManifest.Deserialize(jsonData);
byte[] bytesData = File.ReadAllBytes(filePath);
return PatchManifest.DeserializeFromBinary(bytesData);
}
/// <summary>
/// 存储沙盒内清单文件
/// </summary>
public static PatchManifest SaveCacheManifestFile(string packageName, string fileContent)
public static PatchManifest SaveCacheManifestFile(string packageName, byte[] fileBytesData)
{
YooLogger.Log($"Save sandbox patch manifest file : {packageName}");
var manifest = PatchManifest.Deserialize(fileContent);
var manifest = PatchManifest.DeserializeFromBinary(fileBytesData);
string savePath = GetCacheManifestFilePath(packageName);
FileUtility.CreateFile(savePath, fileContent);
FileUtility.CreateFile(savePath, fileBytesData);
return manifest;
}

View File

@@ -117,15 +117,25 @@ namespace YooAsset
internal static class FileUtility
{
/// <summary>
/// 读取文件
/// 读取文件的文本数据
/// </summary>
public static string ReadFile(string filePath)
public static string ReadAllText(string filePath)
{
if (File.Exists(filePath) == false)
return string.Empty;
return File.ReadAllText(filePath, Encoding.UTF8);
}
/// <summary>
/// 读取文件的字节数据
/// </summary>
public static byte[] ReadAllBytes(string filePath)
{
if (File.Exists(filePath) == false)
return null;
return File.ReadAllBytes(filePath);
}
/// <summary>
/// 创建文件(如果已经存在则删除旧文件)
/// </summary>

View File

@@ -106,6 +106,18 @@ namespace YooAsset
/// </summary>
/// <param name="packageName">资源包名称</param>
public static AssetsPackage GetAssetsPackage(string packageName)
{
var package = TryGetAssetsPackage(packageName);
if (package == null)
YooLogger.Warning($"Not found assets package : {packageName}");
return package;
}
/// <summary>
/// 尝试获取资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
public static AssetsPackage TryGetAssetsPackage(string packageName)
{
if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !");
@@ -118,8 +130,6 @@ namespace YooAsset
if (package.PackageName == packageName)
return package;
}
YooLogger.Warning($"Not found assets package : {packageName}");
return null;
}

View File

@@ -5,9 +5,7 @@ using System.IO;
using UnityEngine;
using YooAsset.Editor;
/// <summary>
/// 按照文件名的首字母来划分资源
/// </summary>
[DisplayName("打包特效纹理(自定义)")]
public class PackEffectTexture : IPackRule
{
private const string PackDirectory = "Assets/Effect/Textures/";

View File

@@ -105,12 +105,12 @@ namespace YooAsset.Editor
newList.Clear();
// 加载补丁清单1
string jsonData1 = FileUtility.ReadFile(_patchManifestPath1);
PatchManifest patchManifest1 = PatchManifest.Deserialize(jsonData1);
byte[] bytesData1 = FileUtility.ReadAllBytes(_patchManifestPath1);
PatchManifest patchManifest1 = PatchManifest.DeserializeFromBinary(bytesData1);
// 加载补丁清单1
string jsonData2 = FileUtility.ReadFile(_patchManifestPath2);
PatchManifest patchManifest2 = PatchManifest.Deserialize(jsonData2);
byte[] bytesData2 = FileUtility.ReadAllBytes(_patchManifestPath2);
PatchManifest patchManifest2 = PatchManifest.DeserializeFromBinary(bytesData2);
// 拷贝文件列表
foreach (var patchBundle2 in patchManifest2.BundleList)

View File

@@ -51,8 +51,8 @@ namespace YooAsset.Editor
string outputDirectory = Path.GetDirectoryName(patchManifestFilePath);
// 加载补丁清单
string jsonData = FileUtility.ReadFile(patchManifestFilePath);
PatchManifest patchManifest = PatchManifest.Deserialize(jsonData);
byte[] bytesData = FileUtility.ReadAllBytes(patchManifestFilePath);
PatchManifest patchManifest = PatchManifest.DeserializeFromBinary(bytesData);
// 拷贝核心文件
{

View File

@@ -15,6 +15,7 @@ MonoBehaviour:
ShowPackageView: 0
EnableAddressable: 1
UniqueBundleName: 0
ShowEditorAlias: 0
Packages:
- PackageName: DefaultPackage
PackageDesc:

View File

@@ -2,6 +2,18 @@
public class PatchEventDefine
{
/// <summary>
/// 补丁包初始化失败
/// </summary>
public class InitializeFailed : IEventMessage
{
public static void SendEventMessage()
{
var msg = new InitializeFailed();
UniEvent.SendMessage(msg);
}
}
/// <summary>
/// 补丁流程步骤改变
/// </summary>

View File

@@ -2,6 +2,18 @@
public class UserEventDefine
{
/// <summary>
/// 用户尝试再次初始化资源包
/// </summary>
public class UserTryInitialize : IEventMessage
{
public static void SendEventMessage()
{
var msg = new UserTryInitialize();
UniEvent.SendMessage(msg);
}
}
/// <summary>
/// 用户开始下载网络文件
/// </summary>

View File

@@ -8,9 +8,9 @@ using UniFramework.Module;
using YooAsset;
/// <summary>
/// 初始化工作
/// 初始化资源包
/// </summary>
internal class FsmPatchInit : IStateNode
internal class FsmInitialize : IStateNode
{
private StateMachine _machine;
@@ -20,12 +20,8 @@ internal class FsmPatchInit : IStateNode
}
void IStateNode.OnEnter()
{
// 加载更新面板
var go = Resources.Load<GameObject>("PatchWindow");
GameObject.Instantiate(go);
// 初始化资源系统
UniModule.StartCoroutine(InitYooAsset());
PatchEventDefine.PatchStatesChange.SendEventMessage("初始化资源包!");
UniModule.StartCoroutine(InitPackage());
}
void IStateNode.OnUpdate()
{
@@ -34,19 +30,24 @@ internal class FsmPatchInit : IStateNode
{
}
private IEnumerator InitYooAsset()
private IEnumerator InitPackage()
{
var playMode = PatchManager.Instance.PlayMode;
// 创建默认的资源包
var package = YooAssets.CreateAssetsPackage("DefaultPackage");
YooAssets.SetDefaultAssetsPackage(package);
// 创建默认的资源包
string packageName = "DefaultPackage";
var package = YooAssets.TryGetAssetsPackage(packageName);
if (package == null)
{
package = YooAssets.CreateAssetsPackage(packageName);
YooAssets.SetDefaultAssetsPackage(package);
}
// 编辑器下的模拟模式
if (playMode == EPlayMode.EditorSimulateMode)
{
var createParameters = new EditorSimulateModeParameters();
createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage");
createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild(packageName);
yield return package.InitializeAsync(createParameters);
}
@@ -69,7 +70,10 @@ internal class FsmPatchInit : IStateNode
yield return package.InitializeAsync(createParameters);
}
_machine.ChangeState<FsmUpdateVersion>();
if (package.InitializeStatus == EOperationStatus.Succeed)
_machine.ChangeState<FsmUpdateVersion>();
else
PatchEventDefine.InitializeFailed.SendEventMessage();
}
/// <summary>

View File

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

View File

@@ -5,7 +5,7 @@ using UniFramework.Machine;
using UniFramework.Module;
/// <summary>
/// 更新完毕
/// 流程更新完毕
/// </summary>
internal class FsmPatchDone : IStateNode
{

View File

@@ -0,0 +1,34 @@
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Machine;
using UniFramework.Module;
/// <summary>
/// 流程准备工作
/// </summary>
internal class FsmPatchPrepare : IStateNode
{
private StateMachine _machine;
void IStateNode.OnCreate(StateMachine machine)
{
_machine = machine;
}
void IStateNode.OnEnter()
{
// 加载更新面板
var go = Resources.Load<GameObject>("PatchWindow");
GameObject.Instantiate(go);
_machine.ChangeState<FsmInitialize>();
}
void IStateNode.OnUpdate()
{
}
void IStateNode.OnExit()
{
}
}

View File

@@ -53,6 +53,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
PlayMode = playMode;
// 注册监听事件
_eventGroup.AddListener<UserEventDefine.UserTryInitialize>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserBeginDownloadWebFiles>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePackageVersion>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePatchManifest>(OnHandleEventMessage);
@@ -60,7 +61,8 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
Debug.Log("开启补丁更新流程...");
_machine = new StateMachine(this);
_machine.AddNode<FsmPatchInit>();
_machine.AddNode<FsmPatchPrepare>();
_machine.AddNode<FsmInitialize>();
_machine.AddNode<FsmUpdateVersion>();
_machine.AddNode<FsmUpdateManifest>();
_machine.AddNode<FsmCreateDownloader>();
@@ -68,7 +70,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
_machine.AddNode<FsmDownloadOver>();
_machine.AddNode<FsmClearCache>();
_machine.AddNode<FsmPatchDone>();
_machine.Run<FsmPatchInit>();
_machine.Run<FsmPatchPrepare>();
}
else
{
@@ -81,7 +83,11 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
/// </summary>
private void OnHandleEventMessage(IEventMessage message)
{
if (message is UserEventDefine.UserBeginDownloadWebFiles)
if (message is UserEventDefine.UserTryInitialize)
{
_machine.ChangeState<FsmInitialize>();
}
else if (message is UserEventDefine.UserBeginDownloadWebFiles)
{
_machine.ChangeState<FsmDownloadFiles>();
}

View File

@@ -70,6 +70,7 @@ public class PatchWindow : MonoBehaviour
_messageBoxObj = transform.Find("UIWindow/MessgeBox").gameObject;
_messageBoxObj.SetActive(false);
_eventGroup.AddListener<PatchEventDefine.InitializeFailed>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.PatchStatesChange>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.FoundUpdateFiles>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.DownloadProgressUpdate>(OnHandleEventMessage);
@@ -87,7 +88,15 @@ public class PatchWindow : MonoBehaviour
/// </summary>
private void OnHandleEventMessage(IEventMessage message)
{
if (message is PatchEventDefine.PatchStatesChange)
if (message is PatchEventDefine.InitializeFailed)
{
System.Action callback = () =>
{
UserEventDefine.UserTryInitialize.SendEventMessage();
};
ShowMessageBox($"Failed to initialize package !", callback);
}
else if (message is PatchEventDefine.PatchStatesChange)
{
var msg = message as PatchEventDefine.PatchStatesChange;
_tips.text = msg.Tips;

View File

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

View File

@@ -6,6 +6,10 @@
windows平台添加命令: **-force-gles**
#### 问题Unity2021编辑器运行游戏提示YooAssets is initialized !
尝试关闭Project Setting ---> Editor ---> Enter Play Mode Options
#### 问题YooAsset的DLL引用丢失导致编译报错了
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
@@ -36,7 +40,8 @@ internal class FsmClearCache : IFsmNode
void IFsmNode.OnEnter()
{
Debug.Log("清理未使用的缓存文件!");
var operation = YooAssets.ClearUnusedCacheFiles();
var package = YooAssets.GetPackage("DefaultPackage");
var operation = package.ClearUnusedCacheFiles();
operation.Completed += Operation_Completed;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -4,7 +4,7 @@
#### 示例内容
**Basic Sample** 包含资源热更和加载的示例。
**Space Shooter** 太空战机DEMO包含资源热更和加载的示例。
**Extension Sample** 包含编辑器扩展代码的示例。
@@ -14,6 +14,6 @@
![image](./Image/Samples-img2.png)
1. Basic Sample在导入完成后打开YooAsset->AssetBundle Collector窗口。
1. Space Shooter在导入完成后打开YooAsset->AssetBundle Collector窗口。
1. 点击修复按钮然后点击Save按钮保存配置最后关闭窗口。
3. 找到Boot.scene场景启动游戏。