升级YooAsset->2.1.1、UniTask->2.5.4

升级YooAsset->2.1.1、UniTask->2.5.4
This commit is contained in:
ALEXTANG
2024-04-15 19:37:42 +08:00
parent 83bea559e4
commit d75c1c8c93
88 changed files with 955 additions and 361 deletions

View File

@@ -0,0 +1,14 @@
using System.IO;
using YooAsset.Editor;
namespace UnityGameFramework.Editor
{
[DisplayName("收集着色器")]
public class CollectShader : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
{
return Path.GetExtension(data.AssetPath) == ".shader";
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0e7486840c674c42afd16926eb15ad2d
timeCreated: 1708430564

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e046ba353633f1e4b9552aa50e780fe0
guid: 40ef2e46f900131419e869398a8d3c9d
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1973dbb90ca25d94490075246d04549a
guid: 52e2d973a2156674e8c1c9433ed031f7
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 456b7e008397a8c4c81fac6abd52110a
guid: 5bee3e3860e37484aa3b861bf76d129f
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -7,6 +7,7 @@ using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace Cysharp.Threading.Tasks
@@ -20,17 +21,12 @@ namespace Cysharp.Threading.Tasks
return ToUniTask(handle).GetAwaiter();
}
public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken)
public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately = false, bool autoReleaseWhenCanceled = false)
{
return ToUniTask(handle, cancellationToken: cancellationToken);
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately, autoReleaseWhenCanceled: autoReleaseWhenCanceled);
}
public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately)
{
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
}
public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false, bool autoReleaseWhenCanceled = false)
{
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken);
@@ -49,7 +45,7 @@ namespace Cysharp.Threading.Tasks
return UniTask.CompletedTask;
}
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token);
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, autoReleaseWhenCanceled, out var token), token);
}
public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion
@@ -108,21 +104,23 @@ namespace Cysharp.Threading.Tasks
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size);
}
readonly Action<AsyncOperationHandle> continuationAction;
readonly Action<AsyncOperationHandle> completedCallback;
AsyncOperationHandle handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
IProgress<float> progress;
bool autoReleaseWhenCanceled;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<AsyncUnit> core;
AsyncOperationHandleConfiguredSource()
{
continuationAction = Continuation;
completedCallback = HandleCompleted;
}
public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, bool autoReleaseWhenCanceled, out short token)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -137,6 +135,8 @@ namespace Cysharp.Threading.Tasks
result.handle = handle;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.autoReleaseWhenCanceled = autoReleaseWhenCanceled;
result.completed = false;
if (cancelImmediately && cancellationToken.CanBeCanceled)
@@ -144,6 +144,10 @@ namespace Cysharp.Threading.Tasks
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource)state;
if (promise.autoReleaseWhenCanceled && promise.handle.IsValid())
{
Addressables.Release(promise.handle);
}
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}
@@ -152,25 +156,31 @@ namespace Cysharp.Threading.Tasks
PlayerLoopHelper.AddAction(timing, result);
handle.Completed += result.continuationAction;
handle.Completed += result.completedCallback;
token = result.core.Version;
return result;
}
void Continuation(AsyncOperationHandle _)
void HandleCompleted(AsyncOperationHandle _)
{
handle.Completed -= continuationAction;
if (handle.IsValid())
{
handle.Completed -= completedCallback;
}
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
if (autoReleaseWhenCanceled && handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
}
else if (handle.Status == AsyncOperationStatus.Failed)
@@ -182,12 +192,21 @@ namespace Cysharp.Threading.Tasks
core.TrySetResult(AsyncUnit.Default);
}
}
}
public void GetResult(short token)
{
try
{
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -208,13 +227,16 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return false;
}
if (cancellationToken.IsCancellationRequested)
{
completed = true;
if (autoReleaseWhenCanceled && handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
return false;
}
@@ -248,17 +270,12 @@ namespace Cysharp.Threading.Tasks
return ToUniTask(handle).GetAwaiter();
}
public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle, CancellationToken cancellationToken)
public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle, CancellationToken cancellationToken, bool cancelImmediately = false, bool autoReleaseWhenCanceled = false)
{
return ToUniTask(handle, cancellationToken: cancellationToken);
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately, autoReleaseWhenCanceled: autoReleaseWhenCanceled);
}
public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle, CancellationToken cancellationToken, bool cancelImmediately)
{
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
}
public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false, bool autoReleaseWhenCanceled = false)
{
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled<T>(cancellationToken);
@@ -276,7 +293,7 @@ namespace Cysharp.Threading.Tasks
return UniTask.FromResult(handle.Result);
}
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token);
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, cancelImmediately, autoReleaseWhenCanceled, out var token), token);
}
sealed class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, ITaskPoolNode<AsyncOperationHandleConfiguredSource<T>>
@@ -290,21 +307,23 @@ namespace Cysharp.Threading.Tasks
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource<T>), () => pool.Size);
}
readonly Action<AsyncOperationHandle<T>> continuationAction;
readonly Action<AsyncOperationHandle<T>> completedCallback;
AsyncOperationHandle<T> handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
IProgress<float> progress;
bool autoReleaseWhenCanceled;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<T> core;
AsyncOperationHandleConfiguredSource()
{
continuationAction = Continuation;
completedCallback = HandleCompleted;
}
public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, bool autoReleaseWhenCanceled, out short token)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -320,12 +339,18 @@ namespace Cysharp.Threading.Tasks
result.cancellationToken = cancellationToken;
result.completed = false;
result.progress = progress;
result.autoReleaseWhenCanceled = autoReleaseWhenCanceled;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource<T>)state;
if (promise.autoReleaseWhenCanceled && promise.handle.IsValid())
{
Addressables.Release(promise.handle);
}
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}
@@ -334,25 +359,30 @@ namespace Cysharp.Threading.Tasks
PlayerLoopHelper.AddAction(timing, result);
handle.Completed += result.continuationAction;
handle.Completed += result.completedCallback;
token = result.core.Version;
return result;
}
void Continuation(AsyncOperationHandle<T> argHandle)
void HandleCompleted(AsyncOperationHandle<T> argHandle)
{
handle.Completed -= continuationAction;
if (handle.IsValid())
{
handle.Completed -= completedCallback;
}
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
if (autoReleaseWhenCanceled && handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
}
else if (argHandle.Status == AsyncOperationStatus.Failed)
@@ -364,12 +394,19 @@ namespace Cysharp.Threading.Tasks
core.TrySetResult(argHandle.Result);
}
}
}
public T GetResult(short token)
{
try
{
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
TryReturn();
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -395,13 +432,16 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return false;
}
if (cancellationToken.IsCancellationRequested)
{
completed = true;
if (autoReleaseWhenCanceled && handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
return false;
}

View File

@@ -2,7 +2,8 @@
"name": "UniTask.Addressables",
"references": [
"UniTask",
"Unity.ResourceManager"
"Unity.ResourceManager",
"Unity.Addressables"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d96696960b382384190300495cd26735
guid: 25cb2f742bfeb1d48a4e65d3140b955d
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c517968e1258cb649984dddf2c0ad8b0
guid: 1f448d5bc5b232e4f98d89d5d1832e8e
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a40cecb731a38b340b0d3899da286566
guid: 029c1c1b674aaae47a6841a0b89ad80e
AssemblyDefinitionImporter:
externalObjects: {}
userData:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 3cc67eb6c366477469fdf07a6922c183
guid: f89da606bde9a4e4e94ae1189a029887
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 930414e3dd7d9d746a13c3a0f14ba5e7
guid: 79f4f2475e0b2c44e97ed1dee760627b
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9a4a4017ce5c23445a882e87e8cb103c
guid: e9bb9fc551a975d44a7180e022a2debe
DefaultImporter:
externalObjects: {}
userData:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a9cba699cacf633438f41c07916c83d0
guid: b6ba480edafb67d4e91bb10feb64fae5
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d82b75b6a37050140bd967e8499035d8
guid: dc47925d1a5fa2946bdd37746b2b5d48
AssemblyDefinitionImporter:
externalObjects: {}
userData:

View File

@@ -1,4 +1,9 @@
#pragma warning disable CS1591
#pragma warning disable CS0108
#if (UNITASK_NETCORE && !NETSTANDARD2_0) || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
using System;
using System.Runtime.CompilerServices;
@@ -19,9 +24,8 @@ namespace Cysharp.Threading.Tasks
// similar as IValueTaskSource
public interface IUniTaskSource
#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
: System.Threading.Tasks.Sources.IValueTaskSource
#pragma warning disable CS0108
#endif
{
UniTaskStatus GetStatus(short token);
@@ -30,8 +34,7 @@ namespace Cysharp.Threading.Tasks
UniTaskStatus UnsafeGetStatus(); // only for debug use.
#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0
#pragma warning restore CS0108
#if SUPPORT_VALUETASK
System.Threading.Tasks.Sources.ValueTaskSourceStatus System.Threading.Tasks.Sources.IValueTaskSource.GetStatus(short token)
{
@@ -53,13 +56,13 @@ namespace Cysharp.Threading.Tasks
}
public interface IUniTaskSource<out T> : IUniTaskSource
#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
, System.Threading.Tasks.Sources.IValueTaskSource<T>
#endif
{
new T GetResult(short token);
#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
new public UniTaskStatus GetStatus(short token)
{

View File

@@ -27,7 +27,9 @@ namespace Cysharp.Threading.Tasks.Linq
public static IUniTaskAsyncEnumerable<T> Merge<T>(this IEnumerable<IUniTaskAsyncEnumerable<T>> sources)
{
return new Merge<T>(sources.ToArray());
return sources is IUniTaskAsyncEnumerable<T>[] array
? new Merge<T>(array)
: new Merge<T>(sources.ToArray());
}
public static IUniTaskAsyncEnumerable<T> Merge<T>(params IUniTaskAsyncEnumerable<T>[] sources)

View File

@@ -0,0 +1,104 @@
#pragma warning disable 0649
#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
#if SUPPORT_VALUETASK
using System;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
namespace Cysharp.Threading.Tasks
{
public static class UniTaskValueTaskExtensions
{
public static ValueTask AsValueTask(this in UniTask task)
{
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return new ValueTask(new UniTaskValueTaskSource(task), 0);
#else
return task;
#endif
}
public static ValueTask<T> AsValueTask<T>(this in UniTask<T> task)
{
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return new ValueTask<T>(new UniTaskValueTaskSource<T>(task), 0);
#else
return task;
#endif
}
public static async UniTask<T> AsUniTask<T>(this ValueTask<T> task)
{
return await task;
}
public static async UniTask AsUniTask(this ValueTask task)
{
await task;
}
#if (UNITASK_NETCORE && NETSTANDARD2_0)
class UniTaskValueTaskSource : IValueTaskSource
{
readonly UniTask task;
readonly UniTask.Awaiter awaiter;
public UniTaskValueTaskSource(UniTask task)
{
this.task = task;
this.awaiter = task.GetAwaiter();
}
public void GetResult(short token)
{
awaiter.GetResult();
}
public ValueTaskSourceStatus GetStatus(short token)
{
return (ValueTaskSourceStatus)task.Status;
}
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
{
awaiter.SourceOnCompleted(continuation, state);
}
}
class UniTaskValueTaskSource<T> : IValueTaskSource<T>
{
readonly UniTask<T> task;
readonly UniTask<T>.Awaiter awaiter;
public UniTaskValueTaskSource(UniTask<T> task)
{
this.task = task;
this.awaiter = task.GetAwaiter();
}
public T GetResult(short token)
{
return awaiter.GetResult();
}
public ValueTaskSourceStatus GetStatus(short token)
{
return (ValueTaskSourceStatus)task.Status;
}
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
{
awaiter.SourceOnCompleted(continuation, state);
}
}
#endif
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d38f0478933be42d895c37b862540a1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -208,6 +208,7 @@ namespace Cysharp.Threading.Tasks
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
YieldPromise()
@@ -227,6 +228,7 @@ namespace Cysharp.Threading.Tasks
}
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -252,10 +254,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -290,6 +295,7 @@ namespace Cysharp.Threading.Tasks
core.Reset();
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -309,6 +315,7 @@ namespace Cysharp.Threading.Tasks
UniTaskCompletionSourceCore<AsyncUnit> core;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
NextFramePromise()
{
@@ -328,6 +335,7 @@ namespace Cysharp.Threading.Tasks
result.frameCount = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -353,10 +361,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -414,6 +425,7 @@ namespace Cysharp.Threading.Tasks
UniTaskCompletionSourceCore<object> core;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
WaitForEndOfFramePromise()
{
@@ -432,6 +444,7 @@ namespace Cysharp.Threading.Tasks
}
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -457,10 +470,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -533,6 +549,7 @@ namespace Cysharp.Threading.Tasks
int delayFrameCount;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
int currentFrameCount;
UniTaskCompletionSourceCore<AsyncUnit> core;
@@ -556,6 +573,7 @@ namespace Cysharp.Threading.Tasks
result.delayFrameCount = delayFrameCount;
result.cancellationToken = cancellationToken;
result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -581,10 +599,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -653,6 +674,7 @@ namespace Cysharp.Threading.Tasks
delayFrameCount = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -673,6 +695,7 @@ namespace Cysharp.Threading.Tasks
float elapsed;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
@@ -696,6 +719,7 @@ namespace Cysharp.Threading.Tasks
result.delayTimeSpan = (float)delayTimeSpan.TotalSeconds;
result.cancellationToken = cancellationToken;
result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -721,10 +745,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -775,6 +802,7 @@ namespace Cysharp.Threading.Tasks
elapsed = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -795,6 +823,7 @@ namespace Cysharp.Threading.Tasks
int initialFrame;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
@@ -818,6 +847,7 @@ namespace Cysharp.Threading.Tasks
result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds;
result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -843,10 +873,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -897,6 +930,7 @@ namespace Cysharp.Threading.Tasks
elapsed = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -916,6 +950,7 @@ namespace Cysharp.Threading.Tasks
ValueStopwatch stopwatch;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<AsyncUnit> core;
@@ -938,6 +973,7 @@ namespace Cysharp.Threading.Tasks
result.stopwatch = ValueStopwatch.StartNew();
result.delayTimeSpanTicks = delayTimeSpan.Ticks;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -963,10 +999,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -1013,6 +1052,7 @@ namespace Cysharp.Threading.Tasks
stopwatch = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}

View File

@@ -81,6 +81,16 @@ namespace Cysharp.Threading.Tasks
return factory();
}
public static UniTask Create(Func<CancellationToken, UniTask> factory, CancellationToken cancellationToken)
{
return factory(cancellationToken);
}
public static UniTask Create<T>(T state, Func<T, UniTask> factory)
{
return factory(state);
}
public static UniTask<T> Create<T>(Func<UniTask<T>> factory)
{
return factory();
@@ -137,11 +147,19 @@ namespace Cysharp.Threading.Tasks
return () => asyncAction(cancellationToken).Forget();
}
/// <summary>
/// helper of create add UniTaskVoid to delegate.
/// </summary>
public static Action Action<T>(T state, Func<T, UniTaskVoid> asyncAction)
{
return () => asyncAction(state).Forget();
}
#if UNITY_2018_3_OR_NEWER
/// <summary>
/// Create async void(UniTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } ))
/// For example: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } ))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<UniTaskVoid> asyncAction)
{
@@ -150,13 +168,22 @@ namespace Cysharp.Threading.Tasks
/// <summary>
/// Create async void(UniTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
/// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<CancellationToken, UniTaskVoid> asyncAction, CancellationToken cancellationToken)
{
return () => asyncAction(cancellationToken).Forget();
}
/// <summary>
/// Create async void(UniTaskVoid) UnityAction.
/// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, Argument))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction<T>(T state, Func<T, UniTaskVoid> asyncAction)
{
return () => asyncAction(state).Forget();
}
#endif
/// <summary>

View File

@@ -49,6 +49,7 @@ namespace Cysharp.Threading.Tasks
Func<bool> predicate;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
@@ -70,6 +71,7 @@ namespace Cysharp.Threading.Tasks
result.predicate = predicate;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -95,10 +97,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -147,6 +152,7 @@ namespace Cysharp.Threading.Tasks
predicate = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -165,6 +171,7 @@ namespace Cysharp.Threading.Tasks
Func<bool> predicate;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
@@ -211,10 +218,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -263,6 +273,7 @@ namespace Cysharp.Threading.Tasks
predicate = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -280,6 +291,7 @@ namespace Cysharp.Threading.Tasks
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<object> core;
@@ -287,7 +299,7 @@ namespace Cysharp.Threading.Tasks
{
}
public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, bool completeImmediately, out short token)
public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, bool cancelImmediately, out short token)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -300,8 +312,9 @@ namespace Cysharp.Threading.Tasks
}
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (completeImmediately && cancellationToken.CanBeCanceled)
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
@@ -325,10 +338,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
{
@@ -362,6 +378,7 @@ namespace Cysharp.Threading.Tasks
core.Reset();
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -385,6 +402,7 @@ namespace Cysharp.Threading.Tasks
IEqualityComparer<U> equalityComparer;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<U> core;
@@ -410,6 +428,7 @@ namespace Cysharp.Threading.Tasks
result.currentValue = monitorFunction(target);
result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault<U>();
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -435,10 +454,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -497,6 +519,7 @@ namespace Cysharp.Threading.Tasks
equalityComparer = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}
@@ -519,6 +542,7 @@ namespace Cysharp.Threading.Tasks
IEqualityComparer<U> equalityComparer;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<U> core;
@@ -543,6 +567,7 @@ namespace Cysharp.Threading.Tasks
result.currentValue = monitorFunction(target);
result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault<U>();
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -568,10 +593,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -630,6 +658,7 @@ namespace Cysharp.Threading.Tasks
equalityComparer = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}

View File

@@ -1,6 +1,10 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CS0436
#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
using Cysharp.Threading.Tasks.CompilerServices;
using System;
using System.Diagnostics;
@@ -69,7 +73,7 @@ namespace Cysharp.Threading.Tasks
return new UniTask<bool>(new IsCanceledSource(source), token);
}
#if !UNITY_2018_3_OR_NEWER
#if SUPPORT_VALUETASK
public static implicit operator System.Threading.Tasks.ValueTask(in UniTask self)
{
@@ -78,7 +82,7 @@ namespace Cysharp.Threading.Tasks
return default;
}
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return self.AsValueTask();
#else
return new System.Threading.Tasks.ValueTask(self.source, self.token);
@@ -440,7 +444,7 @@ namespace Cysharp.Threading.Tasks
return self.AsUniTask();
}
#if !UNITY_2018_3_OR_NEWER
#if SUPPORT_VALUETASK
public static implicit operator System.Threading.Tasks.ValueTask<T>(in UniTask<T> self)
{
@@ -449,7 +453,7 @@ namespace Cysharp.Threading.Tasks
return new System.Threading.Tasks.ValueTask<T>(self.result);
}
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return self.AsValueTask();
#else
return new System.Threading.Tasks.ValueTask<T>(self.source, self.token);

View File

@@ -454,7 +454,7 @@ namespace Cysharp.Threading.Tasks
}
/// <summary>
/// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled).
/// Timeout with suppress OperationCanceledException. Returns (bool, IsCanceled).
/// </summary>
public static async UniTask<bool> TimeoutWithoutException(this UniTask task, TimeSpan timeout, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null)
{

View File

@@ -101,6 +101,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<UnityEngine.Object[]> core;
@@ -127,6 +128,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -155,10 +157,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -216,6 +221,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -223,10 +229,9 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -240,7 +245,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endif
#endif

View File

@@ -45,7 +45,7 @@ namespace Cysharp.Threading.Tasks
AsyncGPUReadbackRequest asyncOperation;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
UniTaskCompletionSourceCore<AsyncGPUReadbackRequest> core;
AsyncGPUReadbackRequestAwaiterConfiguredSource()
@@ -66,6 +66,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
if (cancelImmediately && cancellationToken.CanBeCanceled)
{
@@ -91,10 +92,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -146,6 +150,7 @@ namespace Cysharp.Threading.Tasks
asyncOperation = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
}

View File

@@ -97,6 +97,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<AsyncUnit> core;
@@ -123,6 +124,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -151,10 +153,13 @@ namespace Cysharp.Threading.Tasks
core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
public UniTaskStatus GetStatus(short token)
@@ -209,6 +214,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -216,10 +222,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -231,7 +235,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endregion
@@ -320,6 +323,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<UnityEngine.Object> core;
@@ -346,6 +350,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -374,10 +379,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -436,6 +444,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -443,10 +452,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -458,7 +465,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endregion
@@ -548,6 +554,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<UnityEngine.Object> core;
@@ -574,6 +581,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -602,10 +610,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -664,6 +675,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -671,10 +683,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -686,7 +696,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endregion
#endif
@@ -777,6 +786,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<AssetBundle> core;
@@ -803,6 +813,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -831,10 +842,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -893,6 +907,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -900,10 +915,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -915,7 +928,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endregion
#endif
@@ -1021,6 +1033,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<UnityWebRequest> core;
@@ -1047,6 +1060,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -1076,10 +1090,13 @@ namespace Cysharp.Threading.Tasks
return core.GetResult(token);
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
void IUniTaskSource.GetResult(short token)
{
@@ -1146,6 +1163,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -1153,10 +1171,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -1172,7 +1188,6 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
#endregion
#endif

View File

@@ -165,6 +165,7 @@ namespace Cysharp.Threading.Tasks
IProgress<float> progress;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
bool cancelImmediately;
bool completed;
UniTaskCompletionSourceCore<<#= IsVoid(t) ? "AsyncUnit" : t.returnType #>> core;
@@ -191,6 +192,7 @@ namespace Cysharp.Threading.Tasks
result.asyncOperation = asyncOperation;
result.progress = progress;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;
result.completed = false;
asyncOperation.completed += result.continuationAction;
@@ -226,10 +228,13 @@ namespace Cysharp.Threading.Tasks
<# } #>
}
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
}
}
<# if (!IsVoid(t)) { #>
void IUniTaskSource.GetResult(short token)
@@ -304,6 +309,7 @@ namespace Cysharp.Threading.Tasks
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
cancelImmediately = default;
return pool.TryPush(this);
}
@@ -311,10 +317,8 @@ namespace Cysharp.Threading.Tasks
{
if (completed)
{
TryReturn();
return;
}
else
{
completed = true;
if (cancellationToken.IsCancellationRequested)
{
@@ -337,7 +341,6 @@ namespace Cysharp.Threading.Tasks
<# } #>
}
}
}
#endregion
<# if(IsUnityWebRequest(t) || IsAssetBundleModule(t)) { #>

