Skip to content

Commit b0f4034

Browse files
committed
✨ 更新加载
1 parent 16dc583 commit b0f4034

File tree

3 files changed

+75
-65
lines changed

3 files changed

+75
-65
lines changed

Editor/Windows/Page/4AssetPage.LookCollect.cs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using UnityEditor;
@@ -43,11 +44,11 @@ public void Dispose()
4344

4445
#endregion
4546

46-
private Dictionary<string, string[]> DisplayGroupNames;
47-
private Dictionary<(int, int), string[]> CollectorDisplays;
48-
private Dictionary<(int, int), string[]> TypeDisplays;
49-
private Dictionary<(int, int), string[]> TagDisplays;
50-
private Dictionary<(int, int), List<AssetDataInfo>> DataDic;
47+
private Dictionary<string, string[]> DisplayGroupNames;
48+
private Dictionary<(int, int), string[]> CollectorDisplays;
49+
private Dictionary<(int, int), string[]> TypeDisplays;
50+
private Dictionary<(int, int), string[]> TagDisplays;
51+
private Dictionary<(int, int), ConcurrentBag<AssetDataInfo>> DataDic;
5152

5253
public void OnDrawHeader(Rect rect)
5354
{
@@ -193,47 +194,61 @@ private void UpdateDataCollector(int packageIndex, int groupIndex)
193194
|| Data.Packages[i].Count <= j
194195
) return;
195196

196-
var key = (i, j);
197-
DisplayGroupNames[DisplayPackages[i]] = GetGroupDisPlayNames(Data.Packages[i].Groups);
198-
TagDisplays[key] = Data.Packages[i].Groups[j].Tags;
199-
CollectorDisplays[key] = GetCollectorDisPlayNames(Data.Packages[i].Groups[j].Collectors.GetDisPlayNames());
197+
var key = (i, j);
198+
var package = Data.Packages[i];
199+
var group = package.Groups[j];
200+
201+
DisplayGroupNames[DisplayPackages[i]] = GetGroupDisPlayNames(package.Groups);
202+
TagDisplays[key] = group.Tags;
203+
CollectorDisplays[key] = GetCollectorDisPlayNames(group.Collectors.GetDisPlayNames());
200204
DisplayCollectorsIndex = 0;
201-
DataDic[key] = new List<AssetDataInfo>();
205+
DataDic[key] = new ConcurrentBag<AssetDataInfo>();
202206
TypeDisplays[(i, j)] = Array.Empty<string>();
203207

204208
var toLower = Config.LoadPathToLower;
205209
var hasExtension = Config.HasExtension;
206-
var listTypes = new List<string>();
210+
var listTypes = new ConcurrentBag<string>();
207211

208-
var count = Data.Packages[i].Groups[j].Collectors.Length;
212+
var count = group.Collectors.Length;
209213
var index = 0;
210214

211-
foreach (var item in Data.Packages[i].Groups[j].Collectors)
215+
foreach (var item in group.Collectors)
212216
{
213217
if (item.AllowThread)
214-
Runner.StartTask(() => Collect(item));
218+
Runner.StartTask(Collect, item);
215219
else
216-
Runner.StartCoroutine(() => Collect(item));
220+
Runner.StartCoroutine(Collect, item);
217221
}
218222

219223
TreeViewQueryAsset.Reload(PageValues);
220224
return;
221225

222226
void Collect(AssetCollectItem item)
223227
{
224-
item.CollectAssetAsync(Data.Packages[i], Data.Packages[i].Groups[j], toLower, hasExtension);
225-
DataDic[(i, j)].AddRange(item.DataInfos.Values);
228+
item.CollectAssetAsync(package, group, toLower, hasExtension);
229+
foreach (var variable in item.DataInfos.Values)
230+
{
231+
DataDic[(i, j)].Add(variable);
232+
}
233+
226234
if (count != ++index) return;
227-
Runner.StartCoroutine(() =>
235+
236+
Runner.StartCoroutine(UpdateType, item);
237+
Runner.StartTask(End);
238+
}
239+
240+
void UpdateType(AssetCollectItem item)
241+
{
242+
foreach (var type in item.DataInfos.Values.Select(dataInfo => dataInfo.Type))
228243
{
229-
listTypes.AddRange(DataDic[(i, j)].Where(dataInfo => !listTypes.Contains(dataInfo.Type)).Select(dataInfo => dataInfo.Type));
230-
Runner.StartTask(End);
231-
});
244+
listTypes.Add(type);
245+
}
246+
247+
TypeDisplays[(i, j)] = listTypes.Distinct().ToArray();
232248
}
233249

