Skip to content

Commit

Permalink
Applied suggestion by falko17.
Browse files Browse the repository at this point in the history
The initialization of the ServerNetwork uses System.Lazy providing
lazy initialization.

We have temporarily disabled the download of the data from the backend.
This must be re-enabled when the backend is operational.
  • Loading branch information
koschke committed Jul 3, 2024
1 parent 417b2d2 commit f92cd3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
9 changes: 6 additions & 3 deletions Assets/SEE/Net/ClientActionNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Start()
{
if (!IsServer && !IsHost)
{
Network.ServerNetwork?.SyncFilesServerRpc();
Network.ServerNetwork.Value?.SyncFilesServerRpc();
}
}

Expand Down Expand Up @@ -115,7 +115,10 @@ public void SyncFilesClientRpc(string serverId, string backendDomain)
Directory.CreateDirectory(AbsoluteServerContentDirectory);
}
*/
StartCoroutine(GetAllData());

// For the time being, we will not download the data.
// This must be re-enabled once the backend is ready.
// StartCoroutine(GetAllData());
}


Expand Down Expand Up @@ -143,7 +146,7 @@ private IEnumerator GetAllData()

UnzipSources();

Network.ServerNetwork?.SyncClientServerRpc(NetworkManager.Singleton.LocalClientId);
Network.ServerNetwork.Value?.SyncClientServerRpc(NetworkManager.Singleton.LocalClientId);
}

/// <summary>
Expand Down
34 changes: 15 additions & 19 deletions Assets/SEE/Net/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,31 +376,27 @@ static void CheckArgumentValue(string[] arguments, int i, string argument)
}

/// <summary>
/// The <see cref="ServerActionNetwork"/> component attached to the server game object.
/// The gateway to the server.
/// </summary>
private static ServerActionNetwork serverNetwork;
public static readonly Lazy<ServerActionNetwork> ServerNetwork = new(InitServerNetwork);

/// <summary>
/// The gateway to the server.
/// Yields the <see cref="ServerActionNetwork"/> component attached to the Server game object.
/// </summary>
public static ServerActionNetwork ServerNetwork
private static ServerActionNetwork InitServerNetwork()
{
get
const string serverName = "Server";
GameObject server = GameObject.Find(serverName);
if (server != null)
{
if (serverNetwork == null)
{
const string serverName = "Server";
GameObject server = GameObject.Find(serverName);
if (server != null)
{
server.TryGetComponentOrLog(out serverNetwork);
}
else
{
Debug.LogError($"There is no game object named {serverName} in the scene.\n");
}
}
server.TryGetComponentOrLog(out ServerActionNetwork serverNetwork);
return serverNetwork;
}
else
{
Debug.LogError($"There is no game object named {serverName} in the scene.\n");
return null;
}
}

/// <summary>
Expand All @@ -410,7 +406,7 @@ public static ServerActionNetwork ServerNetwork
/// <param name="recipients">List of recipients to broadcast to, will broadcast to all if this is null.</param>
public static void BroadcastAction(String serializedAction, ulong[] recipients)
{
ServerNetwork?.BroadcastActionServerRpc(serializedAction, recipients);
ServerNetwork.Value?.BroadcastActionServerRpc(serializedAction, recipients);
}

/// <summary>
Expand Down

0 comments on commit f92cd3a

Please sign in to comment.