Compare commits

...

16 Commits

Author SHA1 Message Date
何冠峰
b74a44dc36 update UIElements 2025-03-03 20:57:50 +08:00
何冠峰
6b36cdb5ee update AssetBundleDebugger
内置了新的UIElments的TreeViewer组件。
2025-03-03 18:28:02 +08:00
何冠峰
56ae1a8f95 update UIElements 2025-02-28 19:06:17 +08:00
何冠峰
3069b1d1f1 update diagnostic system 2025-02-28 18:38:18 +08:00
何冠峰
e7d346e4e1 update diagnostic system
调试窗口增加异步操作视图
2025-02-27 20:37:28 +08:00
何冠峰
7d9e00a574 update resource package 2025-02-27 18:15:02 +08:00
何冠峰
7382afe535 Update CHANGELOG.md 2025-02-27 17:43:10 +08:00
何冠峰
af7d4774d6 Update package.json 2025-02-27 17:43:02 +08:00
何冠峰
520a8a0623 code style 2025-02-27 17:14:20 +08:00
何冠峰
fbd0d8ec40 code style 2025-02-27 17:14:12 +08:00
何冠峰
3fea98ce4c fix #480 2025-02-27 17:13:49 +08:00
何冠峰
7c561ce254 update resource package 2025-02-27 17:01:26 +08:00
何冠峰
522ddb5115 update resource package
增加CustomPlayMode运行模式
2025-02-27 16:31:56 +08:00
何冠峰
47f5790507 update resource package
CreateBundleDownloader下载器增加参数:recursiveDownload
2025-02-27 10:31:05 +08:00
何冠峰
0cdcfe7f52 update file system 2025-02-26 19:31:06 +08:00
何冠峰
e4d69d869b update resource package
修复2.3.1版本 抖音和微信小游戏 下载器不生效的问题。
2025-02-26 14:22:59 +08:00
86 changed files with 2437 additions and 2033 deletions

View File

