2019-05-19 23:14:47 +08:00
|
|
|
|
|
|
|
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
|
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
|
|
namespace UniRx.Async.Triggers
|
|
|
|
{
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
public class AsyncCollisionTrigger : AsyncTriggerBase
|
|
|
|
{
|
|
|
|
AsyncTriggerPromise<Collision> onCollisionEnter;
|
|
|
|
AsyncTriggerPromiseDictionary<Collision> onCollisionEnters;
|
|
|
|
AsyncTriggerPromise<Collision> onCollisionExit;
|
|
|
|
AsyncTriggerPromiseDictionary<Collision> onCollisionExits;
|
|
|
|
AsyncTriggerPromise<Collision> onCollisionStay;
|
|
|
|
AsyncTriggerPromiseDictionary<Collision> onCollisionStays;
|
|
|
|
|
|
|
|
|
|
|
|
protected override IEnumerable<ICancelablePromise> GetPromises()
|
|
|
|
{
|
|
|
|
return Concat(onCollisionEnter, onCollisionEnters, onCollisionExit, onCollisionExits, onCollisionStay, onCollisionStays);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnCollisionEnter(Collision collision)
|
|
|
|
{
|
|
|
|
TrySetResult(onCollisionEnter, onCollisionEnters, collision);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-30 18:41:23 +08:00
|
|
|
public UniTask<Collision> OnCollisionEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
2019-05-19 23:14:47 +08:00
|
|
|
{
|
|
|
|
return GetOrAddPromise(ref onCollisionEnter, ref onCollisionEnters, cancellationToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnCollisionExit(Collision collisionInfo)
|
|
|
|
{
|
|
|
|
TrySetResult(onCollisionExit, onCollisionExits, collisionInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-30 18:41:23 +08:00
|
|
|
public UniTask<Collision> OnCollisionExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
2019-05-19 23:14:47 +08:00
|
|
|
{
|
|
|
|
return GetOrAddPromise(ref onCollisionExit, ref onCollisionExits, cancellationToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnCollisionStay(Collision collisionInfo)
|
|
|
|
{
|
|
|
|
TrySetResult(onCollisionStay, onCollisionStays, collisionInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-30 18:41:23 +08:00
|
|
|
public UniTask<Collision> OnCollisionStayAsync(CancellationToken cancellationToken = default(CancellationToken))
|
2019-05-19 23:14:47 +08:00
|
|
|
{
|
|
|
|
return GetOrAddPromise(ref onCollisionStay, ref onCollisionStays, cancellationToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|