2019-09-09 19:07:56 +08:00
|
|
|
|
#if !(UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
|
|
|
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.Scripting;
|
2020-05-05 18:46:43 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2019-09-09 19:07:56 +08:00
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
#endif
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
#if !UNITY_2019_3_OR_NEWER
|
|
|
|
|
using UnityEngine.Experimental.LowLevel;
|
|
|
|
|
#else
|
|
|
|
|
using UnityEngine.LowLevel;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !UNITY_WSA
|
|
|
|
|
using Unity.Jobs;
|
|
|
|
|
#endif
|
|
|
|
|
using Unity.Collections;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine.TestTools;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
2020-05-05 18:46:43 +08:00
|
|
|
|
namespace Cysharp.Threading.TasksTests
|
2019-09-09 19:07:56 +08:00
|
|
|
|
{
|
|
|
|
|
public class RunTest
|
|
|
|
|
{
|
|
|
|
|
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
|
|
|
|
#if !UNITY_WSA
|
|
|
|
|
|
|
|
|
|
//[UnityTest]
|
|
|
|
|
//public IEnumerator RunThread() => UniTask.ToCoroutine(async () =>
|
|
|
|
|
//{
|
|
|
|
|
// var main = Thread.CurrentThread.ManagedThreadId;
|
|
|
|
|
// var v = await UniTask.Run(() => { return System.Threading.Thread.CurrentThread.ManagedThreadId; }, false);
|
|
|
|
|
// UnityEngine.Debug.Log("Ret Value is:" + v);
|
|
|
|
|
// UnityEngine.Debug.Log("Run Here and id:" + System.Threading.Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
// //v.Should().Be(3);
|
|
|
|
|
// main.Should().NotBe(Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator RunThreadConfigure() => UniTask.ToCoroutine(async () =>
|
|
|
|
|
{
|
|
|
|
|
var main = Thread.CurrentThread.ManagedThreadId;
|
|
|
|
|
var v = await UniTask.Run(() => 3, true);
|
|
|
|
|
v.Should().Be(3);
|
|
|
|
|
main.Should().Be(Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//[UnityTest]
|
|
|
|
|
//public IEnumerator RunThreadException() => UniTask.ToCoroutine(async () =>
|
|
|
|
|
//{
|
|
|
|
|
// var main = Thread.CurrentThread.ManagedThreadId;
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// await UniTask.Run<int>(() => throw new Exception(), false);
|
|
|
|
|
// }
|
|
|
|
|
// catch
|
|
|
|
|
// {
|
|
|
|
|
// main.Should().NotBe(Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator RunThreadExceptionConfigure() => UniTask.ToCoroutine(async () =>
|
|
|
|
|
{
|
|
|
|
|
var main = Thread.CurrentThread.ManagedThreadId;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await UniTask.Run<int>(() => throw new Exception(), true);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
main.Should().Be(Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|