@@ -2,6 +2,41 @@
All notable changes to this package will be documented in this file.
## [2.3.2-preview] - 2025-02-27
### Fixed
- (2.3.1) 修复小游戏平台下载器不生效的问题。
- (#480) 修复了Unity工程打包导出时的报错。
### Added
- 下载器新增参数recursiveDownload
```csharp
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包
public ResourceDownloaderOperation CreateBundleDownloader()
```
- 新增CustomPlayMode模式
```csharp
/// <summary>
/// 自定义运行模式的初始化参数
/// </summary>
public class CustomPlayModeParameters : InitializeParameters
{
/// <summary>
/// 文件系统初始化参数列表
/// 注意:列表最后一个元素作为主文件系统!
/// </summary>
public List<FileSystemParameters> FileSystemParameterList;
}
```
## [2.3.1-preview] - 2025-02-25
**资源加载依赖计算方式还原为了1.5x版本的模式,只加载资源对象实际依赖的资源包,不再以资源对象所在资源包的依赖关系为加载标准**。

View File

@@ -326,7 +326,7 @@ namespace YooAsset.Editor
var column = new TableColumn("眼睛框", string.Empty, columnStyle);
column.MakeCell = () =>
{
var toggle = new DisplayToggle();
var toggle = new ToggleDisplay();
toggle.text = string.Empty;
toggle.style.unityTextAlign = TextAnchor.MiddleCenter;
toggle.RegisterValueChangedCallback((evt) => { OnDisplayToggleValueChange(toggle, evt); });
@@ -334,11 +334,10 @@ namespace YooAsset.Editor
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var toggle = element as DisplayToggle;
var toggle = element as ToggleDisplay;
toggle.userData = data;
var tableData = data as ElementTableData;
toggle.SetValueWithoutNotify(tableData.Element.Hidden);
toggle.RefreshIcon();
};
_elementTableView.AddColumn(column);
var headerElement = _elementTableView.GetHeaderElement("眼睛框");
@@ -577,10 +576,8 @@ namespace YooAsset.Editor
// 重绘视图
RebuildView();
}
private void OnDisplayToggleValueChange(DisplayToggle toggle, ChangeEvent<bool> e)
private void OnDisplayToggleValueChange(ToggleDisplay toggle, ChangeEvent<bool> e)
{
toggle.RefreshIcon();
// 处理自身
toggle.SetValueWithoutNotify(e.newValue);
@@ -593,7 +590,8 @@ namespace YooAsset.Editor
foreach (var selectedItem in selectedItems)
{
var selectElement = selectedItem as ElementTableData;
selectElement.Element.Hidden = e.newValue;
if (selectElement != null)
selectElement.Element.Hidden = e.newValue;
}
// 重绘视图

View File

@@ -38,16 +38,22 @@ namespace YooAsset.Editor
/// 资源包视图
/// </summary>
BundleView,
/// <summary>
/// 异步操作视图
/// </summary>
OperationView,
}
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
private Label _playerName;
private ToolbarButton _playerName;
private ToolbarMenu _viewModeMenu;
private SliderInt _frameSlider;
private DebuggerAssetListViewer _assetListViewer;
private DebuggerBundleListViewer _bundleListViewer;
private DebuggerOperationListViewer _operationListViewer;
private EViewMode _viewMode;
private string _searchKeyWord;
@@ -78,13 +84,14 @@ namespace YooAsset.Editor
exportBtn.clicked += ExportBtn_clicked;
// 用户列表菜单
_playerName = root.Q<Label>("PlayerName");
_playerName = root.Q<ToolbarButton>("PlayerName");
_playerName.text = "Editor player";
// 视口模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.AssetView);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.BundleView);
_viewModeMenu.menu.AppendAction(EViewMode.OperationView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.OperationView);
_viewModeMenu.text = EViewMode.AssetView.ToString();
// 搜索栏
@@ -111,6 +118,9 @@ namespace YooAsset.Editor
var frameClear = root.Q<ToolbarButton>("FrameClear");
frameClear.clicked += OnFrameClear_clicked;
var recorderToggle = root.Q<ToggleRecord>("FrameRecord");
recorderToggle.RegisterValueChangedCallback(OnRecordToggleValueChange);
}
// 加载视图
@@ -121,6 +131,10 @@ namespace YooAsset.Editor
_bundleListViewer = new DebuggerBundleListViewer();
_bundleListViewer.InitViewer();
// 加载视图
_operationListViewer = new DebuggerOperationListViewer();
_operationListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.AssetView;
_assetListViewer.AttachParent(root);
@@ -129,8 +143,9 @@ namespace YooAsset.Editor
EditorConnection.instance.Initialize();
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Initialize();
RemoteEditorConnection.Instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
}
catch (Exception e)
{
@@ -142,7 +157,8 @@ namespace YooAsset.Editor
// 远程调试
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor);
_playerSessions.Clear();
}
@@ -159,10 +175,7 @@ namespace YooAsset.Editor
private void OnHandlePlayerMessage(MessageEventArgs args)
{
var debugReport = DebugReport.Deserialize(args.data);
OnHandleDebugReport(args.playerId, debugReport);
}
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
{
int playerId = args.playerId;
Debug.Log($"Handle player {playerId} debug report !");
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
_currentPlayerSession.AddDebugReport(debugReport);
@@ -207,8 +220,19 @@ namespace YooAsset.Editor
_currentPlayerSession.ClearDebugReport();
_assetListViewer.ClearView();
_bundleListViewer.ClearView();
_operationListViewer.ClearView();
}
}
private void OnRecordToggleValueChange(ChangeEvent<bool> evt)
{
// 发送采集数据的命令
RemoteCommand command = new RemoteCommand();
command.CommandType = (int)ERemoteCommand.SampleAuto;
command.CommandParam = evt.newValue ? "open" : "close";
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
{
@@ -242,6 +266,7 @@ namespace YooAsset.Editor
_frameSlider.label = $"Frame: {debugReport.FrameCount}";
_assetListViewer.FillViewData(debugReport);
_bundleListViewer.FillViewData(debugReport);
_operationListViewer.FillViewData(debugReport);
}
}
@@ -252,8 +277,8 @@ namespace YooAsset.Editor
command.CommandType = (int)ERemoteCommand.SampleOnce;
command.CommandParam = string.Empty;
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
RemoteDebuggerInRuntime.EditorRequestDebugReport();
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private void ExportBtn_clicked()
{
@@ -288,6 +313,7 @@ namespace YooAsset.Editor
{
_assetListViewer.RebuildView(_searchKeyWord);
_bundleListViewer.RebuildView(_searchKeyWord);
_operationListViewer.RebuildView(_searchKeyWord);
}
}
private void OnViewModeMenuChange(DropdownMenuAction action)
@@ -303,11 +329,19 @@ namespace YooAsset.Editor
{
_assetListViewer.AttachParent(root);
_bundleListViewer.DetachParent();
_operationListViewer.DetachParent();
}
else if (viewMode == EViewMode.BundleView)
{
_assetListViewer.DetachParent();
_bundleListViewer.AttachParent(root);
_operationListViewer.DetachParent();
}
else if (viewMode == EViewMode.OperationView)
{
_assetListViewer.DetachParent();
_bundleListViewer.DetachParent();
_operationListViewer.AttachParent(root);
}
else
{

View File

@@ -1,7 +1,7 @@
<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">
<uie:Toolbar name="TopToolbar" style="display: flex;">
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: lower-left; padding-left: 5px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
<uie:ToolbarButton text="IP" parse-escape-sequences="true" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 150px; flex-grow: 0;" />
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
<uie:ToolbarButton text="Refresh" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
<uie:ToolbarButton text="Export" display-tooltip-when-elided="true" name="ExportButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
@@ -11,5 +11,6 @@
<uie:ToolbarButton text=" &lt;&lt; " display-tooltip-when-elided="true" name="FrameLast" />
<uie:ToolbarButton text=" &gt;&gt; " display-tooltip-when-elided="true" name="FrameNext" />
<uie:ToolbarButton text="Clear" display-tooltip-when-elided="true" name="FrameClear" />
<YooAsset.Editor.ToggleRecord name="FrameRecord" style="width: 20px;" />
</uie:Toolbar>
</ui:UXML>

View File

@@ -27,7 +27,6 @@ namespace YooAsset.Editor
private TableView _providerTableView;
private TableView _dependTableView;
private DebugReport _debugReport;
private List<ITableData> _sourceDatas;
@@ -53,13 +52,12 @@ namespace YooAsset.Editor
_dependTableView = _root.Q<TableView>("BottomTableView");
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{
@@ -90,6 +88,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("AssetPath", "Asset Path", columnStyle);
column.MakeCell = () =>
{
@@ -126,13 +125,13 @@ namespace YooAsset.Editor
_providerTableView.AddColumn(column);
}
// SpawnTime
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("SpawnTime", "Spawn Time", columnStyle);
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
@@ -226,6 +225,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle);
column.MakeCell = () =>
{
@@ -297,8 +297,6 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(DebugReport debugReport)
{
_debugReport = debugReport;
// 清空旧数据
_providerTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
@@ -315,7 +313,7 @@ namespace YooAsset.Editor
rowData.AddAssetPathCell("PackageName", packageData.PackageName);
rowData.AddStringValueCell("AssetPath", providerInfo.AssetPath);
rowData.AddStringValueCell("SpawnScene", providerInfo.SpawnScene);
rowData.AddStringValueCell("SpawnTime", providerInfo.SpawnTime);
rowData.AddStringValueCell("BeginTime", providerInfo.BeginTime);
rowData.AddLongValueCell("LoadingTime", providerInfo.LoadingTime);
rowData.AddLongValueCell("RefCount", providerInfo.RefCount);
rowData.AddStringValueCell("Status", providerInfo.Status.ToString());
@@ -333,7 +331,6 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_providerTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
RebuildView(null);

View File

@@ -32,7 +32,6 @@ namespace YooAsset.Editor
private TableView _usingTableView;
private TableView _referenceTableView;
private DebugReport _debugReport;
private List<ITableData> _sourceDatas;
/// <summary>
@@ -61,14 +60,13 @@ namespace YooAsset.Editor
_referenceTableView = _root.Q<TableView>("ReferenceTableView");
CreateReferenceTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
PanelSplitView.SplitVerticalPanel(bottomGroup, _usingTableView, _referenceTableView);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
UIElementsTools.SplitVerticalPanel(bottomGroup, _usingTableView, _referenceTableView);
}
private void CreateBundleTableViewColumns()
{
@@ -99,6 +97,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("BundleName", "Bundle Name", columnStyle);
column.MakeCell = () =>
{
@@ -172,6 +171,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("UsingAssets", "Using Assets", columnStyle);
column.MakeCell = () =>
{
@@ -208,13 +208,13 @@ namespace YooAsset.Editor
_usingTableView.AddColumn(column);
}
// SpawnTime
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("SpawnTime", "Spawn Time", columnStyle);
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
@@ -287,6 +287,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("ReferenceBundle", "Reference Bundle", columnStyle);
column.MakeCell = () =>
{
@@ -358,8 +359,6 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(DebugReport debugReport)
{
_debugReport = debugReport;
// 清空旧数据
_bundleTableView.ClearAll(false, true);
_usingTableView.ClearAll(false, true);
@@ -392,7 +391,6 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_bundleTableView.ClearAll(false, true);
_bundleTableView.RebuildView();
_usingTableView.ClearAll(false, true);
@@ -448,7 +446,7 @@ namespace YooAsset.Editor
rowData.ProviderInfo = providerInfo;
rowData.AddStringValueCell("UsingAssets", providerInfo.AssetPath);
rowData.AddStringValueCell("SpawnScene", providerInfo.SpawnScene);
rowData.AddStringValueCell("SpawnTime", providerInfo.SpawnTime);
rowData.AddStringValueCell("BeginTime", providerInfo.BeginTime);
rowData.AddLongValueCell("RefCount", providerInfo.RefCount);
rowData.AddStringValueCell("Status", providerInfo.Status);
sourceDatas.Add(rowData);

View File

@@ -0,0 +1,505 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class DebuggerOperationListViewer
{
private class OperationTableData : DefaultTableData
{
public DebugPackageData PackageData;
public DebugOperationInfo OperationInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private TableView _operationTableView;
private Toolbar _bottomToolbar;
private TreeViewer _childTreeView;
private List<ITableData> _sourceDatas;
/// <summary>
/// 初始化页面
/// </summary>
public void InitViewer()
{
// 加载布局文件
_visualAsset = UxmlLoader.LoadWindowUXML<DebuggerOperationListViewer>();
if (_visualAsset == null)
return;
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 任务列表
_operationTableView = _root.Q<TableView>("TopTableView");
_operationTableView.SelectionChangedEvent = OnOperationTableViewSelectionChanged;
CreateOperationTableViewColumns();
// 底部标题栏
_bottomToolbar = _root.Q<Toolbar>("BottomToolbar");
CreateBottomToolbarHeaders();
// 子列表
_childTreeView = _root.Q<TreeViewer>("BottomTreeView");
_childTreeView.makeItem = MakeTreeViewItem;
_childTreeView.bindItem = BindTreeViewItem;
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateOperationTableViewColumns()
{
// PackageName
{
var columnStyle = new ColumnStyle(200);
columnStyle.Searchable = true;
columnStyle.Sortable = true;
var column = new TableColumn("PackageName", "Package Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// OperationName
{
var columnStyle = new ColumnStyle(300, 300, 600);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("OperationName", "Operation Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Priority
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Priority", "Priority", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Progress
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("Progress", "Progress", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// ProcessTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("ProcessTime", "Process Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var operationTableData = data as OperationTableData;
if (operationTableData.OperationInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_operationTableView.AddColumn(column);
}
// Desc
{
var columnStyle = new ColumnStyle(500, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
var column = new TableColumn("Desc", "Desc", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
}
private void CreateBottomToolbarHeaders()
{
// OperationName
{
ToolbarButton button = new ToolbarButton();
button.text = "OperationName";
button.style.flexGrow = 0;
button.style.width = 315;
_bottomToolbar.Add(button);
}
// Progress
{
ToolbarButton button = new ToolbarButton();
button.text = "Progress";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// BeginTime
{
ToolbarButton button = new ToolbarButton();
button.text = "BeginTime";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// ProcessTime
{
ToolbarButton button = new ToolbarButton();
button.text = "ProcessTime";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// Status
{
ToolbarButton button = new ToolbarButton();
button.text = "Status";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// Desc
{
ToolbarButton button = new ToolbarButton();
button.text = "Desc";
button.style.flexGrow = 0;
button.style.width = 500;
_bottomToolbar.Add(button);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(DebugReport debugReport)
{
// 清空旧数据
_operationTableView.ClearAll(false, true);
_childTreeView.ClearAll();
_childTreeView.RebuildView();
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
foreach (var packageData in debugReport.PackageDatas)
{
foreach (var operationInfo in packageData.OperationInfos)
{
var rowData = new OperationTableData();
rowData.PackageData = packageData;
rowData.OperationInfo = operationInfo;
rowData.AddStringValueCell("PackageName", packageData.PackageName);
rowData.AddStringValueCell("OperationName", operationInfo.OperationName);
rowData.AddLongValueCell("Priority", operationInfo.Priority);
rowData.AddDoubleValueCell("Progress", operationInfo.Progress);
rowData.AddStringValueCell("BeginTime", operationInfo.BeginTime);
rowData.AddLongValueCell("LoadingTime", operationInfo.ProcessTime);
rowData.AddStringValueCell("Status", operationInfo.Status.ToString());
rowData.AddStringValueCell("Desc", operationInfo.OperationDesc);
_sourceDatas.Add(rowData);
}
}
_operationTableView.itemsSource = _sourceDatas;
// 重建视图
RebuildView(null);
}
/// <summary>
/// 清空页面
/// </summary>
public void ClearView()
{
_operationTableView.ClearAll(false, true);
_childTreeView.ClearAll();
RebuildView(null);
}
/// <summary>
/// 重建视图
/// </summary>
public void RebuildView(string searchKeyWord)
{
// 搜索匹配
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
// 重建视图
_operationTableView.RebuildView();
_childTreeView.RebuildView();
}
/// <summary>
/// 挂接到父类页面上
/// </summary>
public void AttachParent(VisualElement parent)
{
parent.Add(_root);
}
/// <summary>
/// 从父类页面脱离开
/// </summary>
public void DetachParent()
{
_root.RemoveFromHierarchy();
}
private void OnOperationTableViewSelectionChanged(ITableData data)
{
var operationTableData = data as OperationTableData;
DebugPackageData packageData = operationTableData.PackageData;
DebugOperationInfo operationInfo = operationTableData.OperationInfo;
TreeNode rootNode = new TreeNode(operationInfo);
FillTreeData(operationInfo, rootNode);
_childTreeView.ClearAll();
_childTreeView.SetRootItem(rootNode);
_childTreeView.RebuildView();
}
private void MakeTreeViewItem(VisualElement container)
{
// OperationName
{
Label label = new Label();
label.name = "OperationName";
label.style.flexGrow = 0f;
label.style.width = 300;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Progress
{
var label = new Label();
label.name = "Progress";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// BeginTime
{
var label = new Label();
label.name = "BeginTime";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// ProcessTime
{
var label = new Label();
label.name = "ProcessTime";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Status
{
var label = new Label();
label.name = "Status";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Desc
{
Label label = new Label();
label.name = "Desc";
label.style.flexGrow = 1f;
label.style.width = 500;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
}
private void BindTreeViewItem(VisualElement container, object userData)
{
var operationInfo = userData as DebugOperationInfo;
// OperationName
{
var label = container.Q<Label>("OperationName");
label.text = operationInfo.OperationName;
}
// Progress
{
var label = container.Q<Label>("Progress");
label.text = operationInfo.Progress.ToString();
}
// BeginTime
{
var label = container.Q<Label>("BeginTime");
label.text = operationInfo.BeginTime;
}
// ProcessTime
{
var label = container.Q<Label>("ProcessTime");
label.text = operationInfo.ProcessTime.ToString();
}
// Status
{
StyleColor textColor;
if (operationInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var label = container.Q<Label>("Status");
label.text = operationInfo.Status;
label.style.color = textColor;
}
// Desc
{
var label = container.Q<Label>("Desc");
label.text = operationInfo.OperationDesc;
}
}
private void FillTreeData(DebugOperationInfo parentOperation, TreeNode rootNode)
{
foreach (var childOperation in parentOperation.Childs)
{
var childNode = new TreeNode(childOperation);
rootNode.AddChild(childNode);
FillTreeData(childOperation, childNode);
}
}
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2fb1b9a2a91f1af4a86acfcfac424e0b
guid: faabdaf3787cba6438d2300f7f71e26f
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,9 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<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;">
<YooAsset.Editor.TableView name="TopTableView" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="flex-grow: 1;">
<uie:Toolbar name="BottomToolbar" />
<YooAsset.Editor.TreeViewer name="BottomTreeView" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7147c7108cba1bb4dba3a2cfc758ad43
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -56,13 +56,12 @@ namespace YooAsset.Editor
_dependTableView.ClickTableDataEvent = OnClickBundleTableView;
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{

View File

@@ -61,7 +61,7 @@ namespace YooAsset.Editor
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
}
private void CreateBundleTableViewColumns()

View File

@@ -1,41 +0,0 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 显示开关(眼睛图标)
/// </summary>
public class DisplayToggle : Toggle
{
private readonly VisualElement _checkbox;
public DisplayToggle()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
/// <summary>
/// 刷新图标
/// </summary>
public void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent("animationvisibilitytoggleoff@2x").image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent("animationvisibilitytoggleon@2x").image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@@ -1,36 +0,0 @@
#if UNITY_2020_3_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 分屏控件
/// </summary>
public class PanelSplitView : TwoPaneSplitView
{
public new class UxmlFactory : UxmlFactory<PanelSplitView, UxmlTraits>
{
}
/// <summary>
/// 竖版分屏
/// </summary>
public static void SplitVerticalPanel(VisualElement root, VisualElement panelA, VisualElement panelB)
{
root.Remove(panelA);
root.Remove(panelB);
var spliteView = new PanelSplitView();
spliteView.fixedPaneInitialDimension = 300;
spliteView.orientation = TwoPaneSplitViewOrientation.Vertical;
spliteView.contentContainer.Add(panelA);
spliteView.contentContainer.Add(panelB);
root.Add(spliteView);
}
}
}
#endif

View File

@@ -0,0 +1,55 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 显示开关(眼睛图标)
/// </summary>
public class ToggleDisplay : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleDisplay, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleDisplay()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
#if UNITY_2021_3_OR_NEWER
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
#endif
private void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.VisibilityToggleOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.VisibilityToggleOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@@ -0,0 +1,55 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 折叠开关
/// </summary>
public class ToggleFoldout : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleFoldout, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleFoldout()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
#if UNITY_2021_3_OR_NEWER
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
#endif
public void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.FoldoutOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.FoldoutOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 84c10fd3507a1c24a9043aebb72db5f5
guid: 2619997e70d98794da26a947f9129e25
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,55 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 录制开关
/// </summary>
public class ToggleRecord : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleRecord, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleRecord()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
#if UNITY_2021_3_OR_NEWER
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
#endif
private void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.RecordOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.RecordOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0c3f4136cf7142346ae33e8a82cbdb27
guid: 4eace285493a0844f8a8b8f4a4ea02d8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1797f960cdbd5aa41a96bb02d16c4998
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class TreeNode
{
/// <summary>
/// 子节点集合
/// </summary>
public List<TreeNode> Children = new List<TreeNode>(10);
/// <summary>
/// 父节点
/// </summary>
public TreeNode Parent { get; set; }
/// <summary>
/// 用户数据
/// </summary>
public object UserData { get; set; }
/// <summary>
/// 是否展开
/// </summary>
public bool IsExpanded { get; set; } = false;
public TreeNode(object userData)
{
UserData = userData;
}
/// <summary>
/// 添加子节点
/// </summary>
public void AddChild(TreeNode child)
{
child.Parent = this;
Children.Add(child);
}
/// <summary>
/// 清理所有子节点
/// </summary>
public void ClearChildren()
{
foreach(var child in Children)
{
child.Parent = null;
}
Children.Clear();
}
/// <summary>
/// 计算节点的深度
/// </summary>
public int GetDepth()
{
int depth = 0;
TreeNode current = this;
while (current.Parent != null)
{
depth++;
current = current.Parent;
}
return depth;
}
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fc10550f17aaeb14795135a51444de1c
guid: 473cdc8e1dd7b0f43938ddb99287a2a8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,152 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class TreeViewer : VisualElement
{
public new class UxmlFactory : UxmlFactory<TreeViewer, UxmlTraits>
{
}
private readonly ListView _listView;
private readonly List<TreeNode> _flattenList = new List<TreeNode>(1000);
private readonly List<TreeNode> _rootList = new List<TreeNode>(100);
/// <summary>
/// 制作列表元素
/// </summary>
public Action<VisualElement> makeItem { get; set; }
/// <summary>
/// 绑定列表数据
/// </summary>
public Action<VisualElement, object> bindItem { get; set; }
public TreeViewer()
{
this.style.flexShrink = 1f;
this.style.flexGrow = 1f;
// 创建ListView
_listView = new ListView();
_listView.style.flexShrink = 1f;
_listView.style.flexGrow = 1f;
_listView.itemsSource = _flattenList;
_listView.makeItem = MakeItemInternal;
_listView.bindItem = BindItemInternal;
this.Add(_listView);
}
/// <summary>
/// 设置根节点数据
/// </summary>
public void SetRootItem(TreeNode rootNode)
{
_rootList.Add(rootNode);
}
/// <summary>
/// 设置根节点数据
/// </summary>
public void SetRootItems(List<TreeNode> rootNodes)
{
_rootList.AddRange(rootNodes);
}
/// <summary>
/// 清理数据
/// </summary>
public void ClearAll()
{
_rootList.Clear();
}
/// <summary>
/// 重新绘制视图
/// </summary>
public void RebuildView()
{
_flattenList.Clear();
foreach (var treeRoot in _rootList)
{
FlattenTree(treeRoot, 0);
}
_listView.Rebuild();
}
/// <summary>
/// 将树形结构扁平化为列表
/// </summary>
private void FlattenTree(TreeNode node, int depth)
{
_flattenList.Add(node);
if (node.IsExpanded)
{
foreach (var child in node.Children)
{
FlattenTree(child, depth + 1);
}
}
}
private VisualElement MakeItemInternal()
{
var container = new VisualElement();
container.style.flexDirection = FlexDirection.Row;
// 折叠按钮
var toggle = new ToggleFoldout();
toggle.text = string.Empty;
toggle.name = "foldout";
toggle.style.alignSelf = Align.Center;
toggle.style.width = 15;
toggle.style.height = 15;
toggle.RegisterValueChangedCallback((ChangeEvent<bool> callback) =>
{
var treeNode = toggle.userData as TreeNode;
treeNode.IsExpanded = toggle.value;
RebuildView();
});
container.Add(toggle);
// 用户自定义元素
if (makeItem != null)
{
makeItem.Invoke(container);
}
return container;
}
private void BindItemInternal(VisualElement item, int index)
{
var treeNode = _flattenList[index];
// 设置折叠状态
var toggle = item.Q<ToggleFoldout>("foldout");
toggle.SetValueWithoutNotify(treeNode.IsExpanded);
toggle.userData = treeNode;
toggle.style.marginLeft = treeNode.GetDepth() * 15;
// 隐藏折叠按钮
if (treeNode.Children.Count == 0)
{
toggle.style.visibility = Visibility.Hidden;
}
// 用户自定义元素
if (bindItem != null)
{
bindItem.Invoke(item, treeNode.UserData);
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,25 @@
#if UNITY_2019_4_OR_NEWER
namespace YooAsset.Editor
{
/// <summary>
/// 引擎图标名称
/// </summary>
public class UIElementsIcon
{
public const string RecordOn = "d_Record On@2x";
public const string RecordOff = "d_Record Off@2x";
#if UNITY_2019
public const string FoldoutOn = "IN foldout on";
public const string FoldoutOff = "IN foldout";
#else
public const string FoldoutOn = "d_IN_foldout_on@2x";
public const string FoldoutOff = "d_IN_foldout@2x";
#endif
public const string VisibilityToggleOff = "animationvisibilitytoggleoff@2x";
public const string VisibilityToggleOn = "animationvisibilitytoggleon@2x";
}
}
#endif

View File

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

View File

@@ -32,6 +32,34 @@ namespace YooAsset.Editor
label.style.minWidth = minWidth;
}
}
/// <summary>
/// 设置按钮图标
/// </summary>
public static void SetToolbarButtonIcon(ToolbarButton element, string iconName)
{
var image = EditorGUIUtility.IconContent(iconName).image as Texture2D;
element.style.backgroundImage = image;
element.text = string.Empty;
}
/// <summary>
/// 竖版分屏
/// </summary>
public static void SplitVerticalPanel(VisualElement root, VisualElement panelA, VisualElement panelB)
{
#if UNITY_2020_3_OR_NEWER
root.Remove(panelA);
root.Remove(panelB);
var spliteView = new TwoPaneSplitView();
spliteView.fixedPaneInitialDimension = 300;
spliteView.orientation = TwoPaneSplitViewOrientation.Vertical;
spliteView.contentContainer.Add(panelA);
spliteView.contentContainer.Add(panelB);
root.Add(spliteView);
#endif
}
}
}
#endif

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
[Serializable]
internal class DebugOperationInfo : IComparer<DebugOperationInfo>, IComparable<DebugOperationInfo>
{
/// <summary>
/// 任务名称
/// </summary>
public string OperationName;
/// <summary>
/// 任务说明
/// </summary>
public string OperationDesc;
/// <summary>
/// 优先级
/// </summary>
public uint Priority;
/// <summary>
/// 任务进度
/// </summary>
public float Progress;
/// <summary>
/// 任务开始的时间
/// </summary>
public string BeginTime;
/// <summary>
/// 处理耗时(单位:毫秒)
/// </summary>
public long ProcessTime;
/// <summary>
/// 任务状态
/// </summary>
public string Status;
/// <summary>
/// 子任务列表
/// TODO : Serialization depth limit 10 exceeded
/// </summary>
public List<DebugOperationInfo> Childs;
public int CompareTo(DebugOperationInfo other)
{
return Compare(this, other);
}
public int Compare(DebugOperationInfo a, DebugOperationInfo b)
{
return string.CompareOrdinal(a.OperationName, b.OperationName);
}
}
}

View File

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

View File

@@ -13,15 +13,9 @@ namespace YooAsset
/// </summary>
public string PackageName;
/// <summary>
/// 调试数据列表
/// </summary>
public List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
/// <summary>
/// 调试数据列表
/// </summary>
public List<DebugBundleInfo> BundleInfos = new List<DebugBundleInfo>(1000);
public List<DebugOperationInfo> OperationInfos = new List<DebugOperationInfo>(1000);
[NonSerialized]

View File

@@ -23,9 +23,9 @@ namespace YooAsset
public string SpawnScene;
/// <summary>
/// 资源出生的时间
/// 资源加载开始时间
/// </summary>
public string SpawnTime;
public string BeginTime;
/// <summary>
/// 加载耗时(单位:毫秒)

View File

@@ -10,6 +10,11 @@ namespace YooAsset
/// 采样一次
/// </summary>
SampleOnce = 0,
/// <summary>
/// 自动采集
/// </summary>
SampleAuto = 1,
}
[Serializable]

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{
internal class RemoteDebuggerDefine
{
public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
public static readonly Guid kMsgPlayerSendToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
public static readonly Guid kMsgEditorSendToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
}
}

View File

@@ -7,47 +7,66 @@ namespace YooAsset
{
internal class RemoteDebuggerInRuntime : MonoBehaviour
{
#if UNITY_EDITOR
/// <summary>
/// 编辑器下获取报告的回调
/// </summary>
public static Action<int, DebugReport> EditorHandleDebugReportCallback;
private static bool _sampleOnce = false;
private static bool _autoSample = false;
/// <summary>
/// 编辑器下请求报告数据
/// </summary>
public static void EditorRequestDebugReport()
private void Awake()
{
if (UnityEditor.EditorApplication.isPlaying)
{
var report = YooAssets.GetDebugReport();
EditorHandleDebugReportCallback?.Invoke(0, report);
}
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Initialize();
#endif
}
#else
private void OnEnable()
{
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#else
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#endif
}
private void OnDisable()
{
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer);
#else
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#endif
}
private void OnHandleEditorMessage(MessageEventArgs args)
private void LateUpdate()
{
if (_autoSample || _sampleOnce)
{
_sampleOnce = false;
var debugReport = YooAssets.GetDebugReport();
var data = DebugReport.Serialize(debugReport);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
#else
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
#endif
}
}
private static void OnHandleEditorMessage(MessageEventArgs args)
{
var command = RemoteCommand.Deserialize(args.data);
YooLogger.Log($"On handle remote command : {command.CommandType} Param : {command.CommandParam}");
if (command.CommandType == (int)ERemoteCommand.SampleOnce)
{
var debugReport = YooAssets.GetDebugReport();
var data = DebugReport.Serialize(debugReport);
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgSendPlayerToEditor, data);
_sampleOnce = true;
}
else if (command.CommandType == (int)ERemoteCommand.SampleAuto)
{
if (command.CommandParam == "open")
_autoSample = true;
else
_autoSample = false;
}
else
{
throw new NotImplementedException(command.CommandType.ToString());
}
}
#endif
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Networking.PlayerConnection;
using UnityEngine;
namespace YooAsset
{
internal class RemoteEditorConnection
{
private static RemoteEditorConnection _instance;
public static RemoteEditorConnection Instance
{
get
{
if (_instance == null)
_instance = new RemoteEditorConnection();
return _instance;
}
}
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
public void Initialize()
{
_messageCallbacks.Clear();
}
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback);
}
public void Unregister(Guid messageID)
{
if (_messageCallbacks.ContainsKey(messageID))
_messageCallbacks.Remove(messageID);
}
public void Send(Guid messageID, byte[] data)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
// 接收对方的消息
RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data);
}
internal void HandlePlayerMessage(Guid messageID, byte[] data)
{
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
{
var args = new MessageEventArgs();
args.playerId = 0;
args.data = data;
value?.Invoke(args);
}
}
}
}

View File

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

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Networking.PlayerConnection;
using UnityEngine;
namespace YooAsset
{
internal class RemotePlayerConnection
{
private static RemotePlayerConnection _instance;
public static RemotePlayerConnection Instance
{
get
{
if (_instance == null)
_instance = new RemotePlayerConnection();
return _instance;
}
}
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
public void Initialize()
{
_messageCallbacks.Clear();
}
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback);
}
public void Unregister(Guid messageID)
{
if (_messageCallbacks.ContainsKey(messageID))
_messageCallbacks.Remove(messageID);
}
public void Send(Guid messageID, byte[] data)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
// 接收对方的消息
RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data);
}
internal void HandleEditorMessage(Guid messageID, byte[] data)
{
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
{
var args = new MessageEventArgs();
args.playerId = 0;
args.data = data;
value?.Invoke(args);
}
}
}
}

View File

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

View File

@@ -18,9 +18,8 @@ namespace YooAsset
YooLogger.Log("Begin to create catalog file !");
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
DirectoryInfo saveDirectory = new DirectoryInfo(savePath);
if (saveDirectory.Exists)
saveDirectory.Delete(true);
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
UnityEditor.AssetDatabase.Refresh();
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);

View File

@@ -110,5 +110,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@@ -153,7 +153,10 @@ namespace YooAsset
{
var downloader = DownloadCenter.DownloadFileAsync(bundle, param);
downloader.Reference(); //增加下载器的引用计数
return downloader;
// 注意:将下载器进行包裹,可以避免父类任务终止的时候,连带子任务里的下载器也一起被终止!
var wrapper = new DownloadFileWrapper(downloader);
return wrapper;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{

View File

@@ -100,6 +100,7 @@ namespace YooAsset
if (_steps == ESteps.CreateDownloadCenter)
{
// 注意:下载中心作为独立任务运行!
if (_fileSystem.DownloadCenter == null)
{
_fileSystem.DownloadCenter = new DownloadCenterOperation(_fileSystem);

View File

@@ -54,18 +54,19 @@ namespace YooAsset
if (_steps == ESteps.DownloadFile)
{
// 注意:下载的异步任务由管理器驱动
// 注意不加到子任务列表里防止Abort的时候将下载器直接关闭
// 注意边玩边下下载器引用计数没有Release
if (_downloadFileOp == null)
{
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
}
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
_downloadFileOp.UpdateOperation();
DownloadProgress = _downloadFileOp.DownloadProgress;
DownloadedBytes = _downloadFileOp.DownloadedBytes;
if (_downloadFileOp.IsDone == false)
@@ -271,18 +272,19 @@ namespace YooAsset
if (_steps == ESteps.DownloadFile)
{
// 注意:下载的异步任务由管理器驱动
// 注意不加到子任务列表里防止Abort的时候将下载器直接关闭
// 注意边玩边下下载器引用计数没有Release
if (_downloadFileOp == null)
{
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
}
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
_downloadFileOp.UpdateOperation();
DownloadProgress = _downloadFileOp.DownloadProgress;
DownloadedBytes = _downloadFileOp.DownloadedBytes;
if (_downloadFileOp.IsDone == false)

View File

@@ -166,12 +166,6 @@ namespace YooAsset
}
internal override void InternalWaitForAsyncComplete()
{
//TODO 防止下载器挂起陷入无限死循环!
if (_steps == ESteps.None)
{
InternalStart();
}
while (true)
{
//TODO 如果是导入或解压本地文件,执行等待完毕

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
@@ -186,12 +185,6 @@ namespace YooAsset
}
internal override void InternalWaitForAsyncComplete()
{
//TODO 防止下载器挂起陷入无限死循环!
if (_steps == ESteps.None)
{
InternalStart();
}
while (true)
{
//TODO 如果是导入或解压本地文件,执行等待完毕

View File

@@ -100,5 +100,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@@ -100,5 +100,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@@ -113,6 +113,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
private string GetWebRequestURL(string fileName)
{

View File

@@ -110,5 +110,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@@ -34,11 +34,19 @@ namespace YooAsset
DownloadedBytes = 0;
DownloadProgress = 0;
}
public void Release()
/// <summary>
/// 减少引用计数
/// </summary>
public virtual void Release()
{
RefCount--;
}
public void Reference()
/// <summary>
/// 增加引用计数
/// </summary>
public virtual void Reference()
{
RefCount++;
}

View File

@@ -1,5 +1,4 @@
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{

View File

@@ -0,0 +1,71 @@

namespace YooAsset
{
internal class DownloadFileWrapper : FSDownloadFileOperation
{
private enum ESteps
{
None,
Download,
Done,
}
private readonly FSDownloadFileOperation _downloadFileOp;
private ESteps _steps = ESteps.None;
internal DownloadFileWrapper(FSDownloadFileOperation downloadFileOp) : base(downloadFileOp.Bundle)
{
_downloadFileOp = downloadFileOp;
}
internal override void InternalStart()
{
_steps = ESteps.Download;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.Download)
{
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
if (_downloadFileOp.Status == EOperationStatus.None)
return;
_downloadFileOp.UpdateOperation();
Progress = _downloadFileOp.Progress;
DownloadedBytes = _downloadFileOp.DownloadedBytes;
DownloadProgress = _downloadFileOp.DownloadProgress;
if (_downloadFileOp.IsDone == false)
return;
_steps = ESteps.Done;
Status = _downloadFileOp.Status;
Error = _downloadFileOp.Error;
HttpCode = _downloadFileOp.HttpCode;
}
}
internal override void InternalWaitForAsyncComplete()
{
while (true)
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
public override void Release()
{
_downloadFileOp.Release();
}
public override void Reference()
{
_downloadFileOp.Reference();
}
}
}

View File

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

View File

@@ -1,4 +1,5 @@

using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
@@ -25,6 +26,11 @@ namespace YooAsset
/// WebGL运行模式
/// </summary>
WebPlayMode,
/// <summary>
/// 自定义运行模式
/// </summary>
CustomPlayMode,
}
/// <summary>
@@ -67,4 +73,16 @@ namespace YooAsset
public FileSystemParameters WebServerFileSystemParameters;
public FileSystemParameters WebRemoteFileSystemParameters;
}
/// <summary>
/// 自定义运行模式的初始化参数
/// </summary>
public class CustomPlayModeParameters : InitializeParameters
{
/// <summary>
/// 文件系统初始化参数列表
/// 注意:列表最后一个元素作为主文件系统!
/// </summary>
public List<FileSystemParameters> FileSystemParameterList;
}
}

View File

@@ -8,11 +8,15 @@ namespace YooAsset
{
public abstract class AsyncOperationBase : IEnumerator, IComparable<AsyncOperationBase>
{
private readonly List<AsyncOperationBase> _childs = new List<AsyncOperationBase>(10);
private Action<AsyncOperationBase> _callback;
private string _packageName = null;
private int _whileFrame = 1000;
/// <summary>
/// 所有子任务
/// </summary>
internal readonly List<AsyncOperationBase> Childs = new List<AsyncOperationBase>(10);
/// <summary>
/// 等待异步执行完成
/// </summary>
@@ -24,12 +28,12 @@ namespace YooAsset
internal bool IsFinish { private set; get; } = false;
/// <summary>
/// 优先级
/// 任务优先级
/// </summary>
public uint Priority { set; get; } = 0;
/// <summary>
/// 状态
/// 任务状态
/// </summary>
public EOperationStatus Status { get; protected set; } = EOperationStatus.None;
@@ -109,11 +113,14 @@ namespace YooAsset
{
throw new System.NotImplementedException(this.GetType().Name);
}
internal virtual string InternalGetDesc()
{
return string.Empty;
}
/// <summary>
/// 设置包裹名称
/// </summary>
/// <param name="packageName"></param>
internal void SetPackageName(string packageName)
{
_packageName = packageName;
@@ -125,11 +132,19 @@ namespace YooAsset
internal void AddChildOperation(AsyncOperationBase child)
{
#if UNITY_EDITOR
if (_childs.Contains(child))
if (Childs.Contains(child))
throw new Exception($"The child node {child.GetType().Name} already exists !");
#endif
_childs.Add(child);
Childs.Add(child);
}
/// <summary>
/// 获取异步操作说明
/// </summary>
internal string GetOperationDesc()
{
return InternalGetDesc();
}
/// <summary>
@@ -140,6 +155,11 @@ namespace YooAsset
if (Status == EOperationStatus.None)
{
Status = EOperationStatus.Processing;
// 开始记录
DebugBeginRecording();
// 开始任务
InternalStart();
}
}
@@ -150,7 +170,13 @@ namespace YooAsset
internal void UpdateOperation()
{
if (IsDone == false)
{
// 更新记录
DebugUpdateRecording();
// 更新任务
InternalUpdate();
}
if (IsDone && IsFinish == false)
{
@@ -159,6 +185,9 @@ namespace YooAsset
// 进度百分百完成
Progress = 1f;
// 结束记录
DebugEndRecording();
//注意如果完成回调内发生异常会导致Task无限期等待
_callback?.Invoke(this);
@@ -172,7 +201,7 @@ namespace YooAsset
/// </summary>
internal void AbortOperation()
{
foreach (var child in _childs)
foreach (var child in Childs)
{
child.AbortOperation();
}
@@ -224,11 +253,67 @@ namespace YooAsset
if (IsDone)
return;
//TODO 防止异步操作被挂起陷入无限死循环!
// 例如:文件解压任务或者文件导入任务!
if (Status == EOperationStatus.None)
{
StartOperation();
}
IsWaitForAsyncComplete = true;
InternalWaitForAsyncComplete();
}
#region
/// <summary>
/// 开始的时间
/// </summary>
public string BeginTime = string.Empty;
/// <summary>
/// 处理耗时(单位:毫秒)
/// </summary>
public long ProcessTime { protected set; get; }
// 加载耗时统计
private Stopwatch _watch = null;
[Conditional("DEBUG")]
private void DebugBeginRecording()
{
if (_watch == null)
{
BeginTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
_watch = Stopwatch.StartNew();
}
}
[Conditional("DEBUG")]
private void DebugUpdateRecording()
{
if (_watch != null)
{
ProcessTime = _watch.ElapsedMilliseconds;
}
}
[Conditional("DEBUG")]
private void DebugEndRecording()
{
if (_watch != null)
{
ProcessTime = _watch.ElapsedMilliseconds;
_watch = null;
}
}
private string SpawnTimeToString(float spawnTime)
{
float h = UnityEngine.Mathf.FloorToInt(spawnTime / 3600f);
float m = UnityEngine.Mathf.FloorToInt(spawnTime / 60f - h * 60f);
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
}
#endregion
#region

View File

@@ -43,6 +43,15 @@ namespace YooAsset
/// </summary>
public static void Update()
{
// 移除已经完成的异步操作
// 注意:移除上一帧完成的异步操作,方便调试器接收到完整的信息!
for (int i = _operations.Count - 1; i >= 0; i--)
{
var operation = _operations[i];
if (operation.IsFinish)
_operations.RemoveAt(i);
}
// 添加新增的异步操作
if (_newList.Count > 0)
{
@@ -77,14 +86,6 @@ namespace YooAsset
operation.UpdateOperation();
}
// 移除已经完成的异步操作
for (int i = _operations.Count - 1; i >= 0; i--)
{
var operation = _operations[i];
if (operation.IsFinish)
_operations.RemoveAt(i);
}
}
/// <summary>
@@ -132,5 +133,39 @@ namespace YooAsset
operation.SetPackageName(packageName);
operation.StartOperation();
}
#region
internal static List<DebugOperationInfo> GetDebugOperationInfos(string packageName)
{
List<DebugOperationInfo> result = new List<DebugOperationInfo>(_operations.Count);
foreach (var operation in _operations)
{
if (operation.PackageName == packageName)
{
var operationInfo = GetDebugOperationInfo(operation);
result.Add(operationInfo);
}
}
return result;
}
internal static DebugOperationInfo GetDebugOperationInfo(AsyncOperationBase operation)
{
var operationInfo = new DebugOperationInfo();
operationInfo.OperationName = operation.GetType().Name;
operationInfo.OperationDesc = operation.GetOperationDesc();
operationInfo.Priority = operation.Priority;
operationInfo.Progress = operation.Progress;
operationInfo.BeginTime = operation.BeginTime;
operationInfo.ProcessTime = operation.ProcessTime;
operationInfo.Status = operation.Status.ToString();
operationInfo.Childs = new List<DebugOperationInfo>(operation.Childs.Count);
foreach (var child in operation.Childs)
{
var childInfo = GetDebugOperationInfo(child);
operationInfo.Childs.Add(childInfo);
}
return operationInfo;
}
#endregion
}
}

View File

@@ -151,6 +151,11 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
var assetInfo = _handle.GetAssetInfo();
return $"AssetPath : {assetInfo.AssetPath}";
}
/// <summary>
/// 取消实例化对象操作

View File

@@ -116,6 +116,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"BundleName : {LoadBundleInfo.Bundle.BundleName}";
}
/// <summary>
/// 引用(引用计数递加)

View File

@@ -110,5 +110,9 @@ namespace YooAsset
Status = EOperationStatus.Succeed;
}
}
internal override string InternalGetDesc()
{
return $"SceneName : {_provider.SceneName}";
}
}
}

View File

@@ -53,6 +53,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"LoopCount : {_loopCount}";
}
/// <summary>
/// 说明:资源包之间会有深层的依赖链表,需要多次迭代才可以在单帧内卸载!

View File

@@ -99,7 +99,6 @@ namespace YooAsset
}
internal override void InternalStart()
{
DebugBeginRecording();
_steps = ESteps.StartBundleLoader;
}
internal override void InternalUpdate()
@@ -174,6 +173,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"AssetPath : {MainAssetInfo.AssetPath}";
}
protected abstract void ProcessBundleResult();
/// <summary>
@@ -267,8 +270,6 @@ namespace YooAsset
/// </summary>
protected void InvokeCompletion(string error, EOperationStatus status)
{
DebugEndRecording();
_steps = ESteps.Done;
Error = error;
Status = status;
@@ -311,50 +312,10 @@ namespace YooAsset
/// </summary>
public string SpawnScene = string.Empty;
/// <summary>
/// 出生的时间
/// </summary>
public string SpawnTime = string.Empty;
/// <summary>
/// 加载耗时(单位:毫秒)
/// </summary>
public long LoadingTime { protected set; get; }
// 加载耗时统计
private Stopwatch _watch = null;
[Conditional("DEBUG")]
public void InitSpawnDebugInfo()
public void InitProviderDebugInfo()
{
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; ;
SpawnTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
}
private string SpawnTimeToString(float spawnTime)
{
float h = UnityEngine.Mathf.FloorToInt(spawnTime / 3600f);
float m = UnityEngine.Mathf.FloorToInt(spawnTime / 60f - h * 60f);
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
}
[Conditional("DEBUG")]
private void DebugBeginRecording()
{
if (_watch == null)
{
_watch = Stopwatch.StartNew();
}
}
[Conditional("DEBUG")]
private void DebugEndRecording()
{
if (_watch != null)
{
LoadingTime = _watch.ElapsedMilliseconds;
_watch = null;
}
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
}
/// <summary>

View File

@@ -34,7 +34,7 @@ namespace YooAsset
/// <summary>
/// 初始化
/// </summary>
public void Initialize(InitializeParameters initializeParameters, IBundleQuery bundleServices)
public void Initialize(IBundleQuery bundleServices)
{
_bundleQuery = bundleServices;
SceneManager.sceneUnloaded += OnSceneUnloaded;
@@ -119,7 +119,7 @@ namespace YooAsset
ProviderOperation provider;
{
provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
provider.InitSpawnDebugInfo();
provider.InitProviderDebugInfo();
ProviderDic.Add(providerGUID, provider);
OperationSystem.StartOperation(PackageName, provider);
}
@@ -158,7 +158,7 @@ namespace YooAsset
if (provider == null)
{
provider = new AssetProvider(this, providerGUID, assetInfo);
provider.InitSpawnDebugInfo();
provider.InitProviderDebugInfo();
ProviderDic.Add(providerGUID, provider);
OperationSystem.StartOperation(PackageName, provider);
}
@@ -194,7 +194,7 @@ namespace YooAsset
if (provider == null)
{
provider = new SubAssetsProvider(this, providerGUID, assetInfo);
provider.InitSpawnDebugInfo();
provider.InitProviderDebugInfo();
ProviderDic.Add(providerGUID, provider);
OperationSystem.StartOperation(PackageName, provider);
}
@@ -230,7 +230,7 @@ namespace YooAsset
if (provider == null)
{
provider = new AllAssetsProvider(this, providerGUID, assetInfo);
provider.InitSpawnDebugInfo();
provider.InitProviderDebugInfo();
ProviderDic.Add(providerGUID, provider);
OperationSystem.StartOperation(PackageName, provider);
}
@@ -266,7 +266,7 @@ namespace YooAsset
if (provider == null)
{
provider = new RawFileProvider(this, providerGUID, assetInfo);
provider.InitSpawnDebugInfo();
provider.InitProviderDebugInfo();
ProviderDic.Add(providerGUID, provider);
OperationSystem.StartOperation(PackageName, provider);
}
@@ -359,14 +359,6 @@ namespace YooAsset
}
#region
internal DebugPackageData GetDebugPackageData()
{
DebugPackageData data = new DebugPackageData();
data.PackageName = PackageName;
data.ProviderInfos = GetDebugProviderInfos();
data.BundleInfos = GetDebugBundleInfos();
return data;
}
internal List<DebugProviderInfo> GetDebugProviderInfos()
{
List<DebugProviderInfo> result = new List<DebugProviderInfo>(ProviderDic.Count);
@@ -375,8 +367,8 @@ namespace YooAsset
DebugProviderInfo providerInfo = new DebugProviderInfo();
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
providerInfo.SpawnScene = provider.SpawnScene;
providerInfo.SpawnTime = provider.SpawnTime;
providerInfo.LoadingTime = provider.LoadingTime;
providerInfo.BeginTime = provider.BeginTime;
providerInfo.LoadingTime = provider.ProcessTime;
providerInfo.RefCount = provider.RefCount;
providerInfo.Status = provider.Status.ToString();
providerInfo.DependBundles = provider.GetDebugDependBundles();

View File

@@ -21,6 +21,13 @@ namespace YooAsset
/// </summary>
public string Error { private set; get; }
/// <summary>
/// 资源对象
/// </summary>
internal PackageAsset Asset
{
get { return _packageAsset; }
}
/// <summary>
/// 唯一标识符

View File

@@ -27,10 +27,5 @@ namespace YooAsset
/// 获取依赖的资源包名称集合
/// </summary>
string[] GetDependBundleNames(AssetInfo assetInfo);
/// <summary>
/// 清单是否有效
/// </summary>
bool ManifestValid();
}
}

View File

@@ -36,7 +36,7 @@ namespace YooAsset
// 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout);
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout);
// 解压相关
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);

View File

@@ -1,146 +1,108 @@

using System.Collections.Generic;
using System.Linq;
namespace YooAsset
{
public abstract class ClearCacheFilesOperation : AsyncOperationBase
{
}
internal sealed class ClearCacheFilesImplOperation : ClearCacheFilesOperation
public sealed class ClearCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
None,
ClearFileSystemA,
ClearFileSystemB,
ClearFileSystemC,
Prepare,
ClearCacheFiles,
CheckClearResult,
Done,
}
private readonly IPlayMode _impl;
private readonly IFileSystem _fileSystemA;
private readonly IFileSystem _fileSystemB;
private readonly IFileSystem _fileSystemC;
private readonly PlayModeImpl _impl;
private readonly string _clearMode;
private readonly object _clearParam;
private FSClearCacheFilesOperation _clearCacheFilesOpA;
private FSClearCacheFilesOperation _clearCacheFilesOpB;
private FSClearCacheFilesOperation _clearCacheFilesOpC;
private List<IFileSystem> _cloneList;
private FSClearCacheFilesOperation _clearCacheFilesOp;
private ESteps _steps = ESteps.None;
internal ClearCacheFilesImplOperation(IPlayMode impl, IFileSystem fileSystemA, IFileSystem fileSystemB, IFileSystem fileSystemC, string clearMode, object clearParam)
internal ClearCacheFilesOperation(PlayModeImpl impl, string clearMode, object clearParam)
{
_impl = impl;
_fileSystemA = fileSystemA;
_fileSystemB = fileSystemB;
_fileSystemC = fileSystemC;
_clearMode = clearMode;
_clearParam = clearParam;
}
internal override void InternalStart()
{
_steps = ESteps.ClearFileSystemA;
_steps = ESteps.Prepare;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearFileSystemA)
if (_steps == ESteps.Prepare)
{
if (_fileSystemA == null)
{
_steps = ESteps.ClearFileSystemB;
return;
}
if (_clearCacheFilesOpA == null)
{
_clearCacheFilesOpA = _fileSystemA.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
_clearCacheFilesOpA.StartOperation();
AddChildOperation(_clearCacheFilesOpA);
}
_clearCacheFilesOpA.UpdateOperation();
Progress = _clearCacheFilesOpA.Progress;
if (_clearCacheFilesOpA.IsDone == false)
return;
if (_clearCacheFilesOpA.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearFileSystemB;
}
else
var fileSytems = _impl.FileSystems;
if (fileSytems == null || fileSytems.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheFilesOpA.Error;
Error = "The file system is empty !";
return;
}
foreach (var fileSystem in fileSytems)
{
if (fileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!";
return;
}
}
_cloneList = fileSytems.ToList();
_steps = ESteps.ClearCacheFiles;
}
if (_steps == ESteps.ClearFileSystemB)
if (_steps == ESteps.ClearCacheFiles)
{
if (_fileSystemB == null)
{
_steps = ESteps.ClearFileSystemC;
return;
}
if (_clearCacheFilesOpB == null)
{
_clearCacheFilesOpB = _fileSystemB.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
_clearCacheFilesOpB.StartOperation();
AddChildOperation(_clearCacheFilesOpB);
}
_clearCacheFilesOpB.UpdateOperation();
Progress = _clearCacheFilesOpB.Progress;
if (_clearCacheFilesOpB.IsDone == false)
return;
if (_clearCacheFilesOpB.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearFileSystemC;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheFilesOpB.Error;
}
}
if (_steps == ESteps.ClearFileSystemC)
{
if (_fileSystemC == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
if (_clearCacheFilesOpC == null)
{
_clearCacheFilesOpC = _fileSystemC.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
_clearCacheFilesOpC.StartOperation();
AddChildOperation(_clearCacheFilesOpC);
}
_clearCacheFilesOpC.UpdateOperation();
Progress = _clearCacheFilesOpC.Progress;
if (_clearCacheFilesOpC.IsDone == false)
return;
if (_clearCacheFilesOpC.Status == EOperationStatus.Succeed)
if (_cloneList.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
var fileSystem = _cloneList[0];
_cloneList.RemoveAt(0);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
_clearCacheFilesOp.StartOperation();
AddChildOperation(_clearCacheFilesOp);
_steps = ESteps.CheckClearResult;
}
}
if (_steps == ESteps.CheckClearResult)
{
_clearCacheFilesOp.UpdateOperation();
Progress = _clearCacheFilesOp.Progress;
if (_clearCacheFilesOp.IsDone == false)
return;
if (_clearCacheFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearCacheFiles;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheFilesOpC.Error;
Error = _clearCacheFilesOp.Error;
}
}
}
internal override string InternalGetDesc()
{
return $"ClearMode : {_clearMode}";
}
}
}

View File

@@ -98,5 +98,9 @@ namespace YooAsset
Status = EOperationStatus.Succeed;
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_resourcePackage.GetPackageVersion()}";
}
}
}

View File

@@ -147,6 +147,7 @@ namespace YooAsset
long downloadBytes = _cachedDownloadBytes;
foreach (var downloader in _downloaders)
{
downloader.UpdateOperation();
downloadBytes += downloader.DownloadedBytes;
if (downloader.IsDone == false)
continue;
@@ -203,6 +204,9 @@ namespace YooAsset
int index = _bundleInfoList.Count - 1;
var bundleInfo = _bundleInfoList[index];
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
downloader.StartOperation();
this.AddChildOperation(downloader);
_downloaders.Add(downloader);
_bundleInfoList.RemoveAt(index);

View File

@@ -1,73 +1,108 @@

using System.Collections.Generic;
using System.Linq;
namespace YooAsset
{
/// <summary>
/// 初始化操作
/// </summary>
public abstract class InitializationOperation : AsyncOperationBase
{
}
/// <summary>
/// 编辑器下模拟模式
/// </summary>
internal sealed class EditorSimulateModeInitializationOperation : InitializationOperation
public class InitializationOperation : AsyncOperationBase
{
private enum ESteps
{
None,
CreateFileSystem,
Prepare,
ClearOldFileSystem,
InitFileSystem,
CheckInitResult,
Done,
}
private readonly EditorSimulateModeImpl _impl;
private readonly EditorSimulateModeParameters _parameters;
private readonly PlayModeImpl _impl;
private readonly List<FileSystemParameters> _parametersList;
private List<FileSystemParameters> _cloneList;
private FSInitializeFileSystemOperation _initFileSystemOp;
private ESteps _steps = ESteps.None;
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters)
internal InitializationOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList)
{
_impl = impl;
_parameters = parameters;
_parametersList = parametersList;
}
internal override void InternalStart()
{
_steps = ESteps.CreateFileSystem;
_steps = ESteps.Prepare;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.CreateFileSystem)
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.Prepare)
{
if (_parameters.EditorFileSystemParameters == null)
if (_parametersList == null || _parametersList.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Editor file system parameters is null";
Error = "The file system parameters is empty !";
return;
}
_impl.EditorFileSystem = _parameters.EditorFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.EditorFileSystem == null)
foreach (var fileSystemParam in _parametersList)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create editor file system";
return;
if (fileSystemParam == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!";
return;
}
}
_cloneList = _parametersList.ToList();
_steps = ESteps.ClearOldFileSystem;
}
if (_steps == ESteps.ClearOldFileSystem)
{
// 注意:初始化失败后可能会残存一些旧的文件系统!
foreach (var fileSystem in _impl.FileSystems)
{
fileSystem.OnDestroy();
}
_impl.FileSystems.Clear();
_steps = ESteps.InitFileSystem;
}
if (_steps == ESteps.InitFileSystem)
{
if (_initFileSystemOp == null)
if (_cloneList.Count == 0)
{
_initFileSystemOp = _impl.EditorFileSystem.InitializeFileSystemAsync();
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
var fileSystemParams = _cloneList[0];
_cloneList.RemoveAt(0);
IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_impl.PackageName);
if (fileSystemInstance == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create file system instance !";
return;
}
_impl.FileSystems.Add(fileSystemInstance);
_initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync();
_initFileSystemOp.StartOperation();
AddChildOperation(_initFileSystemOp);
_steps = ESteps.CheckInitResult;
}
}
if (_steps == ESteps.CheckInitResult)
{
_initFileSystemOp.UpdateOperation();
Progress = _initFileSystemOp.Progress;
if (_initFileSystemOp.IsDone == false)
@@ -75,376 +110,20 @@ namespace YooAsset
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
_steps = ESteps.InitFileSystem;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initFileSystemOp.Error;
return;
}
}
}
}
/// <summary>
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
internal override string InternalGetDesc()
{
None,
CreateFileSystem,
InitFileSystem,
Done,
}
private readonly OfflinePlayModeImpl _impl;
private readonly OfflinePlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initFileSystemOp;
private ESteps _steps = ESteps.None;
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, OfflinePlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalStart()
{
_steps = ESteps.CreateFileSystem;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateFileSystem)
{
if (_parameters.BuildinFileSystemParameters == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Buildin file system parameters is null";
return;
}
_impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.BuildinFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create buildin file system";
return;
}
_steps = ESteps.InitFileSystem;
}
if (_steps == ESteps.InitFileSystem)
{
if (_initFileSystemOp == null)
{
_initFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
_initFileSystemOp.StartOperation();
AddChildOperation(_initFileSystemOp);
}
_initFileSystemOp.UpdateOperation();
Progress = _initFileSystemOp.Progress;
if (_initFileSystemOp.IsDone == false)
return;
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initFileSystemOp.Error;
}
}
}
}
/// <summary>
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
CreateBuildinFileSystem,
InitBuildinFileSystem,
CreateCacheFileSystem,
InitCacheFileSystem,
Done,
}
private readonly HostPlayModeImpl _impl;
private readonly HostPlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initBuildinFileSystemOp;
private FSInitializeFileSystemOperation _initCacheFileSystemOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, HostPlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalStart()
{
_steps = ESteps.CreateBuildinFileSystem;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateBuildinFileSystem)
{
if (_parameters.BuildinFileSystemParameters == null)
{
_steps = ESteps.CreateCacheFileSystem;
return;
}
_impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.BuildinFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create buildin file system";
return;
}
_steps = ESteps.InitBuildinFileSystem;
}
if (_steps == ESteps.InitBuildinFileSystem)
{
if (_initBuildinFileSystemOp == null)
{
_initBuildinFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
_initBuildinFileSystemOp.StartOperation();
AddChildOperation(_initBuildinFileSystemOp);
}
_initBuildinFileSystemOp.UpdateOperation();
Progress = _initBuildinFileSystemOp.Progress;
if (_initBuildinFileSystemOp.IsDone == false)
return;
if (_initBuildinFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.CreateCacheFileSystem;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initBuildinFileSystemOp.Error;
}
}
if (_steps == ESteps.CreateCacheFileSystem)
{
if (_parameters.CacheFileSystemParameters == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Cache file system parameters is null";
return;
}
_impl.CacheFileSystem = _parameters.CacheFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.CacheFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create cache file system";
return;
}
_steps = ESteps.InitCacheFileSystem;
}
if (_steps == ESteps.InitCacheFileSystem)
{
if (_initCacheFileSystemOp == null)
{
_initCacheFileSystemOp = _impl.CacheFileSystem.InitializeFileSystemAsync();
_initCacheFileSystemOp.StartOperation();
AddChildOperation(_initCacheFileSystemOp);
}
_initCacheFileSystemOp.UpdateOperation();
Progress = _initCacheFileSystemOp.Progress;
if (_initCacheFileSystemOp.IsDone == false)
return;
if (_initCacheFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initCacheFileSystemOp.Error;
}
}
}
}
/// <summary>
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
CreateWebServerFileSystem,
InitWebServerFileSystem,
CreateWebRemoteFileSystem,
InitWebRemoteFileSystem,
CheckResult,
Done,
}
private readonly WebPlayModeImpl _impl;
private readonly WebPlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initWebServerFileSystemOp;
private FSInitializeFileSystemOperation _initWebRemoteFileSystemOp;
private ESteps _steps = ESteps.None;
internal WebPlayModeInitializationOperation(WebPlayModeImpl impl, WebPlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalStart()
{
_steps = ESteps.CreateWebServerFileSystem;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateWebServerFileSystem)
{
if (_parameters.WebServerFileSystemParameters == null)
{
_steps = ESteps.CreateWebRemoteFileSystem;
return;
}
_impl.WebServerFileSystem = _parameters.WebServerFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.WebServerFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create web server file system";
return;
}
_steps = ESteps.InitWebServerFileSystem;
}
if (_steps == ESteps.InitWebServerFileSystem)
{
if (_initWebServerFileSystemOp == null)
{
_initWebServerFileSystemOp = _impl.WebServerFileSystem.InitializeFileSystemAsync();
_initWebServerFileSystemOp.StartOperation();
AddChildOperation(_initWebServerFileSystemOp);
}
_initWebServerFileSystemOp.UpdateOperation();
Progress = _initWebServerFileSystemOp.Progress;
if (_initWebServerFileSystemOp.IsDone == false)
return;
if (_initWebServerFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.CreateWebRemoteFileSystem;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initWebServerFileSystemOp.Error;
}
}
if (_steps == ESteps.CreateWebRemoteFileSystem)
{
if (_parameters.WebRemoteFileSystemParameters == null)
{
_steps = ESteps.CheckResult;
return;
}
_impl.WebRemoteFileSystem = _parameters.WebRemoteFileSystemParameters.CreateFileSystem(_impl.PackageName);
if (_impl.WebRemoteFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create web remote file system";
return;
}
_steps = ESteps.InitWebRemoteFileSystem;
}
if (_steps == ESteps.InitWebRemoteFileSystem)
{
if (_initWebRemoteFileSystemOp == null)
{
_initWebRemoteFileSystemOp = _impl.WebRemoteFileSystem.InitializeFileSystemAsync();
_initWebRemoteFileSystemOp.StartOperation();
AddChildOperation(_initWebRemoteFileSystemOp);
}
_initWebRemoteFileSystemOp.UpdateOperation();
Progress = _initWebRemoteFileSystemOp.Progress;
if (_initWebRemoteFileSystemOp.IsDone == false)
return;
if (_initWebRemoteFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.CheckResult;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initWebRemoteFileSystemOp.Error;
}
}
if (_steps == ESteps.CheckResult)
{
if (_impl.WebServerFileSystem == null && _impl.WebRemoteFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Not found any file system !";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
return $"PlayMode : {_impl.PlayMode}";
}
}
}

