Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 820494b

Browse files
committed
增加单个文件的更新接口
1 parent c86ed32 commit 820494b

File tree

5 files changed

+85
-40
lines changed

5 files changed

+85
-40
lines changed

GameFramework/Editor/AssetManagement/AddressablesEditor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,28 @@ public static string ShellBuild(string activeProfileId = "Default")
7171
return "";
7272
}
7373

74+
75+
[MenuItem("Tools/Asset Management/Addressables Player Content")]
76+
private static void BuildPlayerContent()
77+
{
78+
ShellBuildPlayerContent();
79+
}
80+
7481
public static void ShellBuildPlayerContent(string activeProfileId = "Default")
7582
{
7683
var settings = AddressableAssetSettingsDefaultObject.Settings;
77-
if (settings != null && settings.BuildRemoteCatalog)
84+
if (settings != null)
7885
{
7986
var profileId = settings.profileSettings.GetProfileId(activeProfileId);
8087
settings.activeProfileId = profileId;
88+
89+
AddressableAssetSettings.CleanPlayerContent(settings.ActivePlayerDataBuilder);
8190
}
8291
AddressableAssetSettings.BuildPlayerContent();
8392
EditorUtility.SetDirty(settings);
8493
AssetDatabase.Refresh();
94+
//BuildPlayerWindow.RegisterBuildPlayerHandler
95+
//BuildPlayerWindow.DefaultBuildMethods.BuildPlayer();
8596
}
8697

8798
}

GameFramework/Editor/AssetManagement/AssetGroupEditor.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ private void OnMenuInit()
136136
{
137137
continue;
138138
}
139-
if (group.GetAssetEntry(guid) == null)
139+
var entry = group.GetAssetEntry(guid);
140+
if (entry == null)
140141
{
141-
var entry = settings.CreateOrMoveEntry(guid, group);
142-
foreach (var itemLabel in labels)
143-
{
144-
entry.SetLabel(itemLabel, true);
145-
}
142+
entry = settings.CreateOrMoveEntry(guid, group);
143+
}
144+
entry.labels.Clear();
145+
foreach (var itemLabel in labels)
146+
{
147+
entry.SetLabel(itemLabel, true);
146148
}
147149
}
148150
}

GameFramework/Runtime/Resource/AddressableVersion.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public override async void CheckUpdate(Action<bool> needUpdate)
3636
/// <param name="downloadComplete">下载完成</param>
3737
/// <param name="errorCallback">下载错误</param>
3838
/// <returns></returns>
39-
public override async void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback)
39+
public override async void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback,string label)
4040
{
4141
try
4242
{
4343
if (_isCheckUpdate)
4444
{
45+
bool hasLabel = !string.IsNullOrEmpty(label);
46+
4547
if (_checkHandle.Result.Count > 0)
4648
{
4749
var updateHandle = Addressables.UpdateCatalogs(_checkHandle.Result, false);
@@ -56,10 +58,25 @@ public override async void UpdateResource(Action<float, double, double, float> c
5658
long downloadSize = sizeHandle.Result;
5759
if (downloadSize > 0)
5860
{
59-
totalDownloadSize += downloadSize;
60-
foreach (var key in locator.Keys)
61+
if (hasLabel)
62+
{
63+
foreach (var key in locator.Keys)
64+
{
65+
if (key.ToString().Equals(label))
66+
{
67+
totalDownloadSize += downloadSize;
68+
downloadKeys.Add(key);
69+
break;
70+
}
71+
}
72+
}
73+
else
6174
{
62-
downloadKeys.Add(key);
75+
totalDownloadSize += downloadSize;
76+
foreach (var key in locator.Keys)
77+
{
78+
downloadKeys.Add(key);
79+
}
6380
}
6481
}
6582
}

GameFramework/Runtime/Resource/IResourceVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public T Cast<T>() where T : IResourceVersion
2525
/// <param name="downloadComplete">下载完成</param>
2626
/// <param name="errorCallback">下载错误</param>
2727
/// <returns></returns>
28-
public abstract void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback);
28+
public abstract void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback,string key=null);
2929

3030
}
3131
}

GameFramework/Runtime/Resource/ResourceVersion.cs

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,54 @@ public bool CheckResource()
186186
return false;
187187
}
188188

189+
///// <summary>
190+
///// 更新资源
191+
///// </summary>
192+
///// <param name="callback">下载回调[进度(0-1),大小(KB),速度(KB/S),剩余时间(s)]</param>
193+
///// <param name="downloadComplete">下载完成</param>
194+
///// <param name="errorCallback">下载错误</param>
195+
///// <param name="name">是否是更新单个资源,需要更新则传单个文件的名称</param>
196+
///// <returns></returns>
197+
//public bool UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback,string name=null)
198+
//{
199+
// if (_updating)
200+
// return false;
201+
202+
// if (string.IsNullOrEmpty(name) && !CheckResource())
203+
// {
204+
// return false;
205+
// }
206+
207+
// _updating = true;
208+
// //整理下载资源
209+
// CollateDownloadResources((needDownloadFiles)=> {
210+
// DownloadFiles(needDownloadFiles, callback, downloadComplete, errorCallback);
211+
// }, name);
212+
// return true;
213+
//}
214+
189215
/// <summary>
190216
/// 更新资源
191217
/// </summary>
192-
/// <param name="callback">下载回调[进度(0-1),大小(KB),速度(KB/S),剩余时间(s)]</param>
193-
/// <param name="downloadComplete">下载完成</param>
194-
/// <param name="errorCallback">下载错误</param>
195-
/// <param name="name">是否是更新单个资源,需要更新则传单个文件的名称</param>
196-
/// <returns></returns>
197-
public bool UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback,string name=null)
218+
/// <param name="callback"></param>
219+
/// <param name="downloadComplete"></param>
220+
/// <param name="errorCallback"></param>
221+
public override void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback, string name)
198222
{
199-
if (_updating)
200-
return false;
201-
202-
if (string.IsNullOrEmpty(name) && !CheckResource())
223+
if (!_updating)
203224
{
204-
return false;
205-
}
225+
if(string.IsNullOrEmpty(name) && !CheckResource())
226+
{
227+
return;
228+
}
206229

207-
_updating = true;
208-
//整理下载资源
209-
CollateDownloadResources((needDownloadFiles)=> {
210-
DownloadFiles(needDownloadFiles, callback, downloadComplete, errorCallback);
211-
}, name);
212-
return true;
230+
_updating = true;
231+
//整理下载资源
232+
CollateDownloadResources((needDownloadFiles) =>
233+
{
234+
DownloadFiles(needDownloadFiles, callback, downloadComplete, errorCallback);
235+
}, name);
236+
}
213237
}
214238

215239
/// <summary>
@@ -241,16 +265,7 @@ public async void CheckResource(string name, Action<bool,bool> callback)
241265
}
242266
}
243267

244-
/// <summary>
245-
/// 更新资源
246-
/// </summary>
247-
/// <param name="callback"></param>
248-
/// <param name="downloadComplete"></param>
249-
/// <param name="errorCallback"></param>
250-
public override void UpdateResource(Action<float, double, double, float> callback, Action downloadComplete, Action<string, string> errorCallback)
251-
{
252-
bool result = UpdateResource(callback,downloadComplete,errorCallback,null);
253-
}
268+
254269

255270

256271
#region 事件回调

0 commit comments

Comments
 (0)