mirror of https://github.com/Cysharp/UniTask
Compare commits
3 Commits
8b865e05f3
...
d2b7ef06cc
Author | SHA1 | Date |
---|---|---|
|
d2b7ef06cc | |
|
cc3c70af90 | |
|
d9f55b40a5 |
|
@ -35,9 +35,9 @@ jobs:
|
||||||
export-env: false
|
export-env: false
|
||||||
env:
|
env:
|
||||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ jobs:
|
||||||
export-env: false
|
export-env: false
|
||||||
env:
|
env:
|
||||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||||
|
|
||||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
|
@ -15,6 +15,12 @@ namespace Cysharp.Threading.Tasks
|
||||||
return new AnonymousProgress<T>(handler);
|
return new AnonymousProgress<T>(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IProgress<T> Create<T, TState>(TState state, Action<T, TState> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) return NullProgress<T>.Instance;
|
||||||
|
return new AnonymousProgress<T, TState>(handler, state);
|
||||||
|
}
|
||||||
|
|
||||||
public static IProgress<T> CreateOnlyValueChanged<T>(Action<T> handler, IEqualityComparer<T> comparer = null)
|
public static IProgress<T> CreateOnlyValueChanged<T>(Action<T> handler, IEqualityComparer<T> comparer = null)
|
||||||
{
|
{
|
||||||
if (handler == null) return NullProgress<T>.Instance;
|
if (handler == null) return NullProgress<T>.Instance;
|
||||||
|
@ -25,6 +31,16 @@ namespace Cysharp.Threading.Tasks
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IProgress<T> CreateOnlyValueChanged<T, TState>(TState state, Action<T, TState> handler, IEqualityComparer<T> comparer = null)
|
||||||
|
{
|
||||||
|
if (handler == null) return NullProgress<T>.Instance;
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
return new OnlyValueChangedProgress<T, TState>(handler, state, comparer ?? UnityEqualityComparer.GetDefault<T>());
|
||||||
|
#else
|
||||||
|
return new OnlyValueChangedProgress<T, TState>(handler, state, comparer ?? EqualityComparer<T>.Default);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
sealed class NullProgress<T> : IProgress<T>
|
sealed class NullProgress<T> : IProgress<T>
|
||||||
{
|
{
|
||||||
public static readonly IProgress<T> Instance = new NullProgress<T>();
|
public static readonly IProgress<T> Instance = new NullProgress<T>();
|
||||||
|
@ -54,6 +70,23 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class AnonymousProgress<T, TState> : IProgress<T>
|
||||||
|
{
|
||||||
|
readonly Action<T, TState> action;
|
||||||
|
readonly TState state;
|
||||||
|
|
||||||
|
public AnonymousProgress(Action<T, TState> action, TState state)
|
||||||
|
{
|
||||||
|
this.action = action;
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Report(T value)
|
||||||
|
{
|
||||||
|
action(value, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sealed class OnlyValueChangedProgress<T> : IProgress<T>
|
sealed class OnlyValueChangedProgress<T> : IProgress<T>
|
||||||
{
|
{
|
||||||
readonly Action<T> action;
|
readonly Action<T> action;
|
||||||
|
@ -83,5 +116,37 @@ namespace Cysharp.Threading.Tasks
|
||||||
action(value);
|
action(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class OnlyValueChangedProgress<T, TState> : IProgress<T>
|
||||||
|
{
|
||||||
|
readonly Action<T, TState> action;
|
||||||
|
readonly TState state;
|
||||||
|
readonly IEqualityComparer<T> comparer;
|
||||||
|
bool isFirstCall;
|
||||||
|
T latestValue;
|
||||||
|
|
||||||
|
public OnlyValueChangedProgress(Action<T, TState> action, TState state, IEqualityComparer<T> comparer)
|
||||||
|
{
|
||||||
|
this.action = action;
|
||||||
|
this.state = state;
|
||||||
|
this.comparer = comparer;
|
||||||
|
this.isFirstCall = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Report(T value)
|
||||||
|
{
|
||||||
|
if (isFirstCall)
|
||||||
|
{
|
||||||
|
isFirstCall = false;
|
||||||
|
}
|
||||||
|
else if (comparer.Equals(value, latestValue))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
latestValue = value;
|
||||||
|
action(value, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue