Created
July 30, 2024 10:01
-
-
Save somedeveloper00/05b8c13af87fe5bceb1914da2ed4ff40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Fusion; | |
using UnityEngine; | |
using Debug = UnityEngine.Debug; | |
namespace AAA | |
{ | |
public sealed class FusionTest : MonoBehaviour | |
{ | |
public int scene; | |
public string sessionName; | |
public bool autoStartServer; | |
public bool autoStartClient; | |
private void Start() | |
{ | |
if (autoStartServer) | |
{ | |
StartServer(); | |
} | |
if (autoStartClient) | |
{ | |
StartClient(); | |
} | |
} | |
[ContextMenu("Start Server")] | |
public async void StartServer() | |
{ | |
var go = new GameObject("network runner", | |
typeof(NetworkRunner), | |
typeof(NetworkSceneManagerDefault)); | |
var runner = go.GetComponent<NetworkRunner>(); | |
var sm = go.GetComponent<NetworkSceneManagerBase>(); | |
var sw = new Stopwatch(); | |
sw.Start(); | |
var result = await runner.StartGame(new() | |
{ | |
GameMode = GameMode.Server, | |
SessionName = sessionName, | |
IsVisible = false, | |
SceneManager = sm, | |
Scene = scene, | |
}); | |
Debug.LogFormat("StartGame for server finished in {0}ms", sw.Elapsed.TotalSeconds * 1000); | |
} | |
[ContextMenu("Start Client")] | |
public async void StartClient() | |
{ | |
var go = new GameObject("network runner", | |
typeof(NetworkRunner), | |
typeof(NetworkSceneManagerDefault)); | |
var runner = go.GetComponent<NetworkRunner>(); | |
var sm = go.GetComponent<NetworkSceneManagerBase>(); | |
var sw = new Stopwatch(); | |
sw.Start(); | |
var result = await runner.StartGame(new() | |
{ | |
SessionName = sessionName, | |
GameMode = GameMode.Client, | |
SceneManager = sm, | |
Scene = scene, | |
}); | |
Debug.LogFormat("StartGame for client finished in {0}ms", sw.Elapsed.TotalSeconds * 1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment