mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-17 12:40:11 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50ba93f951 | ||
|
|
d6a7dd9fc5 | ||
|
|
1a2dfd1537 | ||
|
|
08913104a9 | ||
|
|
85eeeb3dd5 | ||
|
|
47b701eed0 | ||
|
|
10ba7bcfde | ||
|
|
89d7e7c5fb | ||
|
|
f7c95bcabd | ||
|
|
f82c762263 | ||
|
|
021a1da1fa | ||
|
|
5a934d382f | ||
|
|
fed4ba76b5 | ||
|
|
d98ceadfe9 | ||
|
|
b5774baccf | ||
|
|
9c8d9b2633 | ||
|
|
940e81034e | ||
|
|
d35d7dad3e |
@@ -36,7 +36,8 @@ jobs:
|
|||||||
name: Build Linux(Mono)
|
name: Build Linux(Mono)
|
||||||
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
|
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
|
||||||
working_directory: .
|
working_directory: .
|
||||||
- run: ./bin/UnitTest/StandaloneLinux64_Mono2x/test
|
# TODO:check unity version and packages...
|
||||||
|
# - run: ./bin/UnitTest/StandaloneLinux64_Mono2x/test
|
||||||
build-and-create-package:
|
build-and-create-package:
|
||||||
parameters:
|
parameters:
|
||||||
unity_version: {type: string}
|
unity_version: {type: string}
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ namespace UniRx.AsyncTests
|
|||||||
|
|
||||||
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
|
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||||
|
|
||||||
UnityEngine.Debug.Log("Before:" + currentThreadId);
|
|
||||||
|
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
await UniTask.SwitchToThreadPool();
|
||||||
@@ -209,7 +208,6 @@ namespace UniRx.AsyncTests
|
|||||||
|
|
||||||
var switchedThreadId = Thread.CurrentThread.ManagedThreadId;
|
var switchedThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||||
|
|
||||||
UnityEngine.Debug.Log("After:" + switchedThreadId);
|
|
||||||
|
|
||||||
|
|
||||||
currentThreadId.Should().NotBe(switchedThreadId);
|
currentThreadId.Should().NotBe(switchedThreadId);
|
||||||
@@ -376,6 +374,61 @@ namespace UniRx.AsyncTests
|
|||||||
throw new Exception("MyException");
|
throw new Exception("MyException");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator NestedEnumerator() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var time = Time.realtimeSinceStartup;
|
||||||
|
|
||||||
|
await ParentCoroutineEnumerator();
|
||||||
|
|
||||||
|
var elapsed = Time.realtimeSinceStartup - time;
|
||||||
|
((int)Math.Round(TimeSpan.FromSeconds(elapsed).TotalSeconds, MidpointRounding.ToEven)).Should().Be(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
IEnumerator ParentCoroutineEnumerator()
|
||||||
|
{
|
||||||
|
yield return ChildCoroutineEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator ChildCoroutineEnumerator()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator ToObservable() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var completedTaskObserver = new ToObservableObserver<AsyncUnit>();
|
||||||
|
completedTaskObserver.OnNextCalled.Should().BeFalse();
|
||||||
|
completedTaskObserver.OnCompletedCalled.Should().BeFalse();
|
||||||
|
completedTaskObserver.OnErrorCalled.Should().BeFalse();
|
||||||
|
UniTask.CompletedTask.ToObservable().Subscribe(completedTaskObserver);
|
||||||
|
completedTaskObserver.OnNextCalled.Should().BeTrue();
|
||||||
|
completedTaskObserver.OnCompletedCalled.Should().BeTrue();
|
||||||
|
completedTaskObserver.OnErrorCalled.Should().BeFalse();
|
||||||
|
|
||||||
|
var delayFrameTaskObserver = new ToObservableObserver<int>();
|
||||||
|
UniTask.DelayFrame(1).ToObservable().Subscribe(delayFrameTaskObserver);
|
||||||
|
delayFrameTaskObserver.OnNextCalled.Should().BeFalse();
|
||||||
|
delayFrameTaskObserver.OnCompletedCalled.Should().BeFalse();
|
||||||
|
delayFrameTaskObserver.OnErrorCalled.Should().BeFalse();
|
||||||
|
await UniTask.DelayFrame(1);
|
||||||
|
delayFrameTaskObserver.OnNextCalled.Should().BeTrue();
|
||||||
|
delayFrameTaskObserver.OnCompletedCalled.Should().BeTrue();
|
||||||
|
delayFrameTaskObserver.OnErrorCalled.Should().BeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
class ToObservableObserver<T> : IObserver<T>
|
||||||
|
{
|
||||||
|
public bool OnNextCalled { get; private set; }
|
||||||
|
public bool OnCompletedCalled { get; private set; }
|
||||||
|
public bool OnErrorCalled { get; private set; }
|
||||||
|
|
||||||
|
public void OnNext(T value) => OnNextCalled = true;
|
||||||
|
public void OnCompleted() => OnCompletedCalled = true;
|
||||||
|
public void OnError(Exception error) => OnErrorCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ namespace UniRx.Async
|
|||||||
}
|
}
|
||||||
else if (current is IEnumerator e3)
|
else if (current is IEnumerator e3)
|
||||||
{
|
{
|
||||||
while (e3.MoveNext())
|
var e4 = ConsumeEnumerator(e3);
|
||||||
|
while (e4.MoveNext())
|
||||||
{
|
{
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
@@ -231,14 +232,6 @@ namespace UniRx.Async
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerator UnwrapEnumerator(IEnumerator enumerator)
|
|
||||||
{
|
|
||||||
while (enumerator.MoveNext())
|
|
||||||
{
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static IEnumerator UnwrapWaitAsyncOperation(AsyncOperation asyncOperation)
|
static IEnumerator UnwrapWaitAsyncOperation(AsyncOperation asyncOperation)
|
||||||
{
|
{
|
||||||
while (!asyncOperation.isDone)
|
while (!asyncOperation.isDone)
|
||||||
|
|||||||
@@ -391,5 +391,5 @@ namespace UniRx.Async.Internal
|
|||||||
public abstract bool MoveNext();
|
public abstract bool MoveNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
@@ -67,13 +67,33 @@ namespace UniRx.Async
|
|||||||
var yieldLoop = new PlayerLoopSystem
|
var yieldLoop = new PlayerLoopSystem
|
||||||
{
|
{
|
||||||
type = loopRunnerYieldType,
|
type = loopRunnerYieldType,
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
updateDelegate = () =>
|
||||||
|
{
|
||||||
|
if (Application.isPlaying)
|
||||||
|
{
|
||||||
|
cq.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
updateDelegate = cq.Run
|
updateDelegate = cq.Run
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
var runnerLoop = new PlayerLoopSystem
|
var runnerLoop = new PlayerLoopSystem
|
||||||
{
|
{
|
||||||
type = loopRunnerType,
|
type = loopRunnerType,
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
updateDelegate = () =>
|
||||||
|
{
|
||||||
|
if (Application.isPlaying)
|
||||||
|
{
|
||||||
|
runner.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
updateDelegate = runner.Run
|
updateDelegate = runner.Run
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2];
|
var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2];
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncBeginDragTrigger : AsyncTriggerBase
|
public class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onBeginDrag;
|
AsyncTriggerPromise<PointerEventData> onBeginDrag;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onBeginDrags;
|
AsyncTriggerPromiseDictionary<PointerEventData> onBeginDrags;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnBeginDrag(PointerEventData eventData)
|
void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onBeginDrag, onBeginDrags, eventData);
|
TrySetResult(onBeginDrag, onBeginDrags, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncCancelTrigger : AsyncTriggerBase
|
public class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<BaseEventData> onCancel;
|
AsyncTriggerPromise<BaseEventData> onCancel;
|
||||||
AsyncTriggerPromiseDictionary<BaseEventData> onCancels;
|
AsyncTriggerPromiseDictionary<BaseEventData> onCancels;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnCancel(BaseEventData eventData)
|
void ICancelHandler.OnCancel(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onCancel, onCancels, eventData);
|
TrySetResult(onCancel, onCancels, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncDeselectTrigger : AsyncTriggerBase
|
public class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<BaseEventData> onDeselect;
|
AsyncTriggerPromise<BaseEventData> onDeselect;
|
||||||
AsyncTriggerPromiseDictionary<BaseEventData> onDeselects;
|
AsyncTriggerPromiseDictionary<BaseEventData> onDeselects;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnDeselect(BaseEventData eventData)
|
void IDeselectHandler.OnDeselect(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onDeselect, onDeselects, eventData);
|
TrySetResult(onDeselect, onDeselects, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncDragTrigger : AsyncTriggerBase
|
public class AsyncDragTrigger : AsyncTriggerBase, IDragHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onDrag;
|
AsyncTriggerPromise<PointerEventData> onDrag;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrags;
|
AsyncTriggerPromiseDictionary<PointerEventData> onDrags;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnDrag(PointerEventData eventData)
|
void IDragHandler.OnDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onDrag, onDrags, eventData);
|
TrySetResult(onDrag, onDrags, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncDropTrigger : AsyncTriggerBase
|
public class AsyncDropTrigger : AsyncTriggerBase, IDropHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onDrop;
|
AsyncTriggerPromise<PointerEventData> onDrop;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrops;
|
AsyncTriggerPromiseDictionary<PointerEventData> onDrops;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnDrop(PointerEventData eventData)
|
void IDropHandler.OnDrop(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onDrop, onDrops, eventData);
|
TrySetResult(onDrop, onDrops, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncEndDragTrigger : AsyncTriggerBase
|
public class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onEndDrag;
|
AsyncTriggerPromise<PointerEventData> onEndDrag;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onEndDrags;
|
AsyncTriggerPromiseDictionary<PointerEventData> onEndDrags;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnEndDrag(PointerEventData eventData)
|
void IEndDragHandler.OnEndDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onEndDrag, onEndDrags, eventData);
|
TrySetResult(onEndDrag, onEndDrags, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncInitializePotentialDragTrigger : AsyncTriggerBase
|
public class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onInitializePotentialDrag;
|
AsyncTriggerPromise<PointerEventData> onInitializePotentialDrag;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onInitializePotentialDrags;
|
AsyncTriggerPromiseDictionary<PointerEventData> onInitializePotentialDrags;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnInitializePotentialDrag(PointerEventData eventData)
|
void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData);
|
TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncMoveTrigger : AsyncTriggerBase
|
public class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<AxisEventData> onMove;
|
AsyncTriggerPromise<AxisEventData> onMove;
|
||||||
AsyncTriggerPromiseDictionary<AxisEventData> onMoves;
|
AsyncTriggerPromiseDictionary<AxisEventData> onMoves;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnMove(AxisEventData eventData)
|
void IMoveHandler.OnMove(AxisEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onMove, onMoves, eventData);
|
TrySetResult(onMove, onMoves, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncPointerClickTrigger : AsyncTriggerBase
|
public class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onPointerClick;
|
AsyncTriggerPromise<PointerEventData> onPointerClick;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerClicks;
|
AsyncTriggerPromiseDictionary<PointerEventData> onPointerClicks;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPointerClick(PointerEventData eventData)
|
void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onPointerClick, onPointerClicks, eventData);
|
TrySetResult(onPointerClick, onPointerClicks, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncPointerDownTrigger : AsyncTriggerBase
|
public class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onPointerDown;
|
AsyncTriggerPromise<PointerEventData> onPointerDown;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerDowns;
|
AsyncTriggerPromiseDictionary<PointerEventData> onPointerDowns;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPointerDown(PointerEventData eventData)
|
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onPointerDown, onPointerDowns, eventData);
|
TrySetResult(onPointerDown, onPointerDowns, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncPointerEnterTrigger : AsyncTriggerBase
|
public class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onPointerEnter;
|
AsyncTriggerPromise<PointerEventData> onPointerEnter;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerEnters;
|
AsyncTriggerPromiseDictionary<PointerEventData> onPointerEnters;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPointerEnter(PointerEventData eventData)
|
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onPointerEnter, onPointerEnters, eventData);
|
TrySetResult(onPointerEnter, onPointerEnters, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncPointerExitTrigger : AsyncTriggerBase
|
public class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onPointerExit;
|
AsyncTriggerPromise<PointerEventData> onPointerExit;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerExits;
|
AsyncTriggerPromiseDictionary<PointerEventData> onPointerExits;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPointerExit(PointerEventData eventData)
|
void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onPointerExit, onPointerExits, eventData);
|
TrySetResult(onPointerExit, onPointerExits, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncPointerUpTrigger : AsyncTriggerBase
|
public class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onPointerUp;
|
AsyncTriggerPromise<PointerEventData> onPointerUp;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerUps;
|
AsyncTriggerPromiseDictionary<PointerEventData> onPointerUps;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPointerUp(PointerEventData eventData)
|
void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onPointerUp, onPointerUps, eventData);
|
TrySetResult(onPointerUp, onPointerUps, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncScrollTrigger : AsyncTriggerBase
|
public class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<PointerEventData> onScroll;
|
AsyncTriggerPromise<PointerEventData> onScroll;
|
||||||
AsyncTriggerPromiseDictionary<PointerEventData> onScrolls;
|
AsyncTriggerPromiseDictionary<PointerEventData> onScrolls;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnScroll(PointerEventData eventData)
|
void IScrollHandler.OnScroll(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onScroll, onScrolls, eventData);
|
TrySetResult(onScroll, onScrolls, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncSelectTrigger : AsyncTriggerBase
|
public class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<BaseEventData> onSelect;
|
AsyncTriggerPromise<BaseEventData> onSelect;
|
||||||
AsyncTriggerPromiseDictionary<BaseEventData> onSelects;
|
AsyncTriggerPromiseDictionary<BaseEventData> onSelects;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnSelect(BaseEventData eventData)
|
void ISelectHandler.OnSelect(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onSelect, onSelects, eventData);
|
TrySetResult(onSelect, onSelects, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncSubmitTrigger : AsyncTriggerBase
|
public class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<BaseEventData> onSubmit;
|
AsyncTriggerPromise<BaseEventData> onSubmit;
|
||||||
AsyncTriggerPromiseDictionary<BaseEventData> onSubmits;
|
AsyncTriggerPromiseDictionary<BaseEventData> onSubmits;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnSubmit(BaseEventData eventData)
|
void ISubmitHandler.OnSubmit(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onSubmit, onSubmits, eventData);
|
TrySetResult(onSubmit, onSubmits, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using UnityEngine.EventSystems;
|
|||||||
namespace UniRx.Async.Triggers
|
namespace UniRx.Async.Triggers
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class AsyncUpdateSelectedTrigger : AsyncTriggerBase
|
public class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler
|
||||||
{
|
{
|
||||||
AsyncTriggerPromise<BaseEventData> onUpdateSelected;
|
AsyncTriggerPromise<BaseEventData> onUpdateSelected;
|
||||||
AsyncTriggerPromiseDictionary<BaseEventData> onUpdateSelecteds;
|
AsyncTriggerPromiseDictionary<BaseEventData> onUpdateSelecteds;
|
||||||
@@ -22,7 +22,7 @@ namespace UniRx.Async.Triggers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnUpdateSelected(BaseEventData eventData)
|
void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData);
|
TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ namespace UniRx.Async
|
|||||||
public IDisposable Subscribe(IObserver<T> observer)
|
public IDisposable Subscribe(IObserver<T> observer)
|
||||||
{
|
{
|
||||||
observer.OnNext(value);
|
observer.OnNext(value);
|
||||||
|
observer.OnCompleted();
|
||||||
return EmptyDisposable.Instance;
|
return EmptyDisposable.Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,30 @@ namespace UniRx.Async
|
|||||||
return new UniTask<UnityEngine.Object>(awaiter);
|
return new UniTask<UnityEngine.Object>(awaiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest resourceRequest)
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||||
|
return new AssetBundleRequestAwaiter(resourceRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<UnityEngine.Object> ToUniTask(this AssetBundleRequest resourceRequest)
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||||
|
return new UniTask<UnityEngine.Object>(new AssetBundleRequestAwaiter(resourceRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<UnityEngine.Object> ConfigureAwait(this AssetBundleRequest resourceRequest, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||||
|
|
||||||
|
var awaiter = new AssetBundleRequestConfiguredAwaiter(resourceRequest, progress, cancellation);
|
||||||
|
if (!awaiter.IsCompleted)
|
||||||
|
{
|
||||||
|
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||||
|
}
|
||||||
|
return new UniTask<UnityEngine.Object>(awaiter);
|
||||||
|
}
|
||||||
|
|
||||||
#if ENABLE_WWW
|
#if ENABLE_WWW
|
||||||
|
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
@@ -443,6 +467,166 @@ namespace UniRx.Async
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct AssetBundleRequestAwaiter : IAwaiter<UnityEngine.Object>
|
||||||
|
{
|
||||||
|
AssetBundleRequest asyncOperation;
|
||||||
|
Action<AsyncOperation> continuationAction;
|
||||||
|
AwaiterStatus status;
|
||||||
|
UnityEngine.Object result;
|
||||||
|
|
||||||
|
public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation)
|
||||||
|
{
|
||||||
|
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||||
|
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||||
|
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null;
|
||||||
|
this.continuationAction = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCompleted => status.IsCompleted();
|
||||||
|
public AwaiterStatus Status => status;
|
||||||
|
|
||||||
|
public UnityEngine.Object GetResult()
|
||||||
|
{
|
||||||
|
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||||
|
|
||||||
|
if (status == AwaiterStatus.Pending)
|
||||||
|
{
|
||||||
|
// first timing of call
|
||||||
|
if (asyncOperation.isDone)
|
||||||
|
{
|
||||||
|
status = AwaiterStatus.Succeeded;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error.ThrowNotYetCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.result = asyncOperation.asset;
|
||||||
|
|
||||||
|
if (continuationAction != null)
|
||||||
|
{
|
||||||
|
asyncOperation.completed -= continuationAction;
|
||||||
|
asyncOperation = null; // remove reference.
|
||||||
|
continuationAction = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asyncOperation = null; // remove reference.
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IAwaiter.GetResult() => GetResult();
|
||||||
|
|
||||||
|
public void OnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
UnsafeOnCompleted(continuation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsafeOnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction);
|
||||||
|
continuationAction = continuation.AsFuncOfT<AsyncOperation>();
|
||||||
|
asyncOperation.completed += continuationAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AssetBundleRequestConfiguredAwaiter : IAwaiter<UnityEngine.Object>, IPlayerLoopItem
|
||||||
|
{
|
||||||
|
AssetBundleRequest asyncOperation;
|
||||||
|
IProgress<float> progress;
|
||||||
|
CancellationToken cancellationToken;
|
||||||
|
AwaiterStatus status;
|
||||||
|
Action continuation;
|
||||||
|
UnityEngine.Object result;
|
||||||
|
|
||||||
|
public AssetBundleRequestConfiguredAwaiter(AssetBundleRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||||
|
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||||
|
: AwaiterStatus.Pending;
|
||||||
|
|
||||||
|
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset;
|
||||||
|
if (this.status.IsCompleted()) return;
|
||||||
|
|
||||||
|
this.asyncOperation = asyncOperation;
|
||||||
|
this.progress = progress;
|
||||||
|
this.cancellationToken = cancellationToken;
|
||||||
|
this.continuation = null;
|
||||||
|
this.result = null;
|
||||||
|
|
||||||
|
TaskTracker.TrackActiveTask(this, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCompleted => status.IsCompleted();
|
||||||
|
public AwaiterStatus Status => status;
|
||||||
|
void IAwaiter.GetResult() => GetResult();
|
||||||
|
|
||||||
|
public UnityEngine.Object GetResult()
|
||||||
|
{
|
||||||
|
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||||
|
|
||||||
|
if (status == AwaiterStatus.Canceled)
|
||||||
|
{
|
||||||
|
Error.ThrowOperationCanceledException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error.ThrowNotYetCompleted<UnityEngine.Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
InvokeContinuation(AwaiterStatus.Canceled);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
progress.Report(asyncOperation.progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asyncOperation.isDone)
|
||||||
|
{
|
||||||
|
this.result = asyncOperation.asset;
|
||||||
|
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InvokeContinuation(AwaiterStatus status)
|
||||||
|
{
|
||||||
|
this.status = status;
|
||||||
|
var cont = this.continuation;
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
this.continuation = null;
|
||||||
|
this.cancellationToken = CancellationToken.None;
|
||||||
|
this.progress = null;
|
||||||
|
this.asyncOperation = null;
|
||||||
|
|
||||||
|
if (cont != null) cont.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||||
|
this.continuation = continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsafeOnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||||
|
this.continuation = continuation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if ENABLE_WWW
|
#if ENABLE_WWW
|
||||||
|
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
Provides an efficient async/await integration to Unity.
|
Provides an efficient async/await integration to Unity.
|
||||||
|
|
||||||
> UniTask was included in UniRx before v6 but now completely separated, it no dependent each other.
|
> UniTask was included in UniRx before v7 but now completely separated, it no dependent each other.
|
||||||
|
|
||||||
Getting started
|
Getting started
|
||||||
---
|
---
|
||||||
Install package is available in [UniTask/releases](https://github.com/Cysharp/UniTask/releases) page.
|
Install package(`UniRx.Async.unitypackage`) is available in [UniTask/releases](https://github.com/Cysharp/UniTask/releases) page.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// extension awaiter/methods can be used by this namespace
|
// extension awaiter/methods can be used by this namespace
|
||||||
@@ -192,6 +192,14 @@ UniTask.DelayFrame
|
|||||||
UniTask.Delay(..., bool ignoreTimeScale = false, ...) parameter
|
UniTask.Delay(..., bool ignoreTimeScale = false, ...) parameter
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Cancellation
|
||||||
|
---
|
||||||
|
|
||||||
|
async void vs async UniTask/UniTaskVoid
|
||||||
|
---
|
||||||
|
|
||||||
|
Progress
|
||||||
|
---
|
||||||
|
|
||||||
For Unit Testing
|
For Unit Testing
|
||||||
---
|
---
|
||||||
@@ -201,4 +209,4 @@ Reference
|
|||||||
|
|
||||||
License
|
License
|
||||||
---
|
---
|
||||||
This library is under the MIT License.
|
This library is under the MIT License.
|
||||||
|
|||||||
Reference in New Issue
Block a user