View File

@@ -4,132 +4,7 @@ using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
/// 预下载内容
/// 说明:目前只支持联机模式
/// </summary>
public abstract class PreDownloadContentOperation : AsyncOperationBase
{
/// <summary>
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public abstract ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public abstract ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public abstract ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="location">资源定位地址</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public abstract ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源定位地址列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public abstract ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
}
internal class EditorSimulateModePreDownloadContentOperation : PreDownloadContentOperation
{
private readonly EditorSimulateModeImpl _impl;
public EditorSimulateModePreDownloadContentOperation(EditorSimulateModeImpl impl)
{
_impl = impl;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation
{
private readonly OfflinePlayModeImpl _impl;
public OfflinePlayModePreDownloadContentOperation(OfflinePlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation
public sealed class PreDownloadContentOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -140,7 +15,7 @@ namespace YooAsset
Done,
}
private readonly HostPlayModeImpl _impl;
private readonly PlayModeImpl _impl;
private readonly string _packageVersion;
private readonly int _timeout;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
@@ -148,7 +23,7 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
internal HostPlayModePreDownloadContentOperation(HostPlayModeImpl impl, string packageVersion, int timeout)
internal PreDownloadContentOperation(PlayModeImpl impl, string packageVersion, int timeout)
{
_impl = impl;
_packageVersion = packageVersion;
@@ -196,7 +71,8 @@ namespace YooAsset
{
if (_loadPackageManifestOp == null)
{
_loadPackageManifestOp = _impl.CacheFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
var mainFileSystem = _impl.GetMainFileSystem();
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
}
@@ -220,7 +96,13 @@ namespace YooAsset
}
}
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
/// <summary>
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
if (Status != EOperationStatus.Succeed)
{
@@ -228,11 +110,19 @@ namespace YooAsset
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(_manifest, _impl.BuildinFileSystem, _impl.CacheFileSystem);
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
if (Status != EOperationStatus.Succeed)
{
@@ -240,11 +130,19 @@ namespace YooAsset
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, new string[] { tag }, _impl.BuildinFileSystem, _impl.CacheFileSystem);
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
if (Status != EOperationStatus.Succeed)
{
@@ -252,11 +150,19 @@ namespace YooAsset
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, tags, _impl.BuildinFileSystem, _impl.CacheFileSystem);
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="location">资源定位地址</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
if (Status != EOperationStatus.Succeed)
{
@@ -268,11 +174,19 @@ namespace YooAsset
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.CacheFileSystem);
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源定位地址列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
if (Status != EOperationStatus.Succeed)
{
@@ -287,46 +201,9 @@ namespace YooAsset
assetInfos.Add(assetInfo);
}
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.CacheFileSystem);
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
}
internal class WebPlayModePreDownloadContentOperation : PreDownloadContentOperation
{
private readonly WebPlayModeImpl _impl;
public WebPlayModePreDownloadContentOperation(WebPlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
}

View File

@@ -1,9 +1,6 @@

namespace YooAsset
{
/// <summary>
/// 查询远端包裹的最新版本
/// </summary>
public abstract class RequestPackageVersionOperation : AsyncOperationBase
{
/// <summary>
@@ -20,15 +17,15 @@ namespace YooAsset
Done,
}
private readonly IFileSystem _fileSystem;
private readonly PlayModeImpl _impl;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private FSRequestPackageVersionOperation _requestPackageVersionOp;
private ESteps _steps = ESteps.None;
internal RequestPackageVersionImplOperation(IFileSystem fileSystem, bool appendTimeTicks, int timeout)
internal RequestPackageVersionImplOperation(PlayModeImpl impl, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_impl = impl;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
@@ -45,7 +42,8 @@ namespace YooAsset
{
if (_requestPackageVersionOp == null)
{
_requestPackageVersionOp = _fileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
var mainFileSystem = _impl.GetMainFileSystem();
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
_requestPackageVersionOp.StartOperation();
AddChildOperation(_requestPackageVersionOp);
}

View File

@@ -1,13 +1,7 @@

namespace YooAsset
{
/// <summary>
/// 向远端请求并更新清单
/// </summary>
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
{
}
internal sealed class UpdatePackageManifestImplOperation : UpdatePackageManifestOperation
public sealed class UpdatePackageManifestOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -18,18 +12,15 @@ namespace YooAsset
Done,
}
private readonly IPlayMode _impl;
private readonly IFileSystem _fileSystem;
private readonly PlayModeImpl _impl;
private readonly string _packageVersion;
private readonly int _timeout;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
internal UpdatePackageManifestImplOperation(IPlayMode impl, IFileSystem fileSystem, string packageVersion, int timeout)
internal UpdatePackageManifestOperation(PlayModeImpl impl, string packageVersion, int timeout)
{
_impl = impl;
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
@@ -74,7 +65,8 @@ namespace YooAsset
{
if (_loadPackageManifestOp == null)
{
_loadPackageManifestOp = _fileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
var mainFileSystem = _impl.GetMainFileSystem();
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
}
@@ -97,5 +89,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion}";
}
}
}

View File

@@ -147,22 +147,6 @@ namespace YooAsset
return string.Empty;
}
/// <summary>
/// 获取主资源包
/// 注意:传入的资源路径一定合法有效!
/// </summary>
public PackageBundle GetMainPackageBundle(string assetPath)
{
if (AssetDic.TryGetValue(assetPath, out PackageAsset packageAsset))
{
return GetMainPackageBundle(packageAsset.BundleID);
}
else
{
throw new Exception("Should never get here !");
}
}
/// <summary>
/// 获取主资源包
/// 注意传入的资源包ID一定合法有效
@@ -181,25 +165,27 @@ namespace YooAsset
}
/// <summary>
/// 获取资源依赖列表
/// 注意:传入的资源路径一定合法有效!
/// 获取资源
/// 注意:传入的资源对象一定合法有效!
/// </summary>
public PackageBundle[] GetAllDependencies(string assetPath)
public PackageBundle GetMainPackageBundle(PackageAsset packageAsset)
{
if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
return GetMainPackageBundle(packageAsset.BundleID);
}
/// <summary>
/// 获取资源依赖列表
/// 注意:传入的资源对象一定合法有效!
/// </summary>
public PackageBundle[] GetAllDependencies(PackageAsset packageAsset)
{
List<PackageBundle> result = new List<PackageBundle>(packageAsset.DependBundleIDs.Length);
foreach (var dependID in packageAsset.DependBundleIDs)
{
List<PackageBundle> result = new List<PackageBundle>(packageAsset.DependBundleIDs.Length);
foreach (var dependID in packageAsset.DependBundleIDs)
{
var dependBundle = GetMainPackageBundle(dependID);
result.Add(dependBundle);
}
return result.ToArray();
}
else
{
throw new Exception("Should never get here !");
var dependBundle = GetMainPackageBundle(dependID);
result.Add(dependBundle);
}
return result.ToArray();
}
/// <summary>

View File

@@ -1,173 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class EditorSimulateModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public IFileSystem EditorFileSystem { set; get; }
public EditorSimulateModeImpl(string packageName)
{
PackageName = packageName;
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(EditorSimulateModeParameters initParameters)
{
var operation = new EditorSimulateModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
#region IPlayMode接口
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.DestroyFileSystem()
{
if (EditorFileSystem != null)
EditorFileSystem.OnDestroy();
}
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new RequestPackageVersionImplOperation(EditorFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
var operation = new UpdatePackageManifestImplOperation(this, EditorFileSystem, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new EditorSimulateModePreDownloadContentOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesImplOperation(this, EditorFileSystem, null, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, EditorFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, EditorFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, EditorFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
if (EditorFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(EditorFileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
result.Add(bundleInfo);
}
return result.ToArray();
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
result.Add(packageBundle.BundleName);
}
return result.ToArray();
}
bool IBundleQuery.ManifestValid()
{
return ActiveManifest != null;
}
#endregion
}
}

View File

@@ -1,181 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class HostPlayModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public IFileSystem BuildinFileSystem { set; get; } //可以为空!
public IFileSystem CacheFileSystem { set; get; }
public HostPlayModeImpl(string packageName)
{
PackageName = packageName;
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(HostPlayModeParameters initParameters)
{
var operation = new HostPlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
#region IPlayMode接口
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.DestroyFileSystem()
{
if (BuildinFileSystem != null)
BuildinFileSystem.OnDestroy();
if (CacheFileSystem != null)
CacheFileSystem.OnDestroy();
}
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new RequestPackageVersionImplOperation(CacheFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
var operation = new UpdatePackageManifestImplOperation(this, CacheFileSystem, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new HostPlayModePreDownloadContentOperation(this, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, CacheFileSystem, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem, CacheFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
if (BuildinFileSystem != null && BuildinFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle);
return bundleInfo;
}
if (CacheFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(CacheFileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
result.Add(bundleInfo);
}
return result.ToArray();
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
result.Add(packageBundle.BundleName);
}
return result.ToArray();
}
bool IBundleQuery.ManifestValid()
{
return ActiveManifest != null;
}
#endregion
}
}

View File

@@ -1,173 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class OfflinePlayModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public IFileSystem BuildinFileSystem { set; get; }
public OfflinePlayModeImpl(string packageName)
{
PackageName = packageName;
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(OfflinePlayModeParameters initParameters)
{
var operation = new OfflinePlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
#region IPlayMode接口
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.DestroyFileSystem()
{
if (BuildinFileSystem != null)
BuildinFileSystem.OnDestroy();
}
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new RequestPackageVersionImplOperation(BuildinFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
var operation = new UpdatePackageManifestImplOperation(this, BuildinFileSystem, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new OfflinePlayModePreDownloadContentOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, null, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
if (BuildinFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
result.Add(bundleInfo);
}
return result.ToArray();
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
result.Add(packageBundle.BundleName);
}
return result.ToArray();
}
bool IBundleQuery.ManifestValid()
{
return ActiveManifest != null;
}
#endregion
}
}

View File

@@ -1,258 +0,0 @@
using System;
using System.Collections.Generic;
namespace YooAsset
{
internal class PlayModeHelper
{
public static List<BundleInfo> GetDownloadListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
// 如果未带任何标记,则统一下载
if (packageBundle.HasAnyTags() == false)
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
else
{
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
}
return result;
}
public static List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
// 获取资源对象的资源包和所有依赖资源包
List<PackageBundle> checkList = new List<PackageBundle>();
foreach (var assetInfo in assetInfos)
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
continue;
}
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundle in dependBundles)
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
}
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in checkList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetUnpackListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
public static List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>();
foreach (var filePath in filePaths)
{
string fileName = System.IO.Path.GetFileName(filePath);
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.NeedImport(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.NeedImport(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.NeedImport(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath);
result.Add(bundleInfo);
}
else
{
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
}
}
return result;
}
}
}

View File

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

View File

@@ -0,0 +1,436 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class PlayModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public readonly EPlayMode PlayMode;
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
public PlayModeImpl(string packageName, EPlayMode playMode)
{
PackageName = packageName;
PlayMode = playMode;
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameter)
{
var fileSystemParamList = new List<FileSystemParameters>();
if (fileSystemParameter != null)
fileSystemParamList.Add(fileSystemParameter);
return InitializeAsync(fileSystemParamList);
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameterA, FileSystemParameters fileSystemParameterB)
{
var fileSystemParamList = new List<FileSystemParameters>();
if (fileSystemParameterA != null)
fileSystemParamList.Add(fileSystemParameterA);
if (fileSystemParameterB != null)
fileSystemParamList.Add(fileSystemParameterB);
return InitializeAsync(fileSystemParamList);
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(List<FileSystemParameters> fileSystemParameterList)
{
var operation = new InitializationOperation(this, fileSystemParameterList);
return operation;
}
#region IPlayMode接口
/// <summary>
/// 当前激活的清单
/// </summary>
public PackageManifest ActiveManifest { set; get; }
/// <summary>
/// 销毁文件系统
/// </summary>
void IPlayMode.DestroyFileSystem()
{
foreach (var fileSystem in FileSystems)
{
fileSystem.OnDestroy();
}
FileSystems.Clear();
}
/// <summary>
/// 向网络端请求最新的资源版本
/// </summary>
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new RequestPackageVersionImplOperation(this, appendTimeTicks, timeout);
return operation;
}
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
var operation = new UpdatePackageManifestOperation(this, packageVersion, timeout);
return operation;
}
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new PreDownloadContentOperation(this, packageVersion, timeout);
return operation;
}
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesOperation(this, clearMode, clearParam);
return operation;
}
// 下载相关
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
// 解压相关
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
// 导入相关
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem != null)
{
BundleInfo bundleInfo = new BundleInfo(fileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
return CreateBundleInfo(packageBundle);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
result.Add(bundleInfo);
}
return result.ToArray();
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
result.Add(packageBundle.BundleName);
}
return result.ToArray();
}
#endregion
/// <summary>
/// 获取主文件系统
/// 说明:文件系统列表里,最后一个属于主文件系统
/// </summary>
public IFileSystem GetMainFileSystem()
{
int count = FileSystems.Count;
if (count == 0)
return null;
return FileSystems[count - 1];
}
/// <summary>
/// 获取资源包所属文件系统
/// </summary>
public IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
{
for (int i = 0; i < FileSystems.Count; i++)
{
IFileSystem fileSystem = FileSystems[i];
if (fileSystem.Belong(packageBundle))
{
return fileSystem;
}
}
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
return null;
}
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedDownload(packageBundle))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedDownload(packageBundle))
{
// 如果未带任何标记,则统一下载
if (packageBundle.HasAnyTags() == false)
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
else
{
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
}
}
return result;
}
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
{
if (manifest == null)
return new List<BundleInfo>();
// 获取资源对象的资源包和所有依赖资源包
List<PackageBundle> checkList = new List<PackageBundle>();
foreach (var assetInfo in assetInfos)
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
continue;
}
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.Asset);
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle[] mainDependBundles = manifest.GetAllDependencies(assetInfo.Asset);
foreach (var dependBundle in mainDependBundles)
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
// 下载主资源包内所有资源对象依赖的资源包
if (recursiveDownload)
{
foreach (var otherMainAsset in mainBundle.IncludeMainAssets)
{
var otherMainBundle = manifest.GetMainPackageBundle(otherMainAsset.BundleID);
if (checkList.Contains(otherMainBundle) == false)
checkList.Add(otherMainBundle);
PackageBundle[] otherDependBundles = manifest.GetAllDependencies(otherMainAsset);
foreach (var dependBundle in otherDependBundles)
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
}
}
}
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in checkList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedDownload(packageBundle))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
public List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedUnpack(packageBundle))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
public List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedUnpack(packageBundle))
{
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
}
return result;
}
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>();
foreach (var filePath in filePaths)
{
string fileName = System.IO.Path.GetFileName(filePath);
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedImport(packageBundle))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath);
result.Add(bundleInfo);
}
}
else
{
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
}
}
return result;
}
}
}

