-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,870 additions
and
1,125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/UnityFx.Async.AssetStore/Assets/UnityFx.Async/Scripts/AssetBundleRequestResult{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Alexander Bogarsukov. | ||
// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace UnityFx.Async | ||
{ | ||
/// <summary> | ||
/// A wrapper for <see cref="AssetBundleRequest"/> with result value. | ||
/// </summary> | ||
/// <typeparam name="T">Result type.</typeparam> | ||
public sealed class AssetBundleRequestResult<T> : AsyncResult<T> where T : UnityEngine.Object | ||
{ | ||
#region data | ||
|
||
private readonly AssetBundleRequest _op; | ||
|
||
#endregion | ||
|
||
#region interface | ||
|
||
/// <summary> | ||
/// Gets the underlying <see cref="AssetBundleRequest"/> instance. | ||
/// </summary> | ||
public AssetBundleRequest Request | ||
{ | ||
get | ||
{ | ||
return _op; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AssetBundleRequestResult{T}"/> class. | ||
/// </summary> | ||
/// <param name="op">Source web request.</param> | ||
public AssetBundleRequestResult(AssetBundleRequest op) | ||
: base(AsyncOperationStatus.Running) | ||
{ | ||
_op = op; | ||
|
||
if (op.isDone) | ||
{ | ||
TrySetResult(op.asset as T, true); | ||
} | ||
else | ||
{ | ||
#if UNITY_2017_2_OR_NEWER || UNITY_2018 | ||
|
||
// Starting with Unity 2017.2 there is AsyncOperation.completed event | ||
op.completed += o => TrySetResult(o.asset as T); | ||
|
||
#else | ||
|
||
AsyncUtility.AddCompletionCallback(op, () => TrySetResult(_op.asset as T)); | ||
|
||
#endif | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region AsyncResult | ||
|
||
/// <inheritdoc/> | ||
protected override float GetProgress() | ||
{ | ||
return _op.progress; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/UnityFx.Async.AssetStore/Assets/UnityFx.Async/Scripts/AsyncOperationResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) Alexander Bogarsukov. | ||
// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace UnityFx.Async | ||
{ | ||
/// <summary> | ||
/// A wrapper for <see cref="AsyncOperation"/> with result value. | ||
/// </summary> | ||
public class AsyncOperationResult : AsyncResult | ||
{ | ||
#region data | ||
|
||
private readonly AsyncOperation _op; | ||
|
||
#endregion | ||
|
||
#region interface | ||
|
||
/// <summary> | ||
/// Gets the underlying <see cref="AsyncOperation"/> instance. | ||
/// </summary> | ||
public AsyncOperation Operation | ||
{ | ||
get | ||
{ | ||
return _op; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AsyncOperationResult"/> class. | ||
/// </summary> | ||
/// <param name="op">Source web request.</param> | ||
public AsyncOperationResult(AsyncOperation op) | ||
: base(AsyncOperationStatus.Running) | ||
{ | ||
_op = op; | ||
|
||
if (op.isDone) | ||
{ | ||
TrySetCompleted(true); | ||
} | ||
else | ||
{ | ||
#if UNITY_2017_2_OR_NEWER || UNITY_2018 | ||
|
||
// Starting with Unity 2017.2 there is AsyncOperation.completed event | ||
op.completed += o => TrySetCompleted(); | ||
|
||
#else | ||
|
||
AsyncUtility.AddCompletionCallback(op, () => TrySetCompleted()); | ||
|
||
#endif | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region AsyncResult | ||
|
||
/// <inheritdoc/> | ||
protected override float GetProgress() | ||
{ | ||
return _op.progress; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.