wip: INetworkBehaviour
This commit is contained in:
		
							
								
								
									
										2
									
								
								Engine
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								Engine
									
									
									
									
									
								
							 Submodule Engine updated: 72492a9f5a...be06575f91
									
								
							
							
								
								
									
										15
									
								
								Game/Network/INetworkBehaviour.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Game/Network/INetworkBehaviour.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
using Syntriax.Engine.Core.Abstract;
 | 
			
		||||
 | 
			
		||||
namespace Pong.Network;
 | 
			
		||||
 | 
			
		||||
public interface INetworkBehaviour : IBehaviour
 | 
			
		||||
{
 | 
			
		||||
    int NetworkId { get; }
 | 
			
		||||
 | 
			
		||||
    bool LocalAssigned { get; }
 | 
			
		||||
 | 
			
		||||
    bool IsServer { get; }
 | 
			
		||||
    bool IsClient { get; }
 | 
			
		||||
 | 
			
		||||
    INetworkCommunicator NetworkCommunicator { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								Game/Network/NetworkBehaviour.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Game/Network/NetworkBehaviour.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
using Syntriax.Engine.Core;
 | 
			
		||||
 | 
			
		||||
namespace Pong.Network;
 | 
			
		||||
 | 
			
		||||
public class NetworkBehaviour : BehaviourOverride, INetworkBehaviour
 | 
			
		||||
{
 | 
			
		||||
    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()
 | 
			
		||||
    {
 | 
			
		||||
        if ((BehaviourController.GetBehaviourInParent<INetworkCommunicator>() ?? GameObject.GameManager.FindBehaviour<INetworkCommunicator>()) is not NetworkCommunicator)
 | 
			
		||||
            throw new System.Exception($"Could not find an {nameof(INetworkCommunicator)}.");
 | 
			
		||||
 | 
			
		||||
        if (NetworkCommunicator is INetworkServer server)
 | 
			
		||||
        {
 | 
			
		||||
            IsServer = true;
 | 
			
		||||
            LocalAssigned = true;
 | 
			
		||||
 | 
			
		||||
            // TODO Set and send Network Id
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            IsClient = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user