View File

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

View File

@@ -1,201 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class WebPlayModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public IFileSystem WebServerFileSystem { set; get; } //可以为空!
public IFileSystem WebRemoteFileSystem { set; get; } //可以为空!
public WebPlayModeImpl(string packageName)
{
PackageName = packageName;
}
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(WebPlayModeParameters initParameters)
{
var operation = new WebPlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
#region IPlayMode接口
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.DestroyFileSystem()
{
if (WebServerFileSystem != null)
WebServerFileSystem.OnDestroy();
if (WebRemoteFileSystem != null)
WebRemoteFileSystem.OnDestroy();
}
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
if (WebRemoteFileSystem != null)
{
var operation = new RequestPackageVersionImplOperation(WebRemoteFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else
{
var operation = new RequestPackageVersionImplOperation(WebServerFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
if (WebRemoteFileSystem != null)
{
var operation = new UpdatePackageManifestImplOperation(this, WebRemoteFileSystem, packageVersion, timeout); ;
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else
{
var operation = new UpdatePackageManifestImplOperation(this, WebServerFileSystem, packageVersion, timeout); ;
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new WebPlayModePreDownloadContentOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
if (WebServerFileSystem != null && WebServerFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(WebServerFileSystem, packageBundle);
return bundleInfo;
}
if (WebRemoteFileSystem != null && WebRemoteFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(WebRemoteFileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
result.Add(bundleInfo);
}
return result.ToArray();
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
result.Add(packageBundle.BundleName);
}
return result.ToArray();
}
bool IBundleQuery.ManifestValid()
{
return ActiveManifest != null;
}
#endregion
}
}

View File

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

View File

@@ -96,47 +96,38 @@ namespace YooAsset
}
// 创建资源管理器
InitializationOperation initializeOperation;
_resourceManager = new ResourceManager(PackageName);
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
_bundleQuery = playModeImpl;
_playModeImpl = playModeImpl;
_resourceManager.Initialize(_bundleQuery);
// 初始化资源系统
InitializationOperation initializeOperation;
if (_playMode == EPlayMode.EditorSimulateMode)
{
var editorSimulateModeImpl = new EditorSimulateModeImpl(PackageName);
_bundleQuery = editorSimulateModeImpl;
_playModeImpl = editorSimulateModeImpl;
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters);
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters);
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var offlinePlayModeImpl = new OfflinePlayModeImpl(PackageName);
_bundleQuery = offlinePlayModeImpl;
_playModeImpl = offlinePlayModeImpl;
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as OfflinePlayModeParameters;
initializeOperation = offlinePlayModeImpl.InitializeAsync(initializeParameters);
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
}
else if (_playMode == EPlayMode.HostPlayMode)
{
var hostPlayModeImpl = new HostPlayModeImpl(PackageName);
_bundleQuery = hostPlayModeImpl;
_playModeImpl = hostPlayModeImpl;
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(initializeParameters);
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
}
else if (_playMode == EPlayMode.WebPlayMode)
{
var webPlayModeImpl = new WebPlayModeImpl(PackageName);
_bundleQuery = webPlayModeImpl;
_playModeImpl = webPlayModeImpl;
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(initializeParameters);
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
}
else if (_playMode == EPlayMode.CustomPlayMode)
{
var initializeParameters = parameters as CustomPlayModeParameters;
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList);
}
else
{
@@ -145,6 +136,7 @@ namespace YooAsset
// 监听初始化结果
_isInitialize = true;
OperationSystem.StartOperation(PackageName, initializeOperation);
initializeOperation.Completed += InitializeOperation_Completed;
return initializeOperation;
}
@@ -179,6 +171,8 @@ namespace YooAsset
_playMode = EPlayMode.HostPlayMode;
else if (parameters is WebPlayModeParameters)
_playMode = EPlayMode.WebPlayMode;
else if (parameters is CustomPlayModeParameters)
_playMode = EPlayMode.CustomPlayMode;
else
throw new NotImplementedException();
@@ -224,7 +218,9 @@ namespace YooAsset
public RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
{
DebugCheckInitialize(false);
return _playModeImpl.RequestPackageVersionAsync(appendTimeTicks, timeout);
var operation = _playModeImpl.RequestPackageVersionAsync(appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
@@ -242,7 +238,9 @@ namespace YooAsset
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
}
return _playModeImpl.UpdatePackageManifestAsync(packageVersion, timeout);
var operation = _playModeImpl.UpdatePackageManifestAsync(packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
@@ -253,7 +251,9 @@ namespace YooAsset
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
{
DebugCheckInitialize(false);
return _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
var operation = _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
@@ -264,7 +264,9 @@ namespace YooAsset
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
{
DebugCheckInitialize();
return _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
@@ -275,7 +277,9 @@ namespace YooAsset
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
{
DebugCheckInitialize();
return _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -984,25 +988,31 @@ namespace YooAsset
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
DebugCheckInitialize();
var assetInfo = ConvertLocationToAssetInfo(location, null);
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
}
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain, timeout);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源的定位地址列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
DebugCheckInitialize();
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
@@ -1011,34 +1021,48 @@ namespace YooAsset
var assetInfo = ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
}
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain, timeout);
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
}
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain, timeout);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
DebugCheckInitialize();
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain, timeout);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="assetInfos">资源信息列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain, timeout);
}
#endregion
@@ -1142,7 +1166,12 @@ namespace YooAsset
#region
internal DebugPackageData GetDebugPackageData()
{
return _resourceManager.GetDebugPackageData();
DebugPackageData data = new DebugPackageData();
data.PackageName = PackageName;
data.ProviderInfos = _resourceManager.GetDebugProviderInfos();
data.BundleInfos = _resourceManager.GetDebugBundleInfos();
data.OperationInfos = OperationSystem.GetDebugOperationInfos(PackageName);
return data;
}
#endregion
}

View File

@@ -88,7 +88,7 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Wechat platform not support sync load method !";
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}

View File

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