Skip to content

Commit f08b2e8

Browse files
committed
feat: Supports adding custom headers to URLs
1 parent ca07acc commit f08b2e8

File tree

4 files changed

+300
-41
lines changed

4 files changed

+300
-41
lines changed

Editor/Scripts/AssetHandle.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ public static AssetHandle CreateFromExternalFile(string externalPath, out string
109109
return externalFileHandle;
110110
}
111111

112-
public static AssetHandle CreateFromUrl(string url, out string error)
112+
public static AssetHandle CreateFromUrl(string url, string title, out string error)
113113
{
114114
AssetHandle urlHandle = new AssetHandle
115115
{
116116
_category = AssetCategory.Url,
117117
_guid = url,
118+
_fallbackName = title ?? string.Empty,
118119
};
119120

120121
error = null;
@@ -379,7 +380,14 @@ public string GetDisplayName()
379380
}
380381

381382
case AssetCategory.Url:
382-
return _guid;
383+
if (string.IsNullOrEmpty(_fallbackName))
384+
{
385+
return _guid;
386+
}
387+
else
388+
{
389+
return $"{_fallbackName} <i>({_guid})</i>";
390+
}
383391

384392
default:
385393
throw new ArgumentOutOfRangeException(nameof(Category), Category, null);

Editor/Scripts/AssetQuickAccessLocalCache.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ public bool AddObjects(IEnumerable<UObject> objects, ref StringBuilder errorsBui
165165
return added;
166166
}
167167

168-
public bool AddUrls(HashSet<string> urls, ref StringBuilder errorsBuilder, bool clearErrorsBuilder)
168+
public bool AddUrls(IEnumerable<(string url, string title)> urlInfos, ref StringBuilder errorsBuilder, bool clearErrorsBuilder)
169169
{
170170
if (clearErrorsBuilder)
171171
{
172172
errorsBuilder?.Clear();
173173
}
174174

175175
bool added = false;
176-
foreach (string url in urls)
176+
foreach ((string url, string title) urlInfo in urlInfos)
177177
{
178-
if (_assetHandles.Any(h => h.GetAssetPath() == url))
178+
if (_assetHandles.Any(h => h.GetAssetPath() == urlInfo.url))
179179
{
180180
if (errorsBuilder == null)
181181
{
@@ -185,7 +185,7 @@ public bool AddUrls(HashSet<string> urls, ref StringBuilder errorsBuilder, bool
185185
continue;
186186
}
187187

188-
AssetHandle handle = AssetHandle.CreateFromUrl(url, out string error);
188+
AssetHandle handle = AssetHandle.CreateFromUrl(urlInfo.url, urlInfo.title, out string error);
189189
if (!string.IsNullOrEmpty(error))
190190
{
191191
if (errorsBuilder == null)

Editor/Scripts/AssetQuickAccessWindow.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using UnityEditor;
56
using UnityEngine;
@@ -20,18 +21,18 @@ public static void Open()
2021
GetWindow<AssetQuickAccessWindow>();
2122
}
2223

23-
public static void AddItems(IList<UObject> objects, IList<string> paths, IList<string> urls)
24+
public static void AddItems(IList<UObject> objects, IList<string> paths, IList<(string url, string title)> urlInfos)
2425
{
2526
HashSet<UObject> objectHashSet = new HashSet<UObject>();
2627
if (objects != null)
2728
{
2829
objectHashSet = new HashSet<UObject>(objects);
2930
}
3031

31-
HashSet<string> stringHashSet = null; // For paths and urls
32+
HashSet<string> pathHashSet = null;
3233
if (paths != null)
3334
{
34-
stringHashSet = new HashSet<string>();
35+
pathHashSet = new HashSet<string>();
3536
foreach (string rawPath in paths)
3637
{
3738
string path = rawPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
@@ -52,32 +53,31 @@ public static void AddItems(IList<UObject> objects, IList<string> paths, IList<s
5253
}
5354
else
5455
{
55-
stringHashSet.Add(rawPath);
56+
pathHashSet.Add(rawPath);
5657
}
5758
}
5859
}
5960

6061
StringBuilder errorsBuilder = null;
6162
bool added = AssetQuickAccessLocalCache.instance.AddObjects(objectHashSet, ref errorsBuilder, false);
62-
if (stringHashSet != null)
63+
if (pathHashSet != null)
6364
{
64-
added |= AssetQuickAccessLocalCache.instance.AddExternalPaths(stringHashSet, ref errorsBuilder, false);
65+
added |= AssetQuickAccessLocalCache.instance.AddExternalPaths(pathHashSet, ref errorsBuilder, false);
6566
}
6667

67-
if (urls != null)
68+
if (urlInfos != null)
6869
{
69-
stringHashSet?.Clear();
70-
if (stringHashSet == null)
70+
Dictionary<string, (string url, string title)> urlDict = new Dictionary<string, (string url, string title)>();
71+
for (int i = 0; i < urlInfos.Count; i++)
7172
{
72-
stringHashSet = new HashSet<string>();
73-
}
74-
75-
for (int i = 0; i < urls.Count; i++)
76-
{
77-
stringHashSet.Add(urls[i]);
73+
string url = urlInfos[i].url;
74+
if (!urlDict.ContainsKey(url))
75+
{
76+
urlDict.Add(url, urlInfos[i]);
77+
}
7878
}
7979

80-
added |= AssetQuickAccessLocalCache.instance.AddUrls(stringHashSet, ref errorsBuilder, false);
80+
added |= AssetQuickAccessLocalCache.instance.AddUrls(urlDict.Values, ref errorsBuilder, false);
8181
}
8282

8383
if (_instance)
@@ -274,14 +274,14 @@ private void AddUrlEditor()
274274
UrlEditWindow.Open(center, AddUrl);
275275
}
276276

277-
private void AddUrl(string url)
277+
private void AddUrl(string url, string title)
278278
{
279279
if (string.IsNullOrWhiteSpace(url))
280280
{
281281
return;
282282
}
283283

284-
AddItems(null, null, new string[] { url });
284+
AddItems(null, null, new (string url, string title)[] { (url, title) });
285285
}
286286

287287
#endregion

0 commit comments

Comments
 (0)