Engine-Pong/Game/Network/NetworkManager.cs

32 lines
875 B
C#
Raw Permalink Normal View History

2024-02-12 16:35:24 +03:00
using LiteNetLib;
2024-02-09 11:50:16 +03:00
using Syntriax.Engine.Core;
2024-02-12 16:35:24 +03:00
2024-02-09 11:50:16 +03:00
using Syntriax.Engine.Network.Abstract;
namespace Syntriax.Engine.Network;
public class NetworkManager : NetworkBehaviour, INetworkManager
{
private BehaviourCollector<INetworkEntity> entities = null!;
2024-02-12 16:35:24 +03:00
private static int networkIdIndex = 0;
2024-02-09 11:50:16 +03:00
protected override void OnInitialize()
{
base.OnInitialize();
2024-02-12 16:35:24 +03:00
((INetworkEntity)this).SetNetworkId(networkIdIndex++);
2024-02-09 11:50:16 +03:00
entities = new(GameObject.GameManager);
2024-02-12 16:35:24 +03:00
foreach (var entity in entities)
entity.SetNetworkId(networkIdIndex++);
2024-02-09 11:50:16 +03:00
2024-02-12 16:35:24 +03:00
entities.OnCollected += OnCollected;
2024-02-09 11:50:16 +03:00
}
2024-02-12 16:35:24 +03:00
private void OnCollected(BehaviourCollector<INetworkEntity> collector, INetworkEntity entity)
=> entity.SetNetworkId(networkIdIndex++);
protected override void OnMessageReceived(NetPacketReader reader, NetPeer peer) { }
2024-02-09 11:50:16 +03:00
}