diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask.meta
deleted file mode 100644
index 311da8b9e..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: fb77f0e0a8472cd45a97a75e7cfbb51b
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs
deleted file mode 100644
index 6228d159c..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace System.Runtime.CompilerServices
-{
- public sealed class AsyncMethodBuilderAttribute : Attribute
- {
- public AsyncMethodBuilderAttribute(Type builderType)
- {
- BuilderType = builderType;
- }
-
- public Type BuilderType { get; }
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta
deleted file mode 100644
index a12218427..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 010eb0dc48af5e645af2ff8cb7f7d1d8
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs
deleted file mode 100644
index 545082372..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs
+++ /dev/null
@@ -1,155 +0,0 @@
-using System;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-
-namespace UniGLTF.AltTask
-{
- ///
- /// Importer 向けに Task を wrap した。
- ///
- /// * EditorやUnitTestなどで、Unity の MainLoop を進行させずに 非同期を進行させることが目的
- ///
- /// Global変数 SynchronizationContext.Current を一時的に変更したいのだが、
- /// システムに予期せぬ副作用を与える可能性があるのでこれを回避。
- /// UniGLTF.AltTask.TaskQueue.Current に同じ機能を与えて、タスクのPost先を制御することにした。
- ///
-
- public interface IAwaiter : INotifyCompletion
- {
- bool IsCompleted { get; }
- void GetResult();
- }
-
- public interface IAwaitable
- {
- IAwaiter GetAwaiter();
- }
-
- public struct AwaitableMethodBuilder
- {
- // https://referencesource.microsoft.com/#mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs
- private AsyncTaskMethodBuilder _methodBuilder;
-
- public static AwaitableMethodBuilder Create() =>
- new AwaitableMethodBuilder { _methodBuilder = AsyncTaskMethodBuilder.Create() };
-
- public void Start(ref TStateMachine stateMachine)
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.Start(ref stateMachine);
- }
-
- public void SetStateMachine(IAsyncStateMachine stateMachine)
- {
- _methodBuilder.SetStateMachine(stateMachine);
- }
- public void SetException(Exception exception)
- {
- _methodBuilder.SetException(exception);
- }
- public void SetResult()
- {
- _methodBuilder.SetResult();
- }
-
- public void AwaitOnCompleted(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : INotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.AwaitOnCompleted(ref awaiter, ref stateMachine);
- }
- public void AwaitUnsafeOnCompleted(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
- }
-
- public Awaitable Task => new Awaitable(_methodBuilder.Task);
- }
-
- [AsyncMethodBuilder(typeof(AwaitableMethodBuilder))]
- public struct Awaitable : IAwaitable
- {
- private Task _task;
-
- public Awaitable(Task task)
- {
- _task = task;
- if (_task.Exception != null)
- {
- throw _task.Exception;
- }
- }
-
- public bool IsCompleted => _task.IsCompleted;
-
- public Exception Exception => _task.Exception;
-
- public IAwaiter GetAwaiter()
- {
- return new Awaiter(this);
- }
-
- public void ContinueWith(Action action)
- {
- _task.ContinueWith((Task, _) =>
- {
- action();
- }, null);
- }
-
- public static Awaitable Run(Func action)
- {
- return new Awaitable(Task.Run(action));
- }
-
- public static Awaitable Run(Action action)
- {
- return new Awaitable(Task.Run(action));
- }
-
- public static Awaitable FromResult(T result)
- {
- return new Awaitable(Task.FromResult(result));
- }
- }
-
- public class Awaiter : IAwaiter
- {
- Awaitable m_task;
-
- public bool IsCompleted
- {
- get
- {
- return m_task.IsCompleted;
- }
- }
-
- public void GetResult()
- {
- if (m_task.Exception != null)
- {
- throw m_task.Exception;
- }
- }
-
- public void OnCompleted(Action continuation)
- {
- var context = TaskQueue.Current;
- this.m_task.ContinueWith(() =>
- {
- context.Post(_ => continuation(), null);
- });
- }
-
- public Awaiter(Awaitable task)
- {
- m_task = task;
- }
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs.meta
deleted file mode 100644
index 4b6350805..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/Awaitable.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 4a5d6155408ca734297a104d9e590d1f
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs
deleted file mode 100644
index 87326a28f..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-using System;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-
-namespace UniGLTF.AltTask
-{
- public interface IAwaiter : INotifyCompletion
- {
- bool IsCompleted { get; }
- T GetResult();
- }
-
- public interface IAwaitable
- {
- IAwaiter GetAwaiter();
- }
-
-
- public struct ExplicitTaskMethodBuilder
- {
- // https://referencesource.microsoft.com/#mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs
- private AsyncTaskMethodBuilder _methodBuilder;
-
- public static ExplicitTaskMethodBuilder Create() =>
- new ExplicitTaskMethodBuilder { _methodBuilder = AsyncTaskMethodBuilder.Create() };
-
- public void Start(ref TStateMachine stateMachine)
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.Start(ref stateMachine);
- }
-
- public void SetStateMachine(IAsyncStateMachine stateMachine)
- {
- _methodBuilder.SetStateMachine(stateMachine);
- }
- public void SetException(Exception exception)
- {
- _methodBuilder.SetException(exception);
- }
- public void SetResult(T result)
- {
- _methodBuilder.SetResult(result);
- }
-
- public void AwaitOnCompleted(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : INotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.AwaitOnCompleted(ref awaiter, ref stateMachine);
- }
- public void AwaitUnsafeOnCompleted(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- _methodBuilder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
- }
-
- public Awaitable Task => new Awaitable(_methodBuilder.Task);
- }
-
- [AsyncMethodBuilder(typeof(ExplicitTaskMethodBuilder<>))]
- public struct Awaitable : IAwaitable
- {
- private Task _task;
-
- public Awaitable(Task task)
- {
- _task = task;
- if (_task.Exception != null)
- {
- throw _task.Exception;
- }
- }
-
- public bool IsCompleted => _task.IsCompleted;
- public T Result => _task.Result;
- public Exception Exception => _task.Exception;
-
- public IAwaiter GetAwaiter()
- {
- return new Awaiter(this);
- }
-
- public void ContinueWith(Action action)
- {
- _task.ContinueWith((Task, _) =>
- {
- action();
- }, null);
- }
-
- public static Awaitable Delay()
- {
- var task = Task.FromResult(default);
- return new Awaitable(task);
- }
- }
-
- public class Awaiter : IAwaiter
- {
- Awaitable m_task;
-
- public bool IsCompleted
- {
- get
- {
- return m_task.IsCompleted;
- }
- }
-
- public T GetResult()
- {
- if (m_task.Exception != null)
- {
- throw m_task.Exception;
- }
- return m_task.Result;
- }
-
- public void OnCompleted(Action continuation)
- {
- var context = TaskQueue.Current;
- this.m_task.ContinueWith(() =>
- {
- context.Post(_ => continuation(), null);
- });
- }
-
- public Awaiter(Awaitable task)
- {
- m_task = task;
- }
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs.meta
deleted file mode 100644
index 3e045b411..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericAwaitable.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 58f3a0011aba9ec4cb9d57a9efd35524
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/NextFrameAwaitable.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/NextFrameAwaitable.cs
deleted file mode 100644
index f1be89203..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/NextFrameAwaitable.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-
-namespace UniGLTF.AltTask
-{
- public static class NextFrameAwaitable
- {
- // TODO
- // loop スレッド使わないようにしたい
- public static Awaitable Create()
- {
- return Awaitable.Run(() =>
- {
- System.Threading.Thread.Sleep(10);
- });
- }
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs
deleted file mode 100644
index 4446f232d..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace UniGLTF.AltTask
-{
- public class TaskQueue : SynchronizationContext, IDisposable
- {
- [ThreadStatic]
- static TaskQueue s_queue;
-
- public new static SynchronizationContext Current
- {
- get
- {
- if (s_queue == null)
- {
- return System.Threading.SynchronizationContext.Current;
- }
- else
- {
- return s_queue;
- }
- }
- }
-
- public override void Post(SendOrPostCallback d, object state)
- {
- m_tasks.Enqueue(() => d(state));
- }
-
- Queue m_tasks = new Queue();
-
- public static TaskQueue Create()
- {
- return new TaskQueue();
- }
-
- TaskQueue()
- {
- s_queue = this;
- }
-
- public void Dispose()
- {
- s_queue = null;
- }
-
- public bool ExecuteOneCallback()
- {
- if (m_tasks.Count == 0)
- {
- return false;
- }
- var task = m_tasks.Dequeue();
- task();
- return true;
- }
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta
deleted file mode 100644
index fef1e0f9d..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 6a65e00e71613c24e865e35173c30be0
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/IAwaitCaller.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/IAwaitCaller.cs
new file mode 100644
index 000000000..33e66388c
--- /dev/null
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/IAwaitCaller.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace UniGLTF
+{
+ ///
+ /// ImporterContext の 非同期実行 LoadAsync を補助する。
+ /// この関数を経由して await すること。
+ /// そうしないと、同期実行 Load 時にデッドロックに陥るかもしれない。
+ /// (SynchronizationContext に Post された 継続が再開されない)
+ ///
+ public interface IAwaitCaller
+ {
+ ///
+ /// フレームレートを維持するために1フレーム待つ
+ ///
+ ///
+ Task NextFrame();
+
+ ///
+ /// 非同期に実行して、終了を待つ
+ ///
+ ///
+ ///
+ Task Run(Action action);
+
+ ///
+ /// 非同期に実行して、終了を待つ
+ ///
+ ///
+ ///
+ ///
+ Task Run(Func action);
+ }
+
+ ///
+ /// 同期実行
+ ///
+ public struct ImmediateCaller : IAwaitCaller
+ {
+ public Task NextFrame()
+ {
+ return Task.FromResult