Network Library Documentation
Loading...
Searching...
No Matches
NetworkServer Class Reference

Singleton MonoBehaviour that initializes and manages the network server logic in a Unity scene. More...

Inheritance diagram for NetworkServer:

Public Member Functions

ServerSideClientInstance NewUser ()
 Instantiates a new server-side user prefab and returns its ServerSideClientInstance component.

Static Public Attributes

static NetworkServer instance

Private Member Functions

void Awake ()
 Unity Awake method that ensures only one instance of the NetworkServer exists (Singleton pattern).
void Start ()
 Initializes server settings, disables VSync, sets target frame rate, and starts the server with specified configuration.
void OnApplicationQuit ()
 Ensures the server is stopped when the application quits.

Private Attributes

DefaultNetworkSettings defaultSettings
ServerSettings serverSettings
GameObject userPrefab
int ccu
int port

Detailed Description

Singleton MonoBehaviour that initializes and manages the network server logic in a Unity scene.

Definition at line 8 of file NetworkServer.cs.

Member Function Documentation

◆ Awake()

void NetworkServer.Awake ( )
private

Unity Awake method that ensures only one instance of the NetworkServer exists (Singleton pattern).

Definition at line 19 of file NetworkServer.cs.

20 {
21 if (instance == null)
22 {
23 instance = this;
24 }
25 else if (instance != this)
26 {
27 Debug.Log("Instance already exists, destroying object!");
28 Destroy(this);
29 }
30 }
static NetworkServer instance

◆ NewUser()

ServerSideClientInstance NetworkServer.NewUser ( )

Instantiates a new server-side user prefab and returns its ServerSideClientInstance component.

Definition at line 54 of file NetworkServer.cs.

55 {
56 return Instantiate(userPrefab).GetComponent<ServerSideClientInstance>();
57 }
GameObject userPrefab

◆ OnApplicationQuit()

void NetworkServer.OnApplicationQuit ( )
private

Ensures the server is stopped when the application quits.

Definition at line 47 of file NetworkServer.cs.

48 {
49 ServerLogic.StopServer();
50 }

◆ Start()

void NetworkServer.Start ( )
private

Initializes server settings, disables VSync, sets target frame rate, and starts the server with specified configuration.

Definition at line 35 of file NetworkServer.cs.

36 {
37 QualitySettings.vSyncCount = 0;
38 Application.targetFrameRate = 30;
39 userPrefab = serverSettings.serverSideUserPrefab;
40 ccu = serverSettings.maxCCU;
41 port = defaultSettings.port;
42 ServerLogic.StartServer(ccu, port, defaultSettings, serverSettings);
43 }
DefaultNetworkSettings defaultSettings
ServerSettings serverSettings

Member Data Documentation

◆ ccu

int NetworkServer.ccu
private

Definition at line 14 of file NetworkServer.cs.

◆ defaultSettings

DefaultNetworkSettings NetworkServer.defaultSettings
private

Definition at line 10 of file NetworkServer.cs.

◆ instance

NetworkServer NetworkServer.instance
static

Definition at line 12 of file NetworkServer.cs.

◆ port

int NetworkServer.port
private

Definition at line 15 of file NetworkServer.cs.

◆ serverSettings

ServerSettings NetworkServer.serverSettings
private

Definition at line 11 of file NetworkServer.cs.

◆ userPrefab

GameObject NetworkServer.userPrefab
private

Definition at line 13 of file NetworkServer.cs.