Server-side scenario execution: new Rudder.Core.dll, realtime/planstore glue removed

- Rudder.Core.dll rebuilt from csharp-sdk effects rewrite (96,768 bytes)
- Realtime/ adapters, UnityRealtimeTransportFactory, UnityPlanStateStore,
  UnityPlanScheduler, WebGL jslib and RealtimeUrl config deleted (with .meta)
- Scenarios sample rewired to client.Effects; samples login path updated
- AGENTS.md/README/CHANGELOG/package docs + agent skill updated; realtime.md skill doc removed
This commit is contained in:
edmand46
2026-09-04 14:23:38 +03:00
parent 22805173eb
commit 6d115f158e
71 changed files with 3338 additions and 1034 deletions
+58 -92
View File
@@ -15,8 +15,8 @@ namespace RudderSdk.Unity
/// <summary>
/// Scene bootstrap MonoBehaviour and public entrypoint of the Rudder Unity SDK.
/// Add the component to a scene with a RudderConfiguration assigned, or call
/// Rudder.Initialize(configuration) and the hidden GameObject is created for you.
/// Put this on a startup scene object, assign a RudderConfiguration, then call
/// <see cref="Initialize"/>. Feature calls live on the returned Core client.
/// </summary>
[DefaultExecutionOrder(-1500), DisallowMultipleComponent]
public class Rudder : MonoBehaviour
@@ -43,33 +43,77 @@ namespace RudderSdk.Unity
if (State != RudderState.Ready || _client == null)
{
throw new InvalidOperationException(
"Rudder is not initialized. Add the Rudder component to the scene with a " +
"RudderConfiguration assigned, or call Rudder.Initialize(configuration).");
"Rudder is not initialized. Add the Rudder component to a scene with a " +
"RudderConfiguration assigned, then call Rudder.Initialize().");
}
return _client;
}
}
/// Completes with the initialized client, or faults with the initialization error.
/// Completes with the client after <see cref="Initialize"/>, or faults on
/// the initialization error. Prefer <see cref="Initialize"/> in game code.
public static Task<CoreClient> Ready => _readyCompletion.Task;
public static void Initialize(RudderConfiguration configuration)
public static CoreClient Initialize()
{
if (configuration == null)
throw new ArgumentNullException(nameof(configuration));
if (State == RudderState.Ready && _client != null)
return _client;
if (State == RudderState.Initializing || State == RudderState.Ready)
throw new InvalidOperationException("Rudder is already initialized.");
if (State == RudderState.Failed)
{
_readyCompletion = NewCompletion();
LastError = null;
State = RudderState.NotInitialized;
}
if (_instance == null)
{
var host = new GameObject(nameof(Rudder));
_instance = host.AddComponent<Rudder>();
throw new InvalidOperationException(
"Rudder is not in the scene. Add the Rudder component to a startup scene " +
"and assign a RudderConfiguration.");
}
_instance._configuration = configuration;
_ = _instance.InitializeAsync();
if (_instance._configuration == null)
{
throw new InvalidOperationException(
"Rudder has no configuration. Assign a RudderConfiguration on the Rudder " +
"component (Assets > Create > Rudder > Configuration).");
}
try
{
State = RudderState.Initializing;
LastError = null;
var options = new RudderUnityClientOptions
{
BaseUrl = _instance._configuration.BaseUrl,
ProjectKey = _instance._configuration.ProjectKey,
TimeoutSeconds = _instance._configuration.TimeoutSeconds,
KeyValueStore = new PlayerPrefsUnityKeyValueStore(),
LoggerSink = new UnityDebugLoggerSink()
};
_client = RudderUnityClientFactory.Create(options);
}
catch (Exception exception)
{
_client = null;
State = RudderState.Failed;
LastError = exception;
_readyCompletion.TrySetException(exception);
Debug.LogError(
"[Rudder] Failed to initialize the Rudder SDK. Check the RudderConfiguration asset " +
$"(ProjectKey and BaseUrl must be set). {exception.Message}");
throw;
}
State = RudderState.Ready;
Debug.Log("[Rudder] Rudder SDK initialized.");
_readyCompletion.TrySetResult(_client);
Initialized?.Invoke(_client);
return _client;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
@@ -95,75 +139,16 @@ namespace RudderSdk.Unity
DontDestroyOnLoad(gameObject);
}
private void Start()
{
if (_instance == this && _configuration != null && State == RudderState.NotInitialized)
_ = InitializeAsync();
}
private async Task InitializeAsync()
{
State = RudderState.Initializing;
LastError = null;
try
{
var options = new RudderUnityClientOptions
{
BaseUrl = _configuration.BaseUrl,
RealtimeUrl = _configuration.RealtimeUrl,
ProjectKey = _configuration.ProjectKey,
TimeoutSeconds = _configuration.TimeoutSeconds,
KeyValueStore = new PlayerPrefsUnityKeyValueStore(),
LoggerSink = new UnityDebugLoggerSink()
};
_client = RudderUnityClientFactory.Create(options);
try
{
await _client.Scenario.RestoreAsync();
}
catch (Exception restoreException)
{
Debug.LogWarning("[Rudder] Failed to restore scenario state: " + restoreException.Message);
}
}
catch (Exception exception)
{
_client = null;
State = RudderState.Failed;
LastError = exception;
_readyCompletion.TrySetException(exception);
Debug.LogError(
"[Rudder] Failed to initialize the Rudder SDK. Check the RudderConfiguration asset " +
$"(ProjectKey and BaseUrl must be set). {exception.Message}");
return;
}
State = RudderState.Ready;
Debug.Log("[Rudder] Rudder SDK initialized.");
_readyCompletion.TrySetResult(_client);
Initialized?.Invoke(_client);
}
private void Update()
{
_client?.Update(Time.deltaTime);
}
private void OnApplicationQuit()
{
DisconnectRealtime();
}
private void OnDestroy()
{
if (_instance != this)
return;
DisconnectRealtime();
_instance = null;
_client = null;
State = RudderState.NotInitialized;
@@ -172,25 +157,6 @@ namespace RudderSdk.Unity
_readyCompletion = NewCompletion();
}
private void DisconnectRealtime()
{
var client = _client;
if (client == null)
return;
try
{
_ = client.Realtime.DisconnectAsync().ContinueWith(
task => Debug.LogWarning(
"[Rudder] Realtime disconnect failed: " + task.Exception?.GetBaseException().Message),
TaskContinuationOptions.OnlyOnFaulted);
}
catch (Exception exception)
{
Debug.LogWarning("[Rudder] Realtime disconnect failed: " + exception.Message);
}
}
private static TaskCompletionSource<CoreClient> NewCompletion()
{
return new TaskCompletionSource<CoreClient>(TaskCreationOptions.RunContinuationsAsynchronously);