mirror of https://github.com/tuyoogame/YooAsset
update yooasset2.0
parent
6fb5a4b946
commit
006d4c6f09
|
@ -12,12 +12,12 @@ namespace Cysharp.Threading.Tasks
|
||||||
{
|
{
|
||||||
public static class OperationHandleBaseExtensions
|
public static class OperationHandleBaseExtensions
|
||||||
{
|
{
|
||||||
public static UniTask.Awaiter GetAwaiter(this OperationHandleBase handle)
|
public static UniTask.Awaiter GetAwaiter(this HandleBase handle)
|
||||||
{
|
{
|
||||||
return ToUniTask(handle).GetAwaiter();
|
return ToUniTask(handle).GetAwaiter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UniTask ToUniTask(this OperationHandleBase handle,
|
public static UniTask ToUniTask(this HandleBase handle,
|
||||||
IProgress<float> progress = null,
|
IProgress<float> progress = null,
|
||||||
PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||||
{
|
{
|
||||||
|
@ -54,15 +54,15 @@ namespace Cysharp.Threading.Tasks
|
||||||
TaskPool.RegisterSizeGetter(typeof(OperationHandleBaserConfiguredSource), () => pool.Size);
|
TaskPool.RegisterSizeGetter(typeof(OperationHandleBaserConfiguredSource), () => pool.Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Action<OperationHandleBase> continuationAction;
|
private readonly Action<HandleBase> continuationAction;
|
||||||
private OperationHandleBase handle;
|
private HandleBase handle;
|
||||||
private IProgress<float> progress;
|
private IProgress<float> progress;
|
||||||
private bool completed;
|
private bool completed;
|
||||||
private UniTaskCompletionSourceCore<AsyncUnit> core;
|
private UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||||
|
|
||||||
OperationHandleBaserConfiguredSource() { continuationAction = Continuation; }
|
OperationHandleBaserConfiguredSource() { continuationAction = Continuation; }
|
||||||
|
|
||||||
public static IUniTaskSource Create(OperationHandleBase handle,
|
public static IUniTaskSource Create(HandleBase handle,
|
||||||
PlayerLoopTiming timing,
|
PlayerLoopTiming timing,
|
||||||
IProgress<float> progress,
|
IProgress<float> progress,
|
||||||
out short token)
|
out short token)
|
||||||
|
@ -83,40 +83,46 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG 在 Unity 2020.3.36 版本测试中, IL2Cpp 会报 如下错误
|
// BUG 在 Unity 2020.3.36 版本测试中, IL2Cpp 会报 如下错误
|
||||||
// BUG ArgumentException: Incompatible Delegate Types. First is System.Action`1[[YooAsset.AssetOperationHandle, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] second is System.Action`1[[YooAsset.OperationHandleBase, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
|
// BUG ArgumentException: Incompatible Delegate Types. First is System.Action`1[[YooAsset.AssetHandle, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] second is System.Action`1[[YooAsset.OperationHandleBase, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
|
||||||
// BUG 也可能报的是 Action '1' Action '1' 的 InvalidCastException
|
// BUG 也可能报的是 Action '1' Action '1' 的 InvalidCastException
|
||||||
// BUG 此处不得不这么修改, 如果后续 Unity 修复了这个问题, 可以恢复之前的写法
|
// BUG 此处不得不这么修改, 如果后续 Unity 修复了这个问题, 可以恢复之前的写法
|
||||||
#if UNITY_2020_BUG
|
#if UNITY_2020_BUG
|
||||||
switch(handle)
|
switch(handle)
|
||||||
{
|
{
|
||||||
case AssetOperationHandle asset_handle:
|
case AssetHandle asset_handle:
|
||||||
asset_handle.Completed += result.AssetContinuation;
|
asset_handle.Completed += result.AssetContinuation;
|
||||||
break;
|
break;
|
||||||
case SceneOperationHandle scene_handle:
|
case SceneHandle scene_handle:
|
||||||
scene_handle.Completed += result.SceneContinuation;
|
scene_handle.Completed += result.SceneContinuation;
|
||||||
break;
|
break;
|
||||||
case SubAssetsOperationHandle sub_asset_handle:
|
case SubAssetsHandle sub_asset_handle:
|
||||||
sub_asset_handle.Completed += result.SubContinuation;
|
sub_asset_handle.Completed += result.SubContinuation;
|
||||||
break;
|
break;
|
||||||
case RawFileOperationHandle raw_file_handle:
|
case RawFileHandle raw_file_handle:
|
||||||
raw_file_handle.Completed += result.RawFileContinuation;
|
raw_file_handle.Completed += result.RawFileContinuation;
|
||||||
break;
|
break;
|
||||||
|
case AllAssetsHandle all_assets_handle:
|
||||||
|
all_assets_handle.Completed += result.AllAssetsContinuation;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch (handle)
|
switch (handle)
|
||||||
{
|
{
|
||||||
case AssetOperationHandle asset_handle:
|
case AssetHandle asset_handle:
|
||||||
asset_handle.Completed += result.continuationAction;
|
asset_handle.Completed += result.continuationAction;
|
||||||
break;
|
break;
|
||||||
case SceneOperationHandle scene_handle:
|
case SceneHandle scene_handle:
|
||||||
scene_handle.Completed += result.continuationAction;
|
scene_handle.Completed += result.continuationAction;
|
||||||
break;
|
break;
|
||||||
case SubAssetsOperationHandle sub_asset_handle:
|
case SubAssetsHandle sub_asset_handle:
|
||||||
sub_asset_handle.Completed += result.continuationAction;
|
sub_asset_handle.Completed += result.continuationAction;
|
||||||
break;
|
break;
|
||||||
case RawFileOperationHandle raw_file_handle:
|
case RawFileHandle raw_file_handle:
|
||||||
raw_file_handle.Completed += result.continuationAction;
|
raw_file_handle.Completed += result.continuationAction;
|
||||||
break;
|
break;
|
||||||
|
case AllAssetsHandle all_assets_handle:
|
||||||
|
all_assets_handle.Completed += result.continuationAction;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
token = result.core.Version;
|
token = result.core.Version;
|
||||||
|
@ -124,29 +130,35 @@ namespace Cysharp.Threading.Tasks
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#if UNITY_2020_BUG
|
#if UNITY_2020_BUG
|
||||||
private void AssetContinuation(AssetOperationHandle handle)
|
private void AssetContinuation(AssetHandle handle)
|
||||||
{
|
{
|
||||||
handle.Completed -= AssetContinuation;
|
handle.Completed -= AssetContinuation;
|
||||||
BaseContinuation();
|
BaseContinuation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SceneContinuation(SceneOperationHandle handle)
|
private void SceneContinuation(SceneHandle handle)
|
||||||
{
|
{
|
||||||
handle.Completed -= SceneContinuation;
|
handle.Completed -= SceneContinuation;
|
||||||
BaseContinuation();
|
BaseContinuation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SubContinuation(SubAssetsOperationHandle handle)
|
private void SubContinuation(SubAssetsHandle handle)
|
||||||
{
|
{
|
||||||
handle.Completed -= SubContinuation;
|
handle.Completed -= SubContinuation;
|
||||||
BaseContinuation();
|
BaseContinuation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RawFileContinuation(RawFileOperationHandle handle)
|
private void RawFileContinuation(RawFileHandle handle)
|
||||||
{
|
{
|
||||||
handle.Completed -= RawFileContinuation;
|
handle.Completed -= RawFileContinuation;
|
||||||
BaseContinuation();
|
BaseContinuation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AllAssetsContinuation(AllAssetsHandle handle)
|
||||||
|
{
|
||||||
|
handle.Completed -= AllAssetsContinuation;
|
||||||
|
BaseContinuation();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void BaseContinuation()
|
private void BaseContinuation()
|
||||||
|
@ -169,22 +181,25 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Continuation(OperationHandleBase _)
|
private void Continuation(HandleBase _)
|
||||||
{
|
{
|
||||||
switch(handle)
|
switch(handle)
|
||||||
{
|
{
|
||||||
case AssetOperationHandle asset_handle:
|
case AssetHandle asset_handle:
|
||||||
asset_handle.Completed -= continuationAction;
|
asset_handle.Completed -= continuationAction;
|
||||||
break;
|
break;
|
||||||
case SceneOperationHandle scene_handle:
|
case SceneHandle scene_handle:
|
||||||
scene_handle.Completed -= continuationAction;
|
scene_handle.Completed -= continuationAction;
|
||||||
break;
|
break;
|
||||||
case SubAssetsOperationHandle sub_asset_handle:
|
case SubAssetsHandle sub_asset_handle:
|
||||||
sub_asset_handle.Completed -= continuationAction;
|
sub_asset_handle.Completed -= continuationAction;
|
||||||
break;
|
break;
|
||||||
case RawFileOperationHandle raw_file_handle:
|
case RawFileHandle raw_file_handle:
|
||||||
raw_file_handle.Completed -= continuationAction;
|
raw_file_handle.Completed -= continuationAction;
|
||||||
break;
|
break;
|
||||||
|
case AllAssetsHandle all_assets_handle:
|
||||||
|
all_assets_handle.Completed -= continuationAction;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseContinuation();
|
BaseContinuation();
|
||||||
|
|
Loading…
Reference in New Issue