mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-09-20 06:11:54 +00:00
Create CustomNetworkManager which prevents client from marking itself as ready until the Loaded finishes
This commit is contained in:
parent
00ac3b5153
commit
b66c73457f
3 changed files with 85 additions and 2 deletions
74
Assets/Scripts/Networking/CustomNetworkManager.cs
Normal file
74
Assets/Scripts/Networking/CustomNetworkManager.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using SanAndreasUnity.Utilities;
|
||||
using SanAndreasUnity.Behaviours;
|
||||
|
||||
namespace SanAndreasUnity.Net
|
||||
{
|
||||
|
||||
public class CustomNetworkManager : NetworkManager
|
||||
{
|
||||
|
||||
public override void OnClientConnect(NetworkConnection conn)
|
||||
{
|
||||
if (NetStatus.IsServer)
|
||||
{
|
||||
// just do default action
|
||||
base.OnClientConnect(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
// default method: if no scene was loaded, do Ready/AddPlayer
|
||||
|
||||
// we won't do this until loading process finishes
|
||||
|
||||
if (Loader.HasLoaded)
|
||||
base.OnClientConnect(conn);
|
||||
}
|
||||
|
||||
public override void OnClientSceneChanged(NetworkConnection conn)
|
||||
{
|
||||
if (NetStatus.IsServer)
|
||||
{
|
||||
// just do default action
|
||||
base.OnClientSceneChanged(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
// default method: do Ready/AddPlayer
|
||||
|
||||
// we won't do this until loading process finishes
|
||||
|
||||
if (Loader.HasLoaded)
|
||||
base.OnClientSceneChanged(conn);
|
||||
}
|
||||
|
||||
void OnLoaderFinished()
|
||||
{
|
||||
if (NetStatus.IsServer) // don't do anything on server
|
||||
return;
|
||||
|
||||
if (!NetworkClient.isConnected)
|
||||
{
|
||||
// client is not connected ? hmm... then loading process could not have started
|
||||
Debug.LogErrorFormat("Loader finished, but client is not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
// make client ready
|
||||
if (ClientScene.ready)
|
||||
Debug.LogErrorFormat("Client was made ready before loader finished");
|
||||
else
|
||||
ClientScene.Ready(NetworkClient.connection);
|
||||
|
||||
// add player if specified
|
||||
if (autoCreatePlayer && ClientScene.localPlayer == null)
|
||||
{
|
||||
ClientScene.AddPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Networking/CustomNetworkManager.cs.meta
Normal file
11
Assets/Scripts/Networking/CustomNetworkManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 155a544cb11c9481ea41b4e39d8c4b3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
- send input to server
|
||||
|
||||
- make console available in main menu
|
||||
|
||||
- client must not be marked as ready, until Loader finishes
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue