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