Repository URL to install this package:
|
Version:
2023.12.1 ▾
|
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Gs2.Core.Domain;
using Gs2.Core.Model;
using Gs2.Unity.Core;
using Gs2.Unity.Util;
#if UNITY_2017_1_OR_NEWER
using UnityEngine;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
#endif
#else
using System.Threading.Tasks;
#endif
namespace Gs2.Unity.Gs2StateMachine.Local
{
public class SpeculativeExecuteStreamer
{
private List<ConsumeAction> _consumeActions = new List<ConsumeAction>();
private List<AcquireAction> _acquireActions = new List<AcquireAction>();
public void Attach(
ActiveStateMachine stateMachine
) {
stateMachine.OnIssueTransaction += (consumeActions, acquireActions) =>
{
this._consumeActions.AddRange(consumeActions);
this._acquireActions.AddRange(acquireActions);
};
}
public Gs2Future DispatchFuture(
Gs2Domain gs2,
GameSession gameSession
) {
IEnumerator Impl(Gs2Future result) {
var future = new Gs2.Core.SpeculativeExecutor.SpeculativeExecutor(
this._consumeActions.ToArray(),
this._acquireActions.ToArray(),
1.0
).ExecuteFuture(
gs2.Super,
gameSession.AccessToken
);
this._consumeActions.Clear();
this._acquireActions.Clear();
yield return future;
if (future.Error != null) {
result.OnError(future.Error);
yield break;
}
future.Result.Invoke();
result.OnComplete(null);
}
return new Gs2InlineFuture(Impl);
}
#if !UNITY_2017_1_OR_NEWER || GS2_ENABLE_UNITASK
#if UNITY_2017_1_OR_NEWER
public async UniTask DispatchAsync(
#else
public async Task DispatchAsync(
#endif
Gs2Domain gs2,
GameSession gameSession
) {
var func = await new Gs2.Core.SpeculativeExecutor.SpeculativeExecutor(
this._consumeActions.ToArray(),
this._acquireActions.ToArray(),
1.0
).ExecuteAsync(
gs2.Super,
gameSession.AccessToken
);
this._consumeActions.Clear();
this._acquireActions.Clear();
func.Invoke();
}
#endif
}
}