View File

@@ -4,4 +4,3 @@
[assembly: InternalsVisibleTo("UniTask.Addressables")]
[assembly: InternalsVisibleTo("UniTask.DOTween")]
[assembly: InternalsVisibleTo("UniTask.TextMeshPro")]
[assembly: InternalsVisibleTo("UniTask.YooAsset")]

View File

@@ -2,7 +2,7 @@
"name": "com.cysharp.unitask",
"displayName": "UniTask",
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
"version": "2.5.0",
"version": "2.5.4",
"unity": "2018.4",
"description": "Provides an efficient async/await integration to Unity.",
"keywords": [ "async/await", "async", "Task", "UniTask" ],

View File

@@ -9,7 +9,7 @@ namespace YooAsset.Editor
public static class AssetBundleBuilderHelper
{
/// <summary>
/// 获取默认的输出根
/// 获取默认的输出根
/// </summary>
public static string GetDefaultBuildOutputRoot()
{

View File

@@ -37,7 +37,7 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
// 构建参数

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// ִ<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>
/// 执行构建
/// </summary>
protected override void ExecuteBuild()
{

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
@@ -20,7 +20,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// ִ<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>
/// 执行构建
/// </summary>
protected override void ExecuteBuild()
{

View File

@@ -166,7 +166,7 @@ namespace YooAsset.Editor
foreach (string assetPath in findAssets)
{
var assetInfo = new AssetInfo(assetPath);
if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo))
if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo))
{
if (result.ContainsKey(assetPath) == false)
{
@@ -228,37 +228,6 @@ namespace YooAsset.Editor
return collectAssetInfo;
}
private bool IsValidateAsset(CollectCommand command, AssetInfo assetInfo)
{
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
return false;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
return false;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return false;
// 忽略Unity引擎无法识别的文件
if (command.IgnoreDefaultType)
{
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
return false;
}
}
if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension))
return false;
return true;
}
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
{
// 根据规则设置过滤资源文件
@@ -312,7 +281,7 @@ namespace YooAsset.Editor
continue;
AssetInfo assetInfo = new AssetInfo(assetPath);
if (IsValidateAsset(command, assetInfo))
if (command.IgnoreRule.IsIgnore(assetInfo) == false)
result.Add(assetInfo);
}
return result;

