Skip to content
This repository was archived by the owner on May 10, 2026. It is now read-only.

Commit 2163ef8

Browse files
committed
Add: sync methods to IResourceProvider
1 parent b86a66f commit 2163ef8

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/NavStack/Assets/NavStack/Runtime/Content/AddressablesResourceProvider.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ namespace NavStack.Content
77
{
88
internal sealed class AddressablesResourceProvider : IResourceProvider
99
{
10+
public T Load<T>(string key) where T : UnityEngine.Object
11+
{
12+
var result = Addressables.LoadAssetAsync<T>(key).WaitForCompletion();
13+
return result;
14+
}
15+
16+
public void Unload<T>(T obj) where T : UnityEngine.Object
17+
{
18+
Addressables.Release(obj);
19+
}
20+
1021
public async UniTask<T> LoadAsync<T>(string key, CancellationToken cancellationToken = default)
1122
where T : UnityEngine.Object
1223
{

src/NavStack/Assets/NavStack/Runtime/Content/IResourceProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace NavStack.Content
55
{
66
public interface IResourceProvider
77
{
8+
T Load<T>(string key) where T : UnityEngine.Object;
9+
void Unload<T>(T obj) where T : UnityEngine.Object;
810
UniTask<T> LoadAsync<T>(string key, CancellationToken cancellationToken = default) where T : UnityEngine.Object;
911
UniTask UnloadAsync<T>(T obj, CancellationToken cancellationToken = default) where T : UnityEngine.Object;
1012
}

src/NavStack/Assets/NavStack/Runtime/Content/ResourcesResourceProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ namespace NavStack.Content
77
{
88
internal sealed class ResourcesResourceProvider : IResourceProvider
99
{
10+
public T Load<T>(string key) where T : UnityEngine.Object
11+
{
12+
var resource = Resources.Load(key);
13+
if (resource is not T result) throw new Exception(); // TODO:
14+
return result;
15+
}
16+
1017
public async UniTask<T> LoadAsync<T>(string key, CancellationToken cancellationToken = default)
1118
where T : UnityEngine.Object
1219
{
@@ -16,6 +23,11 @@ public async UniTask<T> LoadAsync<T>(string key, CancellationToken cancellationT
1623
return result;
1724
}
1825

26+
public void Unload<T>(T obj) where T : UnityEngine.Object
27+
{
28+
// not supported
29+
}
30+
1931
public UniTask UnloadAsync<T>(T obj, CancellationToken cancellationToken = default)
2032
where T : UnityEngine.Object
2133
{

0 commit comments

Comments
 (0)