online fix
This commit is contained in:
@@ -37,16 +37,7 @@ namespace MegaKoop.Game.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (networkManager == null)
|
||||
{
|
||||
networkManager = SteamCoopNetworkManager.Instance;
|
||||
}
|
||||
|
||||
if (networkManager != null)
|
||||
{
|
||||
networkManager.RegisterHandler(NetworkMessageType.ProjectileSpawn, HandleProjectileSpawnMessage);
|
||||
isRegistered = true;
|
||||
}
|
||||
TryEnsureNetworkManager();
|
||||
|
||||
weaponController.ProjectileSpawned += OnProjectileSpawned;
|
||||
|
||||
@@ -72,6 +63,11 @@ namespace MegaKoop.Game.Networking
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TryEnsureNetworkManager();
|
||||
}
|
||||
|
||||
private bool IsAuthoritative()
|
||||
{
|
||||
if (networkManager == null)
|
||||
@@ -82,6 +78,26 @@ namespace MegaKoop.Game.Networking
|
||||
return networkManager.IsHost;
|
||||
}
|
||||
|
||||
private void TryEnsureNetworkManager()
|
||||
{
|
||||
if (networkManager == null)
|
||||
{
|
||||
networkManager = SteamCoopNetworkManager.Instance;
|
||||
}
|
||||
|
||||
if (networkManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isRegistered)
|
||||
{
|
||||
networkManager.RegisterHandler(NetworkMessageType.ProjectileSpawn, HandleProjectileSpawnMessage);
|
||||
isRegistered = true;
|
||||
ApplyLocalAuthoritySetting();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnProjectileSpawned(WeaponController.ProjectileSpawnEvent spawnEvent)
|
||||
{
|
||||
if (!IsAuthoritative())
|
||||
@@ -89,6 +105,8 @@ namespace MegaKoop.Game.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
networkManager ??= SteamCoopNetworkManager.Instance;
|
||||
|
||||
if (networkManager == null)
|
||||
{
|
||||
return;
|
||||
@@ -96,7 +114,7 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
var message = new ProjectileSpawnMessage(identity.NetworkId, spawnEvent.WeaponIndex, spawnEvent.Position, spawnEvent.Direction, spawnEvent.Speed, spawnEvent.Lifetime, spawnEvent.Damage);
|
||||
byte[] payload = ProjectileSpawnMessage.Serialize(message);
|
||||
networkManager.SendToAll(NetworkMessageType.ProjectileSpawn, payload, EP2PSend.k_EP2PSendUnreliableNoDelay);
|
||||
networkManager.SendToAll(NetworkMessageType.ProjectileSpawn, payload, EP2PSend.k_EP2PSendReliable);
|
||||
}
|
||||
|
||||
private void HandleProjectileSpawnMessage(NetworkMessage message)
|
||||
|
||||
Reference in New Issue
Block a user