Skip to content

Commit e211326

Browse files
committed
fixed UniTask compatibility
1 parent 5e958a6 commit e211326

File tree

3 files changed

+22
-115
lines changed

3 files changed

+22
-115
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.1.2
4+
5+
### Fixed
6+
7+
- UniTask compatibility
8+
39
## v0.1.1
410

511
### Added

Runtime/ManageAddressables.UniTask.cs

Lines changed: 15 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,7 @@ public static async UniTask<OperationResult<IResourceLocator>> InitializeAsync()
3434

3535
public static async UniTask<OperationResult<object>> LoadLocationsAsync(object key)
3636
{
37-
if (key == null)
38-
{
39-
if (ExceptionHandle == ExceptionHandleType.Throw)
40-
throw new InvalidKeyException(key);
41-
42-
if (ExceptionHandle == ExceptionHandleType.Log)
43-
Debug.LogException(new InvalidKeyException(key));
44-
45-
return new OperationResult<object>(false, key);
46-
}
37+
_ = key ?? throw new InvalidKeyException(key);
4738

4839
try
4940
{
@@ -53,30 +44,15 @@ public static async UniTask<OperationResult<object>> LoadLocationsAsync(object k
5344
OnLoadLocationsCompleted(operation, key);
5445
return new OperationResult<object>(operation.Status == AsyncOperationStatus.Succeeded, key);
5546
}
56-
catch (Exception ex)
47+
catch (Exception e)
5748
{
58-
if (ExceptionHandle == ExceptionHandleType.Throw)
59-
throw ex;
60-
61-
if (ExceptionHandle == ExceptionHandleType.Log)
62-
Debug.LogException(ex);
63-
64-
return new OperationResult<object>(false, key);
49+
throw e;
6550
}
6651
}
6752

6853
public static async UniTask<OperationResult<T>> LoadAssetAsync<T>(string key) where T : Object
6954
{
70-
if (!GuardKey(key, out key))
71-
{
72-
if (ExceptionHandle == ExceptionHandleType.Throw)
73-
throw new InvalidKeyException(key);
74-
75-
if (ExceptionHandle == ExceptionHandleType.Log)
76-
Debug.LogException(new InvalidKeyException(key));
77-
78-
return default;
79-
}
55+
RuntimeKeyIsValid(key, true);
8056

8157
if (_assets.ContainsKey(key))
8258
{
@@ -106,16 +82,7 @@ public static async UniTask<OperationResult<T>> LoadAssetAsync<T>(string key) wh
10682

10783
public static async UniTask<OperationResult<T>> LoadAssetAsync<T>(AssetReferenceT<T> reference) where T : Object
10884
{
109-
if (!GuardKey(reference, out var key))
110-
{
111-
if (ExceptionHandle == ExceptionHandleType.Throw)
112-
throw Exceptions.InvalidReference;
113-
114-
if (ExceptionHandle == ExceptionHandleType.Log)
115-
Debug.LogException(new InvalidKeyException(key));
116-
117-
return default;
118-
}
85+
RuntimeKeyIsValid(reference, out var key, true);
11986

12087
if (_assets.ContainsKey(key))
12188
{
@@ -156,16 +123,7 @@ public static async UniTask<OperationResult<SceneInstance>> LoadSceneAsync(strin
156123
bool activateOnLoad = true,
157124
int priority = 100)
158125
{
159-
if (!GuardKey(key, out key))
160-
{
161-
if (ExceptionHandle == ExceptionHandleType.Throw)
162-
throw new InvalidKeyException(key);
163-
164-
if (ExceptionHandle == ExceptionHandleType.Log)
165-
Debug.LogException(new InvalidKeyException(key));
166-
167-
return default;
168-
}
126+
RuntimeKeyIsValid(key, true);
169127

170128
if (_scenes.TryGetValue(key, out var scene))
171129
{
@@ -194,16 +152,7 @@ public static async UniTask<OperationResult<SceneInstance>> LoadSceneAsync(Asset
194152
bool activateOnLoad = true,
195153
int priority = 100)
196154
{
197-
if (!GuardKey(reference, out var key))
198-
{
199-
if (ExceptionHandle == ExceptionHandleType.Throw)
200-
throw Exceptions.InvalidReference;
201-
202-
if (ExceptionHandle == ExceptionHandleType.Log)
203-
Debug.LogException(new InvalidKeyException(key));
204-
205-
return default;
206-
}
155+
RuntimeKeyIsValid(reference, out var key, true);
207156

208157
if (_scenes.TryGetValue(key, out var scene))
209158
{
@@ -229,16 +178,7 @@ public static async UniTask<OperationResult<SceneInstance>> LoadSceneAsync(Asset
229178

230179
public static async UniTask<OperationResult<SceneInstance>> UnloadSceneAsync(string key, bool autoReleaseHandle = true)
231180
{
232-
if (!GuardKey(key, out key))
233-
{
234-
if (ExceptionHandle == ExceptionHandleType.Throw)
235-
throw new InvalidKeyException(key);
236-
237-
if (ExceptionHandle == ExceptionHandleType.Log)
238-
Debug.LogException(new InvalidKeyException(key));
239-
240-
return default;
241-
}
181+
RuntimeKeyIsValid(key, true);
242182

243183
if (!_scenes.TryGetValue(key, out var scene))
244184
{
@@ -257,30 +197,15 @@ public static async UniTask<OperationResult<SceneInstance>> UnloadSceneAsync(str
257197

258198
return operation;
259199
}
260-
catch (Exception ex)
200+
catch (Exception e)
261201
{
262-
if (ExceptionHandle == ExceptionHandleType.Throw)
263-
throw ex;
264-
265-
if (ExceptionHandle == ExceptionHandleType.Log)
266-
Debug.LogException(ex);
267-
268-
return new OperationResult<SceneInstance>(false, in scene);
202+
throw e;
269203
}
270204
}
271205

272206
public static async UniTask<OperationResult<SceneInstance>> UnloadSceneAsync(AssetReference reference)
273207
{
274-
if (!GuardKey(reference, out var key))
275-
{
276-
if (ExceptionHandle == ExceptionHandleType.Throw)
277-
throw Exceptions.InvalidReference;
278-
279-
if (ExceptionHandle == ExceptionHandleType.Log)
280-
Debug.LogException(new InvalidKeyException(key));
281-
282-
return default;
283-
}
208+
RuntimeKeyIsValid(reference, out var key, true);
284209

285210
if (!_scenes.TryGetValue(key, out var scene))
286211
{
@@ -299,15 +224,9 @@ public static async UniTask<OperationResult<SceneInstance>> UnloadSceneAsync(Ass
299224

300225
return operation;
301226
}
302-
catch (Exception ex)
227+
catch (Exception e)
303228
{
304-
if (ExceptionHandle == ExceptionHandleType.Throw)
305-
throw ex;
306-
307-
if (ExceptionHandle == ExceptionHandleType.Log)
308-
Debug.LogException(ex);
309-
310-
return new OperationResult<SceneInstance>(false, scene);
229+
throw e;
311230
}
312231
}
313232

@@ -316,16 +235,7 @@ public static async UniTask<OperationResult<GameObject>> InstantiateAsync(string
316235
bool inWorldSpace = false,
317236
bool trackHandle = true)
318237
{
319-
if (!GuardKey(key, out key))
320-
{
321-
if (ExceptionHandle == ExceptionHandleType.Throw)
322-
throw new InvalidKeyException(key);
323-
324-
if (ExceptionHandle == ExceptionHandleType.Log)
325-
Debug.LogException(new InvalidKeyException(key));
326-
327-
return default;
328-
}
238+
RuntimeKeyIsValid(key, true);
329239

330240
try
331241
{
@@ -345,16 +255,7 @@ public static async UniTask<OperationResult<GameObject>> InstantiateAsync(AssetR
345255
Transform parent = null,
346256
bool inWorldSpace = false)
347257
{
348-
if (!GuardKey(reference, out var key))
349-
{
350-
if (ExceptionHandle == ExceptionHandleType.Throw)
351-
throw Exceptions.InvalidReference;
352-
353-
if (ExceptionHandle == ExceptionHandleType.Log)
354-
Debug.LogException(new InvalidKeyException(key));
355-
356-
return default;
357-
}
258+
RuntimeKeyIsValid(reference, out var key, true);
358259

359260
try
360261
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.inc8877.addressables-master",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"displayName": "AddressablesMaster",
55
"description": "Essential Addressables tool",
66
"homepage": "https://github.com/inc8877/AddressablesMaster#readme",

0 commit comments

Comments
 (0)