View File

@@ -10,7 +10,7 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorConfig
{
public const string ConfigVersion = "v2.0.0";
public const string ConfigVersion = "v2.1";
public const string XmlVersion = "Version";
public const string XmlCommon = "Common";
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlLocationToLower = "LocationToLower";
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
public const string XmlIgnoreDefaultType = "IgnoreDefaultType";
public const string XmlIgnoreRuleName = "IgnoreRuleName";
public const string XmlGroup = "Group";
public const string XmlGroupActiveRule = "GroupActiveRule";
@@ -101,7 +101,7 @@ namespace YooAsset.Editor
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false;
package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
packages.Add(package);
// 读取分组配置
@@ -213,7 +213,7 @@ namespace YooAsset.Editor
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString());
packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
root.AppendChild(packageElement);
// 设置分组配置
@@ -258,6 +258,23 @@ namespace YooAsset.Editor
if (configVersion == ConfigVersion)
return true;
// v2.0.0 -> v2.1
if (configVersion == "v2.0.0")
{
// 读取包裹配置
var packageNodeList = root.GetElementsByTagName(XmlPackage);
foreach (var packageNode in packageNodeList)
{
XmlElement packageElement = packageNode as XmlElement;
if (packageElement.HasAttribute(XmlIgnoreRuleName) == false)
packageElement.SetAttribute(XmlIgnoreRuleName, nameof(NormalIgnoreRule));
}
// 更新版本
root.SetAttribute(XmlVersion, "v2.1");
return UpdateXmlConfig(xmlDoc);
}
return false;
}
}

