Unity 5.6.1でC#プロジェクトを更新して後でHololensで実行しようとしています。もともと、このプロジェクトではSystem.Threadingを使用していましたが、Unityの問題のためにタスクを代わりに使用する必要があると思います。C#を使用したUnityビルドエラータスク
Visual Studioでプロジェクトを開くと、タスクを使用して正常に動作します。 Unityでプロジェクトをビルドすると、Tasksが存在しないと表示されます(以下のエラー)。ユニバーサル10 SDKのUnityで.Net 4.6を使ってビルドしています。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace SampleCSApp
{
// Based on http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html
class BaseThread
{
private bool _isDone = false;
private object _handle = new object();
//private System.Threading.Thread _thread = null;
private System.Threading.Tasks.Task _thread = null;
private static int WAIT_FOR_MS = 100;
public bool IsDone
{
get
{
bool tmp;
lock (_handle)
{
tmp = _isDone;
}
return tmp;
}
set
{
lock (_handle)
{
_isDone = value;
}
}
}
public virtual void Start()
{
_thread = new System.Threading.Tasks.Task(Run);
//_thread = new System.Threading.Thread(Run);
_thread.Start();
}
public virtual void Abort()
{
_thread.Dispose();
//_thread.Abort();
}
protected virtual void ThreadFunction() { }
public void WaitFor()
{
while (!IsDone)
{
_thread.Wait(WAIT_FOR_MS);
//System.Threading.Thread.Sleep(WAIT_FOR_MS);
}
}
private void Run()
{
ThreadFunction();
}
}
}
与えられたユニティ・エラー:
資産/ SampleCSApp/BaseThread.cs(14,34):エラーCS0234:型または名前空間名 `タスクは名前空間`システムに存在しません。スレッディング '。アセンブリの参照がありませんか?
店舗の既存の無料のスレッドライブラリを使用する必要があります。使用したコード例は最大ではありません。 –