Kanda Foundation 0.2.0
Loading...
Searching...
No Matches
App Lifecycle

The Kanda SDK manages the application lifecycle through two main scenes: the Lobby and the Session.

Standard Scenes

Lobby Scene

The Lobby scene is where clients start. It allows users to view active sessions, create new ones, and select content.

Session Scene

The Session scene is the primary scene for training simulations, containing elements like the player rig, UI, and essential services.

When a session is selected in the Lobby, clients transition to the Session scene. Servers start directly in the Session scene and wait for clients to connect. Content scenes are then loaded additively.

Transitioning Between Scenes

From Lobby to Session

When a session is selected in the Lobby, the application transitions to the Session scene. The desired content scene is carried over using the LocalPlayerInfoService.

From Session to Lobby

Clients can return to the Lobby from the Session scene to join or create a new session.

Starting Sessions

The AppLifecycleService provides several methods for starting different types of sessions:

  • StartOfflineSession(): Starts an offline session.
  • StartServerHostedSession(): Starts a server-hosted session (UGS or dedicated server).
  • HostLanSession(): Starts a LAN session as the host.
  • JoinLanSession(string hostIp): Joins a LAN session hosted by another client.

Content Scenes

Content scenes are loaded additively during a session to provide specific training content. These scenes are selected in the Lobby and carried over to the Session scene using the LocalPlayerInfoService. For detailed information on loading content scenes, refer to the Loading Content Scenes page.

Accessing and Using the AppLifecycleService

The AppLifecycleService handles the application lifecycle, moving between the Lobby and Sessions by loading scenes and instantiating relevant ECS worlds. The service can be accessed using the AppServiceLocator.

Here is an example script that demonstrates how to access and use the AppLifecycleService to transition between the Lobby and Session scenes:

using Kanda.Foundation.DependencyInjection;
using Unity.Entities.Content;
using UnityEngine;
public class AppLifecycleExample : MonoBehaviour
{
// A content scene to load when joining session
[SerializeField]
private string _entitySceneName;
[SerializeField]
private WeakObjectSceneReference _entitySceneReference;
// App services
private IAppLifecycleService _appLifecycleService;
private ILocalPlayerInfoService _localPlayerInfoService;
private void Awake()
{
_appLifecycleService = AppServiceLocator.Get<IAppLifecycleService>();
_localPlayerInfoService = AppServiceLocator.Get<ILocalPlayerInfoService>();
_localPlayerInfoService.SetSelectedContentScene(
new ContentSceneMetadata
{
Name = _entitySceneName,
Guid = _entitySceneReference.Id.GlobalId.AssetGUID
});
}
public async void GoToLobby()
{
var result = await _appLifecycleService.GoToLobby();
Debug.Log(result.Succeeded ? "Went to lobby successfully" : "Failed to go to lobby: " + result.Message);
}
public async void StartOfflineSession()
{
var result = await _appLifecycleService.StartOfflineSession();
Debug.Log(result.Succeeded ? "Started offline session successfully" : "Failed to start offline session: " + result.Message);
}
public async void StartServerHostedSession()
{
var result = await _appLifecycleService.StartServerHostedSession();
Debug.Log(result.Succeeded ? "Started server-hosted session successfully" : "Failed to start server-hosted session: " + result.Message);
}
public async void HostLanSession()
{
var result = await _appLifecycleService.HostLanSession();
if (result.Succeeded)
{
Debug.Log($"Hosted LAN session successfully. Endpoint to join: {result.EndpointToJoin}");
}
else
{
Debug.Log("Failed to host LAN session: " + result.Message);
}
}
public async void JoinLanSession(string hostIp)
{
var result = await _appLifecycleService.JoinLanSession(hostIp);
Debug.Log(result.Succeeded ? "Joined LAN session successfully" : "Failed to join LAN session: " + result.Message);
}
}
A service which handles application lifecycle, moving between lobby and sessions by loading scenes an...
Definition AppLifecycleService.cs:22
Task< AppLifecycleResult > GoToLobby()
Instructs application to go to the Lobby.
Task< HostLanSessionResult > HostLanSession()
Instructs application to start a self-hosted LAN session.
Task< AppLifecycleResult > StartServerHostedSession()
Instructs the app to start a server-hosted session. This will be handled differently depending on whe...
Task< AppLifecycleResult > StartOfflineSession()
Instructs the application to start an offline session.
Task< AppLifecycleResult > JoinLanSession(string hostIp)
Instructs application to join a LAN session hosted by someone else.
A service which stores local player information for consumption throughout the application lifecycle.
Definition LocalPlayerInfoService.cs:10
Definition AppLifecycleResult.cs:4
Definition AppEventUtils.cs:5