View File

@@ -35,16 +35,16 @@ namespace YooAsset.Editor
/// </summary>
public bool IncludeAssetGUID = false;
/// <summary>
/// 忽略Unity引擎无法识别的文件
/// </summary>
public bool IgnoreDefaultType = true;
/// <summary>
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
/// </summary>
public bool AutoCollectShaders = true;
/// <summary>
/// 资源忽略规则名
/// </summary>
public string IgnoreRuleName = nameof(NormalIgnoreRule);
/// <summary>
/// 分组列表
/// </summary>
@@ -56,6 +56,16 @@ namespace YooAsset.Editor
/// </summary>
public void CheckConfigError()
{
if (string.IsNullOrEmpty(IgnoreRuleName))
{
throw new Exception($"{nameof(IgnoreRuleName)} is null or empty !");
}
else
{
if (AssetBundleCollectorSettingData.HasIgnoreRuleName(IgnoreRuleName) == false)
throw new Exception($"Invalid {nameof(IIgnoreRule)} class type : {IgnoreRuleName} in package : {PackageName}");
}
foreach (var group in Groups)
{
group.CheckConfigError();
@@ -68,6 +78,14 @@ namespace YooAsset.Editor
public bool FixConfigError()
{
bool isFixed = false;
if (string.IsNullOrEmpty(IgnoreRuleName))
{
Debug.LogWarning($"Set the {nameof(IgnoreRuleName)} to {nameof(NormalIgnoreRule)}");
IgnoreRuleName = nameof(NormalIgnoreRule);
isFixed = true;
}
foreach (var group in Groups)
{
if (group.FixConfigError())
@@ -75,6 +93,7 @@ namespace YooAsset.Editor
isFixed = true;
}
}
return isFixed;
}

View File

@@ -24,7 +24,6 @@ namespace YooAsset.Editor
/// </summary>
public bool UniqueBundleName = false;
/// <summary>
/// 包裹列表
/// </summary>
@@ -100,13 +99,13 @@ namespace YooAsset.Editor
package.CheckConfigError();
// 创建资源收集命令
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
CollectCommand command = new CollectCommand(buildMode, packageName,
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
package.IgnoreDefaultType,
package.AutoCollectShaders,
UniqueBundleName);
UniqueBundleName, ignoreRule);
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);

