using Sandbox.Network;
using System;
namespace Editor;
public static partial class EditorUtility
{
public static partial class Network
{
///
/// True if the network system is active
///
public static bool Active => Networking.System is not null;
///
/// True if the network system is active and we're the host
///
public static bool Hosting => Networking.System?.IsHost ?? false;
///
/// True if the network system is active and we're the host
///
public static bool Client => Networking.System?.IsClient ?? false;
///
/// Determines who can join a lobby hosted from the editor. Should only be set
/// before creating a lobby. Persists between lobbies.
///
public static LobbyPrivacy HostPrivacy
{
get => Networking.EditorLobbyPrivacy;
set => Networking.EditorLobbyPrivacy = value;
}
///
/// Disconnect from the current network session
///
public static void Disconnect() => Networking.Disconnect();
///
/// Connenct to a network address
///
public static void Connect( string address ) => Networking.Connect( address );
///
/// Start hosting a lobby. If we're not already in play mode, we'll enter play mode first.
///
public static void StartHosting()
{
if ( !Game.IsPlaying )
{
EditorScene.Play();
}
Networking.CreateLobby( new LobbyConfig() );
}
///
/// Return all of the channels on this connection.
/// If you're the host, it should return all client connections.
/// If you're the client, it should return empty - unless you're in a p2p session (lobby).
/// Returns empty if you're not connected
///
public static Connection[] Channels
{
get
{
if ( Networking.System is null ) return Array.Empty();
return Networking.System.Connections.ToArray();
}
}
///
/// Return all of the sockets on this connection.
/// If you're the host, it should return all active sockets.
/// If you're the client, it should return empty - unless you're in a p2p session (lobby).
/// Returns empty if you're not connected
///
public static NetworkSocket[] Sockets
{
get
{
if ( Networking.System is null ) return Array.Empty();
return Networking.System.Sockets.ToArray();
}
}
}
}