234250
void End()
235251
{
236-
TypeDisplays[(i, j)] = listTypes.ToArray();
237252
lock (PageValues)
238253
{
239254
PageValues.Add(DataDic[(i, j)].Where(data => !FilterData(data)));
@@ -273,7 +288,7 @@ public void UpdateData()
273288
if (TagDisplays is null) TagDisplays = new Dictionary<(int, int), string[]>();
274289
if (TypeDisplays is null) TypeDisplays = new Dictionary<(int, int), string[]>();
275290
if (DisplayGroupNames is null) DisplayGroupNames = new Dictionary<string, string[]>();
276-
if (DataDic is null) DataDic = new Dictionary<(int, int), List<AssetDataInfo>>();
291+
if (DataDic is null) DataDic = new Dictionary<(int, int), ConcurrentBag<AssetDataInfo>>();
277292

278293
PageValues.Clear();
279294
PageValues.PageIndex = 0;

Editor/Windows/Page/AssetPage.Look.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.ComponentModel;
55
using System.IO;
66
using System.Linq;
7+
using System.Threading.Tasks;
78
using AIO.UEngine;
89
using UnityEditor;
910
using UnityEngine;
@@ -101,7 +102,9 @@ public string Type
101102

102103
private readonly Dictionary<string, DependenciesInfo> Dependencies = new Dictionary<string, DependenciesInfo>(); // 依赖资源
103104

104-
private void OnQueryAsseChanged(int id)
105+
private int TempIndex;
106+
107+
private async void OnQueryAsseChanged(int id)
105108
{
106109
Runner.StopCoroutine(OnSelectionChangedRef);
107110
if (id < 0)
@@ -111,28 +114,31 @@ private void OnQueryAsseChanged(int id)
111114
}
112115

113116
SelectAssetDataInfo = PageValues.CurrentPageValues[id];
117+
Dependencies.Clear();
118+
TempIndex = id;
119+
await Task.Delay(500);
120+
if (TempIndex != id) return;
114121
Runner.StartCoroutine(OnSelectionChangedRef);
115122
}
116123

117124
private IEnumerator OnSelectionChangedRef()
118125
{
119-
Dependencies.Clear();
120-
yield return Runner.WaitForSeconds(0.5f);
126+
yield return Runner.YieldReturn;
121127
var assetPath = SelectAssetDataInfo.AssetPath;
122128
foreach (var dependency in AssetDatabase.GetDependencies(assetPath))
123129
{
124130
if (assetPath == dependency) continue;
125131
if (Dependencies.ContainsKey(dependency)) continue;
126-
var info = new DependenciesInfo
127-
{
128-
AssetPath = dependency, Object = AssetDatabase.LoadAssetAtPath<Object>(dependency)
129-
};
130-
if (!info.Object) continue;
131-
DependenciesSize += info.Size = new FileInfo(dependency).Length;
132-
Dependencies.Add(dependency, info);
132+
var obj = AssetDatabase.LoadAssetAtPath<Object>(dependency);
133+
if (!obj) continue;
134+
var info = new DependenciesInfo { AssetPath = dependency, Object = obj, Size = new FileInfo(dependency).Length };
135+
DependenciesSize += info.Size;
136+
Dependencies[dependency] = info;
137+
yield return Runner.YieldReturn;
133138
}
134139

135140
SelectAsset = AssetDatabase.LoadAssetAtPath<Object>(assetPath);
141+
yield return Runner.YieldReturn;
136142
TreeViewDependencies.Reload(Dependencies.Values);
137143
}
138144

@@ -422,7 +428,7 @@ private void OnDrawAssetDetail(Rect rect)
422428

423429
cell.x += cell.width;
424430
cell.width = rect.width - cell.x;
425-
EditorGUI.LabelField(cell, $"{AssetDatabase.IsSubAsset(SelectAsset)}");
431+
EditorGUI.LabelField(cell, SelectAsset ? $"{AssetDatabase.IsSubAsset(SelectAsset)}" : "false");
426432
}
427433