View File

@@ -21,6 +21,9 @@ namespace YooAsset.Editor
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
private static readonly Dictionary<string, System.Type> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
/// <summary>
/// 配置数据是否被修改
/// </summary>
@@ -129,6 +132,29 @@ namespace YooAsset.Editor
_cacheActiveRuleTypes.Add(type.Name, type);
}
}
// IIgnoreRule
{
// 清空缓存集合
_cacheIgnoreRuleTypes.Clear();
_cacheIgnoreRuleInstance.Clear();
// 获取所有类型
List<Type> types = new List<Type>(100)
{
typeof(NormalIgnoreRule),
typeof(RawFileIgnoreRule),
};
var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule));
types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++)
{
Type type = types[i];
if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false)
_cacheIgnoreRuleTypes.Add(type.Name, type);
}
}
}
private static AssetBundleCollectorSetting _setting = null;
@@ -165,6 +191,7 @@ namespace YooAsset.Editor
if (isFixed)
{
IsDirty = true;
Debug.Log("Fix package config error done !");
}
}
@@ -225,6 +252,18 @@ namespace YooAsset.Editor
}
return names;
}
public static List<RuleDisplayName> GetIgnoreRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheIgnoreRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
private static string GetRuleDisplayName(string name, Type type)
{
var attribute = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
@@ -250,6 +289,10 @@ namespace YooAsset.Editor
{
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
}
public static bool HasIgnoreRuleName(string ruleName)
{
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
}
public static IActiveRule GetActiveRuleInstance(string ruleName)
{
@@ -319,6 +362,23 @@ namespace YooAsset.Editor
throw new Exception($"{nameof(IFilterRule)} is invalid{ruleName}");
}
}
public static IIgnoreRule GetIgnoreRuleInstance(string ruleName)
{
if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance))
return instance;
// 如果不存在创建类的实例
if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type))
{
instance = (IIgnoreRule)Activator.CreateInstance(type);
_cacheIgnoreRuleInstance.Add(ruleName, instance);
return instance;
}
else
{
throw new Exception($"{nameof(IIgnoreRule)} is invalid{ruleName}");
}
}
// 公共参数编辑相关
public static void ModifyShowPackageView(bool showPackageView)

