Engine-Pong/Game/Network/NetworkManager.cs

35 lines
1019 B
C#
Raw Normal View History

2024-02-09 11:50:16 +03:00
using System;
using System.Threading.Tasks;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Network.Abstract;
namespace Syntriax.Engine.Network;
public class NetworkManager : NetworkBehaviour, INetworkManager
{
public Action<IGameObject>? OnNetworkGameObjectInstantiated { get; set; } = null;
public INetworkCommunicator Communicator { get; private set; } = null!;
private BehaviourCollector<INetworkEntity> entities = null!;
protected override void OnInitialize()
{
base.OnInitialize();
entities = new(GameObject.GameManager);
}
public Task<T> Instantiate<T>(params object?[]? args) where T : class, IGameObject
{
return Task.Run(() =>
{
if (IsServer)
return GameObject.GameManager.InstantiateGameObject<T>(args);
// Request Instantiation From Server
int id = 0;
return GameObject.GameManager.InstantiateGameObject<T>(args);
});
}
}