Skip to content

Commit c94cc7a

Browse files
committed
⭐[update] up version
1 parent d8d2d5f commit c94cc7a

File tree

15 files changed

+338
-123
lines changed

15 files changed

+338
-123
lines changed

Editor/Windows/ASConfigEditor.cs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static void Create()
2525
private List<AssetsPackageConfig> _packages;
2626
private bool FoldoutAutoRecord = true;
2727
private Queue<AssetSystem.SequenceRecord> RecordQueue;
28+
private string RecordQueueSizeStr = "0 bytes";
2829

2930
protected override void OnActivation()
3031
{
@@ -33,21 +34,35 @@ protected override void OnActivation()
3334
? new List<AssetsPackageConfig>()
3435
: Target.Packages.ToList();
3536

36-
RecordQueue = File.Exists(AssetSystem.SequenceRecordPath)
37-
? AHelper.IO.ReadJsonUTF8<Queue<AssetSystem.SequenceRecord>>(AssetSystem.SequenceRecordPath)
38-
: new Queue<AssetSystem.SequenceRecord>();
37+
UpdateRecordQueue();
3938
}
4039

4140
protected override void OnGUI()
4241
{
42+
using (GELayout.VHorizontal())
43+
{
44+
if (GELayout.Button("Clean Sandbox"))
45+
{
46+
var sandbox = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "Sandbox");
47+
if (Directory.Exists(sandbox)) AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
48+
}
49+
50+
if (GELayout.Button("Clean Bundles"))
51+
{
52+
var sandbox = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "Bundles");
53+
if (Directory.Exists(sandbox)) AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
54+
}
55+
}
56+
4357
Target.ASMode = GELayout.Popup("加载模式", Target.ASMode);
4458
Target.OutputLog = GELayout.ToggleLeft("开启日志输出", Target.OutputLog);
59+
Target.LoadPathToLower = GELayout.ToggleLeft("定位地址小写", Target.LoadPathToLower);
60+
4561
switch (Target.ASMode)
4662
{
4763
case EASMode.Remote:
4864
Target.AutoSaveVersion = GELayout.ToggleLeft("自动激活清单", Target.AutoSaveVersion);
4965
Target.AppendTimeTicks = GELayout.ToggleLeft("请求附加时间磋", Target.AppendTimeTicks);
50-
Target.LoadPathToLower = GELayout.ToggleLeft("定位地址小写", Target.LoadPathToLower);
5166
Target.AutoSequenceRecord = GELayout.ToggleLeft("自动序列记录", Target.AutoSequenceRecord);
5267
Target.DownloadFailedTryAgain = GELayout.Slider("下载失败尝试次数", Target.DownloadFailedTryAgain, 1, 100);
5368
Target.LoadingMaxTimeSlice = GELayout.Slider("资源加载的最大数量", Target.LoadingMaxTimeSlice, 144, 8192);
@@ -78,7 +93,7 @@ protected override void OnGUI()
7893
Target.SequenceRecordRemotePath =
7994
GELayout.AreaText(Target.SequenceRecordRemotePath, GUILayout.Height(50));
8095

81-
FoldoutAutoRecord = GELayout.VFoldout("序列记录", FoldoutAutoRecord);
96+
FoldoutAutoRecord = GELayout.VFoldout($"序列记录 Size {RecordQueueSizeStr}", FoldoutAutoRecord);
8297
if (FoldoutAutoRecord)
8398
{
8499
if (RecordQueue != null)
@@ -88,7 +103,8 @@ protected override void OnGUI()
88103
var index = 0;
89104
foreach (var record in RecordQueue)
90105
{
91-
GELayout.Label($"{++index} : {record.Name} -> {record.Location} ");
106+
GELayout.Label(
107+
$"{++index} : {record.Name} -> {record.Location} : {record.AssetPath} ");
92108
GELayout.HelpBox(
93109
$"{record.Time:yyyy-MM-dd HH:mm:ss} [Num : {record.Count}] [Size : {record.Bytes.ToConverseStringFileSize()}] ");
94110
}
@@ -97,13 +113,7 @@ protected override void OnGUI()
97113

98114
using (GELayout.VHorizontal())
99115
{
100-
GELayout.Button("Update", () =>
101-
{
102-
RecordQueue = File.Exists(AssetSystem.SequenceRecordPath)
103-
? AHelper.IO.ReadJsonUTF8<Queue<AssetSystem.SequenceRecord>>(AssetSystem
104-
.SequenceRecordPath)
105-
: new Queue<AssetSystem.SequenceRecord>();
106-
});
116+
GELayout.Button("Update", UpdateRecordQueue);
107117

108118
if (File.Exists(AssetSystem.SequenceRecordPath))
109119
{
@@ -145,6 +155,17 @@ private static void OpenSequenceRecordPath()
145155
Application.OpenURL(AssetSystem.SequenceRecordPath);
146156
}
147157

158+
private void UpdateRecordQueue()
159+
{
160+
RecordQueue = File.Exists(AssetSystem.SequenceRecordPath)
161+
? AHelper.IO.ReadJsonUTF8<Queue<AssetSystem.SequenceRecord>>(AssetSystem
162+
.SequenceRecordPath)
163+
: new Queue<AssetSystem.SequenceRecord>();
164+
165+
if (RecordQueue is null) RecordQueue = new Queue<AssetSystem.SequenceRecord>();
166+
RecordQueueSizeStr = RecordQueue.Sum(record => record.Bytes).ToConverseStringFileSize();
167+
}
168+
148169
private async void Update()
149170
{
150171
await Target.UpdatePackage();

Runtime/Basics/AssetSystem.Helper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public static bool IsNeedDownloadFromRemote(string location)
101101
public static void FreeHandle(string location)
102102
{
103103
Proxy.FreeHandle(location);
104+
#if UNITY_EDITOR
105+
UnityEngine.Debug.LogFormat("Asset System FreeHandle Release : {0}", location);
106+
#endif
104107
}
105108

106109
[DebuggerNonUserCode, DebuggerHidden]
@@ -156,17 +159,16 @@ public static async Task<AssetsPackageConfig[]> GetRemotePackageList(string url)
156159
var config = await AHelper.Net.HTTP.GetAsync(remote);
157160
return AHelper.Json.Deserialize<AssetsPackageConfig[]>(config);
158161
}
159-
160-
162+
163+
161164
/// <summary>
162165
/// 是否已经加载
163166
/// </summary>
164167
/// <param name="location">寻址地址</param>
165168
/// <returns>Ture 已经加载 False 未加载</returns>
166169
public static bool IsAlreadyLoad(string location)
167170
{
168-
return Proxy.IsAlreadyLoad(location);
171+
return Proxy.IsAlreadyLoad(Parameter.LoadPathToLower ? location.ToLower() : location);
169172
}
170-
171173
}
172174
}

Runtime/Basics/AssetSystem.Load.cs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*|✩ - - - - - |||
2-
|||✩ Author: ||| -> XINAN
2+
|||✩ Author: ||| -> xi nan
33
|||✩ Date: ||| -> 2023-08-22
44
|||✩ Document: ||| ->
55
|||✩ - - - - - |*/
66

77
using System;
88
using System.Collections;
99
using System.Diagnostics;
10+
using System.Runtime.CompilerServices;
1011
using System.Threading.Tasks;
1112
using UnityEngine.SceneManagement;
1213
using Object = UnityEngine.Object;
@@ -192,6 +193,104 @@ public static IEnumerator LoadAssetCO<TObject>(string location, Action<TObject>
192193
return Proxy.LoadAssetCO(Parameter.LoadPathToLower ? location.ToLower() : location, cb);
193194
}
194195

196+
public interface IAsyncHandle : IEnumerator, IDisposable
197+
{
198+
/// <summary>
199+
/// 是否已经完成
200+
/// </summary>
201+
bool IsDone { get; }
202+
203+
/// <summary>
204+
/// 处理进度
205+
/// </summary>
206+
float Progress { get; }
207+
}
208+
209+
public interface IAsyncHandle<T> : IAsyncHandle where T : Object
210+
{
211+
T Result { get; }
212+
213+
TaskAwaiter<T> GetAwaiter();
214+
}
215+
216+
internal class LoadAssetHandleCo<T> : IAsyncHandle<T> where T : Object
217+
{
218+
private IEnumerator CO => _CO ?? (_CO = Proxy.LoadAssetCO<T>(Location, OnCompletedCo));
219+
private IEnumerator _CO;
220+
221+
internal readonly string Location;
222+
223+
public bool IsDone { get; set; }
224+
225+
public T Result { get; set; }
226+
227+
public float Progress { get; private set; }
228+
229+
private void OnCompletedCo(T asset)
230+
{
231+
Progress = 1;
232+
Result = asset;
233+
IsDone = true;
234+
}
235+
236+
private void OnCompletedTask()
237+
{
238+
Progress = 1;
239+
Result = Awaiter.GetResult();
240+
IsDone = true;
241+
}
242+
243+
public LoadAssetHandleCo(string location)
244+
{
245+
Location = location;
246+
IsDone = false;
247+
Progress = 0;
248+
Result = null;
249+
_CO = null;
250+
}
251+
252+
bool IEnumerator.MoveNext()
253+
{
254+
return CO.MoveNext();
255+
}
256+
257+
void IEnumerator.Reset()
258+
{
259+
Progress = 0;
260+
IsDone = false;
261+
CO?.Reset();
262+
}
263+
264+
object IEnumerator.Current => CO.Current;
265+
266+
private TaskAwaiter<T> Awaiter;
267+
268+
public TaskAwaiter<T> GetAwaiter()
269+
{
270+
var Task = Proxy.LoadAssetTask<T>(Location);
271+
Awaiter = Task.GetAwaiter();
272+
Awaiter.OnCompleted(OnCompletedTask);
273+
return Awaiter;
274+
}
275+
276+
void IDisposable.Dispose()
277+
{
278+
_CO = null;
279+
Result = null;
280+
}
281+
}
282+
283+
/// <summary>
284+
/// 异步加载资源对象
285+
/// </summary>
286+
/// <typeparam name="TObject">资源类型</typeparam>
287+
/// <param name="location">资源的定位地址</param>
288+
[DebuggerNonUserCode, DebuggerHidden]
289+
public static IAsyncHandle<TObject> LoadAssetCO<TObject>(string location) where TObject : Object
290+
{
291+
return new LoadAssetHandleCo<TObject>(Parameter.LoadPathToLower ? location.ToLower() : location);
292+
}
293+
195294
/// <summary>
196295
/// 异步加载资源对象
197296
/// </summary>
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/*|✩ - - - - - |||
2-
|||✩ Author: ||| -> XINAN
2+
|||✩ Author: ||| -> xi nan
33
|||✩ Date: ||| -> 2023-08-22
44
|||✩ Document: ||| ->
55
|||✩ - - - - - |*/
66

7+
using System;
78
using System.Diagnostics;
8-
using UnityEngine;
9+
using System.Threading.Tasks;
10+
using AIO.UEngine;
11+
using Object = UnityEngine.Object;
912

1013
namespace AIO
1114
{
@@ -17,19 +20,19 @@ public partial class AssetSystem
1720
/// <param name="location">资源的定位地址</param>
1821
/// <typeparam name="TObject">资源类型</typeparam>
1922
[DebuggerNonUserCode, DebuggerHidden]
20-
public static void PreLoadSubAssets<TObject>(string location) where TObject : Object
23+
public static Task PreLoadSubAssets<TObject>(string location) where TObject : Object
2124
{
22-
Proxy.PreLoadSubAssets<TObject>(location);
25+
return Proxy.PreLoadSubAssets<TObject>(Parameter.LoadPathToLower ? location.ToLower() : location);
2326
}
2427

2528
/// <summary>
2629
/// 预加载资源
2730
/// </summary>
2831
/// <param name="location">资源的定位地址</param>
2932
[DebuggerNonUserCode, DebuggerHidden]
30-
public static void PreLoadSubAssets(string location)
33+
public static Task PreLoadSubAssets(string location)
3134
{
32-
Proxy.PreLoadSubAssets<Object>(location);
35+
return Proxy.PreLoadSubAssets<Object>(Parameter.LoadPathToLower ? location.ToLower() : location);
3336
}
3437

3538
/// <summary>
@@ -38,29 +41,42 @@ public static void PreLoadSubAssets(string location)
3841
/// <param name="location">资源的定位地址</param>
3942
/// <typeparam name="TObject">资源类型</typeparam>
4043
[DebuggerNonUserCode, DebuggerHidden]
41-
public static void PreLoadAsset<TObject>(string location) where TObject : Object
44+
public static Task PreLoadAsset<TObject>(string location) where TObject : Object
4245
{
43-
Proxy.PreLoadAsset<TObject>(location);
46+
return Proxy.PreLoadAsset<TObject>(Parameter.LoadPathToLower ? location.ToLower() : location);
4447
}
4548

4649
/// <summary>
4750
/// 预加载资源
4851
/// </summary>
4952
/// <param name="location">资源的定位地址</param>
53+
/// <param name="type">资源类型</param>
5054
[DebuggerNonUserCode, DebuggerHidden]
51-
public static void PreLoadAsset(string location)
55+
public static Task PreLoadAsset(string location, Type type)
5256
{
53-
Proxy.PreLoadAsset<Object>(location);
57+
return Proxy.PreLoadAsset(Parameter.LoadPathToLower ? location.ToLower() : location, type);
5458
}
5559

5660
/// <summary>
5761
/// 预加载资源
5862
/// </summary>
5963
/// <param name="location">资源的定位地址</param>
6064
[DebuggerNonUserCode, DebuggerHidden]
61-
public static void PreLoadRaw(string location)
65+
public static Task PreLoadRaw(string location)
6266
{
63-
Proxy.PreLoadRaw(location);
67+
return Proxy.PreLoadRaw(Parameter.LoadPathToLower ? location.ToLower() : location);
68+
}
69+
70+
/// <summary>
71+
/// 预加载记录
72+
/// </summary>
73+
public static async Task DownloadPreRecord(ProgressArgs progressArgs = default)
74+
{
75+
if (Parameter.ASMode != EASMode.Remote) return;
76+
var handle = GetDownloader();
77+
var flow = await handle.UpdatePackageManifestTask();
78+
if (flow) flow = await handle.UpdatePackageVersionTask();
79+
if (flow) await Proxy.PreRecord(SequenceRecordQueue, progressArgs);
6480
}
6581
}
6682
}

Runtime/Basics/AssetSystem.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ public struct SequenceRecord
5151
/// </summary>
5252
public string Location;
5353

54+
/// <summary>
55+
/// 资源路径
56+
/// </summary>
57+
public string AssetPath;
58+
5459
/// <summary>
5560
/// 记录时间
5661
/// </summary>
5762
public DateTime Time;
58-
63+
5964
/// <summary>
6065
/// 记录大小
6166
/// </summary>
@@ -118,9 +123,12 @@ public static IEnumerator Initialize<T>(T proxy, ASConfig config) where T : Asse
118123
IsInitialized = true;
119124
#if !UNITY_WEBGL
120125
if (Parameter.AutoSequenceRecord)
126+
{
121127
SequenceRecordQueue = File.Exists(SequenceRecordPath)
122128
? AHelper.IO.ReadJsonUTF8<Queue<SequenceRecord>>(SequenceRecordPath)
123129
: new Queue<SequenceRecord>();
130+
if (SequenceRecordQueue is null) SequenceRecordQueue = new Queue<SequenceRecord>();
131+
}
124132
#endif
125133
}
126134

0 commit comments

Comments
 (0)