View File

@@ -24,6 +24,7 @@ namespace YooAsset.Editor
private List<RuleDisplayName> _addressRuleList;
private List<RuleDisplayName> _packRuleList;
private List<RuleDisplayName> _filterRuleList;
private List<RuleDisplayName> _ignoreRuleList;
private VisualElement _helpBoxContainer;
@@ -39,8 +40,8 @@ namespace YooAsset.Editor
private Toggle _enableAddressableToogle;
private Toggle _locationToLowerToogle;
private Toggle _includeAssetGUIDToogle;
private Toggle _ignoreDefaultTypeToogle;
private Toggle _autoCollectShadersToogle;
private PopupField<RuleDisplayName> _ignoreRulePopupField;
private VisualElement _packageContainer;
private ListView _packageListView;
@@ -77,6 +78,7 @@ namespace YooAsset.Editor
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
_ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames();
VisualElement root = this.rootVisualElement;
@@ -151,17 +153,6 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
_ignoreDefaultTypeToogle = root.Q<Toggle>("IgnoreDefaultType");
_ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.IgnoreDefaultType = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
RefreshWindow();
}
});
_autoCollectShadersToogle = root.Q<Toggle>("AutoCollectShaders");
_autoCollectShadersToogle.RegisterValueChangedCallback(evt =>
{
@@ -173,6 +164,25 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
{
_ignoreRulePopupField = new PopupField<RuleDisplayName>(_ignoreRuleList, 0);
_ignoreRulePopupField.label = "File Ignore Rule";
_ignoreRulePopupField.name = "IgnoreRulePopupField";
_ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
_ignoreRulePopupField.style.width = 300;
_ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
_ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if(selectPackage != null)
{
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
_setting2Container.Add(_ignoreRulePopupField);
}
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
@@ -475,8 +485,8 @@ namespace YooAsset.Editor
_enableAddressableToogle.SetValueWithoutNotify(selectPackage.EnableAddressable);
_locationToLowerToogle.SetValueWithoutNotify(selectPackage.LocationToLower);
_includeAssetGUIDToogle.SetValueWithoutNotify(selectPackage.IncludeAssetGUID);
_ignoreDefaultTypeToogle.SetValueWithoutNotify(selectPackage.IgnoreDefaultType);
_autoCollectShadersToogle.SetValueWithoutNotify(selectPackage.AutoCollectShaders);
_ignoreRulePopupField.SetValueWithoutNotify(GetIgnoreRuleIndex(selectPackage.IgnoreRuleName));
}
else
{
@@ -970,7 +980,7 @@ namespace YooAsset.Editor
if (collector.IsValid() == false)
{
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
collector.CheckConfigError();
return;
}
@@ -980,14 +990,15 @@ namespace YooAsset.Editor
try
{
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild,
_packageNameTxt.value,
_enableAddressableToogle.value,
_locationToLowerToogle.value,
_includeAssetGUIDToogle.value,
_ignoreDefaultTypeToogle.value,
_autoCollectShadersToogle.value,
_uniqueBundleNameToogle.value);
_uniqueBundleNameToogle.value,
ignoreRule);
collector.CheckConfigError();
collectAssetInfos = collector.GetAllCollectAssets(command, group);
}
@@ -1078,6 +1089,15 @@ namespace YooAsset.Editor
}
return 0;
}
private RuleDisplayName GetIgnoreRuleIndex(string ruleName)
{
for (int i = 0; i < _ignoreRuleList.Count; i++)
{
if (_ignoreRuleList[i].ClassName == ruleName)
return _ignoreRuleList[i];
}
return _ignoreRuleList[0];
}
private RuleDisplayName GetActiveRuleIndex(string ruleName)
{
for (int i = 0; i < _activeRuleList.Count; i++)

View File

@@ -21,7 +21,6 @@
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Ignore Default Type" name="IgnoreDefaultType" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement>
</ui:VisualElement>

View File

@@ -13,11 +13,6 @@ namespace YooAsset.Editor
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 忽略Unity引擎无法识别的文件
/// </summary>
public bool IgnoreDefaultType { private set; get; }
/// <summary>
/// 启用可寻址资源定位
/// </summary>
@@ -48,17 +43,24 @@ namespace YooAsset.Editor
/// </summary>
public string ShadersBundleName { private set; get; }
/// <summary>
/// 忽略规则实例
/// </summary>
public IIgnoreRule IgnoreRule { private set; get; }
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool autoCollectShaders, bool uniqueBundleName)
public CollectCommand(EBuildMode buildMode, string packageName,
bool enableAddressable, bool locationToLower, bool includeAssetGUID,
bool autoCollectShaders, bool uniqueBundleName, IIgnoreRule ignoreRule)
{
BuildMode = buildMode;
PackageName = packageName;
EnableAddressable = enableAddressable;
LocationToLower = locationToLower;
IncludeAssetGUID = includeAssetGUID;
IgnoreDefaultType = ignoreDefaultType;
AutoCollectShaders = autoCollectShaders;
UniqueBundleName = uniqueBundleName;
IgnoreRule = ignoreRule;
// 着色器统一全名称
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();

View File

@@ -0,0 +1,11 @@

namespace YooAsset.Editor
{
/// <summary>
/// 资源忽略规则接口
/// </summary>
public interface IIgnoreRule
{
bool IsIgnore(AssetInfo assetInfo);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd55753dbb880fa449bf4e37b33d8ba7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -6,22 +6,6 @@ using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultFilterRule
{
/// <summary>
/// 忽略的文件类型
/// </summary>
private readonly static HashSet<string> _ignoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public static bool IsIgnoreFile(string fileExtension)
{
return _ignoreFileExtensions.Contains(fileExtension);
}
}
[DisplayName("收集所有资源")]
public class CollectAll : IFilterRule
{
@@ -70,6 +54,15 @@ namespace YooAsset.Editor
}
}
[DisplayName("收集着色器")]
public class CollectShader : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
{
return Path.GetExtension(data.AssetPath) == ".shader";
}
}
[DisplayName("收集着色器变种集合")]
public class CollectShaderVariants : IFilterRule
{

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultIgnoreRule
{
/// <summary>
/// 忽略的文件类型
/// </summary>
public readonly static HashSet<string> IgnoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
}
/// <summary>
/// 适配常规的资源构建管线
/// </summary>
public class NormalIgnoreRule : IIgnoreRule
{
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public bool IsIgnore(AssetInfo assetInfo)
{
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
return true;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
return true;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return true;
if (assetInfo.AssetType == typeof(LightmapParameters))
return true;
// 忽略Unity引擎无法识别的文件
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
return true;
}
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
}
}
/// <summary>
/// 适配原生文件构建管线
/// </summary>
public class RawFileIgnoreRule : IIgnoreRule
{
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public bool IsIgnore(AssetInfo assetInfo)
{
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
return true;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
return true;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return true;
if (assetInfo.AssetType == typeof(LightmapParameters))
return true;
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9c1900577194bb4ab49ce4332ccc4bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -147,6 +147,18 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 打包着色器
/// </summary>
[DisplayName("打包着色器文件")]
public class PackShader : IPackRule
{
public PackRuleResult GetPackRuleResult(PackRuleData data)
{
return DefaultPackRule.CreateShadersPackRuleResult();
}
}
/// <summary>
/// 打包着色器变种集合
/// </summary>

View File

@@ -58,8 +58,8 @@ namespace YooAsset.Editor
public bool EnableAddressable;
public bool LocationToLower;
public bool IncludeAssetGUID;
public bool IgnoreDefaultType;
public bool AutoCollectShaders;
public string IgnoreRuleName;
// 构建参数
public bool EnableSharePackRule;

View File

@@ -72,8 +72,8 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("Enable Addressable", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("Location To Lower", $"{buildReport.Summary.LocationToLower}"));
_items.Add(new ItemWrapper("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}"));
_items.Add(new ItemWrapper("Ignore Default Type", $"{buildReport.Summary.IgnoreDefaultType}"));
_items.Add(new ItemWrapper("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}"));
_items.Add(new ItemWrapper("Ignore Rule Name", $"{buildReport.Summary.IgnoreRuleName}"));
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Build Params", string.Empty));

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 07a483743a0f68e4cb55a38570d1b7cd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -111,7 +111,7 @@ namespace YooAsset
// 再验证文件CRC
if (verifyLevel == EVerifyLevel.High)
{
string crc = HashUtility.FileCRC32(filePath);
string crc = HashUtility.FileCRC32Safely(filePath);
if (crc == fileCRC)
return EVerifyResult.Succeed;
else

View File

@@ -23,6 +23,8 @@ namespace YooAsset
return new System.Uri(path).ToString();
#elif UNITY_STANDALONE
return StringUtility.Format("file:///{0}", path);
#elif UNITY_OPENHARMONY
return path;
#else
return path;
#endif

View File

@@ -58,7 +58,12 @@ namespace YooAsset
}
private static string CreateDefaultBuildinRoot()
{
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#if UNITY_OPENHARMONY
return $"file://{path}";
#else
return path;
#endif
}
private static string CreateDefaultSandboxRoot()
{
@@ -176,6 +181,7 @@ namespace YooAsset
/// </summary>
public void SaveSandboxPackageVersionFile(string version)
{
YooLogger.Log($"Save package version : {version}");
string filePath = GetSandboxPackageVersionFilePath();
FileUtility.WriteAllText(filePath, version);
}

View File

@@ -150,5 +150,10 @@ namespace YooAsset
/// 内置资源查询服务接口
/// </summary>
public IBuildinQueryServices BuildinQueryServices = null;
/// <summary>
/// 微信缓存查询服务接口
/// </summary>
public IWechatQueryServices WechatQueryServices = null;
}
}

View File

@@ -100,28 +100,21 @@ namespace YooAsset
if (IsValidWithWarning == false)
return false;
if (SceneObject.IsValid())
{
if (Provider is DatabaseSceneProvider)
{
var temp = Provider as DatabaseSceneProvider;
return temp.UnSuspendLoad();
var provider = Provider as DatabaseSceneProvider;
provider.UnSuspendLoad();
}
else if (Provider is BundledSceneProvider)
{
var temp = Provider as BundledSceneProvider;
return temp.UnSuspendLoad();
var provider = Provider as BundledSceneProvider;
provider.UnSuspendLoad();
}
else
{
throw new System.NotImplementedException();
}
}
else
{
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
return false;
}
return true;
}
/// <summary>

View File

@@ -31,6 +31,22 @@ namespace YooAsset
{
_error = null;
_provider = provider;
// 注意:卸载场景前必须先解除挂起操作
if (provider is DatabaseSceneProvider)
{
var temp = provider as DatabaseSceneProvider;
temp.UnSuspendLoad();
}
else if (provider is BundledSceneProvider)
{
var temp = provider as BundledSceneProvider;
temp.UnSuspendLoad();
}
else
{
throw new System.NotImplementedException();
}
}
internal override void InternalOnStart()
{

View File

@@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class BundledSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
private AsyncOperation _asyncOperation;
private bool _suspendLoadMode;
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@@ -80,7 +80,7 @@ namespace YooAsset
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@@ -106,6 +106,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@@ -128,13 +135,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}

View File

@@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class DatabaseSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
private bool _suspendLoadMode;
private AsyncOperation _asyncOperation;
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@@ -69,7 +69,7 @@ namespace YooAsset
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@@ -95,6 +95,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@@ -118,13 +125,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}