428434
{
@@ -609,13 +615,10 @@ private void OnDrawPageSetting(Rect rect)
609615
private static string[] GetGroupDisPlayNames(ICollection<AssetCollectGroup> groups)
610616
{
611617
var page = groups.Count > 15;
612-
return (from t in groups
613-
select t.Name
614-
into groupName
615-
where !string.IsNullOrEmpty(groupName)
616-
select page
617-
? string.Concat(char.ToUpper(groupName[0]), '/', groupName)
618-
: groupName).ToArray();
618+
return groups.Select(t => t.Name)
619+
.Where(groupName => !string.IsNullOrEmpty(groupName))
620+
.Select(groupName => page ? string.Concat(char.ToUpper(groupName[0]), '/', groupName) : groupName)
621+
.ToArray();
619622
}
620623

621624
private static string[] GetCollectorDisPlayNames(IList<string> collectors)
@@ -630,8 +633,7 @@ private static string[] GetCollectorDisPlayNames(IList<string> collectors)
630633

631634
if (collectors.Count > 15)
632635
for (var index = 0; index < collectors.Count; index++)
633-
collectors[index] = string.Concat(char.ToUpper(collectors[index][0]), '/',
634-
collectors[index].Replace('/', '\\').TrimEnd('\\'));
636+
collectors[index] = string.Concat(char.ToUpper(collectors[index][0]), '/', collectors[index].Replace('/', '\\').TrimEnd('\\'));
635637
else
636638
for (var index = 0; index < collectors.Count; index++)
637639
collectors[index] = collectors[index].Replace('/', '\\').TrimEnd('\\');

Extensions/YooAsset.CLI/Runtime/1.5.7/Proxy.UnLoad.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,31 @@ public override void HandleFree(string location)
4848
/// <param name="isForce">是否强制回收</param>
4949
public void UnloadUnusedAssets(string packageName, bool isForce = false)
5050
{
51-
if (Dic.TryGetValue(packageName, out var value))
52-
{
53-
if (isForce)
54-
value.Package.ForceUnloadAllAssets();
55-
else
56-
Runner.StartCoroutine(UnloadUnusedAssetsCo(_ =>
57-
{
58-
value.Package.UnloadUnusedAssets();
59-
AssetSystem.LogFormat(string.Intern("Free Asset Handle Release : {0}"), packageName);
60-
}));
61-
}
51+
if (!Dic.TryGetValue(packageName, out var value)) return;
52+
if (isForce) value.Package.ForceUnloadAllAssets();
53+
else
54+
Runner.StartCoroutine(UnloadUnusedAssetsCo, (Action<AsyncOperation>)delegate
55+
{
56+
value.Package.UnloadUnusedAssets();
57+
AssetSystem.LogFormat(string.Intern("Free Asset Handle Release : {0}"), packageName);
58+
});
6259
}
6360

6461
public override void UnloadUnusedAssets(bool isForce = false)
6562
{
66-
foreach (var key in ReferenceOPHandle.Keys.ToArray())
67-
{
68-
var temp = ReferenceOPHandle[key];
69-
if (temp.IsValid) continue;
70-
var status = temp.Status;
71-
if (status == EOperationStatus.Succeed || status == EOperationStatus.Processing) continue;
72-
ReferenceOPHandle.Remove(key);
73-
}
74-
7563
if (isForce)
7664
{
7765
ReferenceOPHandle.Clear();
78-
foreach (var value in Dic.Values)
79-
value.Package.ForceUnloadAllAssets();
66+
Dic.Values.ToList().ForEach(value => value.Package.ForceUnloadAllAssets());
8067
}
8168
else
8269
{
70+
ReferenceOPHandle.Where(pair => !pair.Value.IsValid)
71+
.Where(pair => pair.Value.Status != EOperationStatus.Succeed)
72+
.Where(pair => pair.Value.Status != EOperationStatus.Processing)
73+
.Select(pair => pair.Key)
74+
.ToList()
75+
.ForEach(item => ReferenceOPHandle.Remove(item));
8376
Runner.StartCoroutine(UnloadUnusedAssetsCo(_ =>
8477
{
8578
foreach (var value in Dic.Values)

0 commit comments

Comments
 (0)