Engine-Pong/Game/Network/NetworkManager.cs

32 lines
875 B
C#

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