View File

@@ -332,6 +332,7 @@ namespace YooAsset
{
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
_steps = ESteps.PackageCaching;
}
else

View File

@@ -77,7 +77,7 @@ namespace YooAsset
return;
}
string fileHash = HashUtility.FileMD5(_manifestFilePath);
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
if (fileHash != _queryCachePackageHashOp.PackageHash)
{
_steps = ESteps.Done;

View File

@@ -63,7 +63,6 @@ namespace YooAsset
TryLoadCacheManifest,
DownloadManifest,
LoadCacheManifest,
CheckDeserializeManifest,
Done,
}

View File

@@ -10,6 +10,7 @@ namespace YooAsset
private ResourceAssist _assist;
private IBuildinQueryServices _buildinQueryServices;
private IRemoteServices _remoteServices;
private IWechatQueryServices _wechatQueryServices;
public readonly string PackageName;
public DownloadManager Download
@@ -34,11 +35,12 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
{
_assist = assist;
_buildinQueryServices = buildinQueryServices;
_remoteServices = remoteServices;
_wechatQueryServices = wechatQueryServices;
var operation = new WebPlayModeInitializationOperation(this);
OperationSystem.StartOperation(PackageName, operation);
@@ -65,23 +67,13 @@ namespace YooAsset
}
// 查询相关
#if UNITY_WECHAT_GAME
private WeChatWASM.WXFileSystemManager _wxFileSystemMgr;
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
if (_wxFileSystemMgr == null)
_wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager();
string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName;
string result = _wxFileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok");
}
#else
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
if (_wechatQueryServices != null)
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
else
return false;
}
#endif
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);

