Engine-Pong/Game/Network/NetworkBehaviour.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2024-02-08 17:59:04 +03:00
using Syntriax.Engine.Core;
using Syntriax.Engine.Network.Abstract;
2024-02-08 17:59:04 +03:00
namespace Syntriax.Engine.Network;
2024-02-08 17:59:04 +03:00
2024-02-09 11:50:16 +03:00
public class NetworkBehaviour : BehaviourOverride, INetworkBehaviour, INetworkEntity
2024-02-08 17:59:04 +03:00
{
public int NetworkId { get; private set; } = 0;
public bool LocalAssigned { get; private set; } = false;
public bool IsServer { get; private set; } = false;
public bool IsClient { get; private set; } = false;
public INetworkCommunicator NetworkCommunicator { get; private set; } = null!;
protected override void OnInitialize()
{
2024-02-09 11:50:16 +03:00
NetworkCommunicator = BehaviourController.GetBehaviourInParent<INetworkCommunicator>()
?? GameObject.GameManager.FindBehaviour<INetworkCommunicator>()
?? throw new System.Exception($"Could not find an {nameof(INetworkCommunicator)}.");
2024-02-08 17:59:04 +03:00
2024-02-09 11:50:16 +03:00
if (NetworkCommunicator is INetworkClient client)
2024-02-08 17:59:04 +03:00
{
2024-02-09 11:50:16 +03:00
IsClient = true;
return;
}
IsServer = true;
LocalAssigned = true;
2024-02-08 17:59:04 +03:00
// TODO Set and send Network Id
2024-02-08 17:59:04 +03:00
}
2024-02-09 11:50:16 +03:00
int INetworkEntity.NetworkId { get => NetworkId; set => NetworkId = value; }
void INetworkEntity.SetNetworkId(int id) => NetworkId = id;
2024-02-08 17:59:04 +03:00
}