View File

@@ -184,7 +184,8 @@ namespace YooAsset
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices);
initializeParameters.RemoteServices,
initializeParameters.WechatQueryServices);
}
else
{

View File

@@ -0,0 +1,15 @@

namespace YooAsset
{
public interface IWechatQueryServices
{
/// <summary>
/// 查询是否为微信缓存的资源文件
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
/// <param name="fileCRC">文件哈希值</param>
/// <returns>返回查询结果</returns>
bool Query(string packageName, string fileName, string fileCRC);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6b28ce9425f5eb4f972dcda9fd864f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -214,14 +214,22 @@ namespace YooAsset
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamSHA1(fs);
}
}
/// <summary>
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1Safely(string filePath)
{
try
{
return FileSHA1(filePath);
}
catch (Exception e)
{
YooLogger.Exception(e);
@@ -266,14 +274,22 @@ namespace YooAsset
/// 获取文件的MD5
/// </summary>
public static string FileMD5(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamMD5(fs);
}
}
/// <summary>
/// 获取文件的MD5
/// </summary>
public static string FileMD5Safely(string filePath)
{
try
{
return FileMD5(filePath);
}
catch (Exception e)
{
YooLogger.Exception(e);
@@ -316,14 +332,22 @@ namespace YooAsset
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamCRC32(fs);
}
}
/// <summary>
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32Safely(string filePath)
{
try
{
return FileCRC32(filePath);
}
catch (Exception e)
{
YooLogger.Exception(e);