예제 #1
0
        public virtual void FromRPC(RPCNode pNetworkSceneNodeRPC)
        {
            _nodeId            = pNetworkSceneNodeRPC.nodeId;
            _nodeName          = pNetworkSceneNodeRPC.nodeName;
            _isMasterNode      = pNetworkSceneNodeRPC.isMasterNode;
            _dynamicPortMin    = pNetworkSceneNodeRPC.portRangeMin;
            _dynamicPortMax    = pNetworkSceneNodeRPC.portRangeMax;
            _masterNodeSetting = new NetworkSceneManagerSetting();
            _masterNodeSetting.FromRPC(pNetworkSceneNodeRPC.masterNodeSettingRPC);
            if (pNetworkSceneNodeRPC.networkSceneTemplatesRPC == null)
            {
                Init(null);
            }

            List <NetworkSceneTemplate> networkSceneTemplates = new List <NetworkSceneTemplate>(pNetworkSceneNodeRPC.networkSceneTemplatesRPC.Length);

            for (int i = 0; i < pNetworkSceneNodeRPC.networkSceneTemplatesRPC.Length; i++)
            {
                NetworkSceneTemplate networkSceneTemplate = new NetworkSceneTemplate();
                networkSceneTemplate.FromRPC(pNetworkSceneNodeRPC.networkSceneTemplatesRPC[i]);
                networkSceneTemplates.Add(networkSceneTemplate);
            }

            Init(networkSceneTemplates.ToArray());
        }
예제 #2
0
 public virtual void FromRPC(RPCNetworkSceneTemplate pTemplateRPC)
 {
     _buildIndex  = pTemplateRPC.buildIndex;
     _sceneName   = pTemplateRPC.sceneName;
     _sceneOffset = pTemplateRPC.sceneOffset;
     _settings    = new NetworkSceneManagerSetting(pTemplateRPC.settings);
 }
예제 #3
0
 public NetworkSceneTemplate(int pBuildIndex, string pSceneName, RPCVector3 pSceneOffset, NetworkSceneManagerSetting pSetting)
 {
     _buildIndex  = pBuildIndex;
     _sceneName   = pSceneName;
     _sceneOffset = pSceneOffset;
     _settings    = pSetting;
 }
예제 #4
0
 public NetworkSceneManagerSetting(NetworkSceneManagerSetting pSetting)
 {
     _maxConnections = pSetting.MaxConnections;
     _useTCP         = pSetting.UseTCP;
     _useMainThreadManagerForRPCs = pSetting.UseMainThreadManagerForRPCs;
     _serverAddress    = new NetworkSceneManagerEndpoint(pSetting.ServerAddress);
     _serverNATAddress = new NetworkSceneManagerEndpoint(pSetting.ServerNATAddress);
     _clientAddress    = new NetworkSceneManagerEndpoint(pSetting.ClientAddress);
     _clientNATAddress = new NetworkSceneManagerEndpoint(pSetting.ClientNATAddress);
 }
예제 #5
0
 public Node(uint pNodeId, string pNodeName, bool pIsMasterNode, ushort pPortRangeMin, ushort pPortRangeMax, NetworkSceneManagerSetting pMasterNodeSetting, NetworkSceneTemplate[] pInitWithNetworkSceneTemplates) : this()
 {
     _nodeId                = pNodeId;
     _nodeName              = pNodeName;
     _isMasterNode          = pIsMasterNode;
     _dynamicPortMin        = pPortRangeMin;
     _dynamicPortMax        = pPortRangeMax;
     _masterNodeSetting     = pMasterNodeSetting;
     _initWithNetworkScenes = pInitWithNetworkSceneTemplates;
     Init(_initWithNetworkScenes);
 }
 //Functions
 #region Unity
 protected virtual void Awake()
 {
     _autoReconnectDelay = new DelayFixedTime(GameTime.FixedTimeUpdater());
     _autoReconnectDelay.Stop();
     _settings              = new NetworkSceneManagerSetting();
     _pendingObjects        = new Dictionary <int, INetworkBehavior>();
     _pendingNetworkObjects = new Dictionary <int, NetworkObject>();
     _tmpMetadata           = new BMSByte();
     if (_networkBehaviorListSO != null)
     {
         _networkBehaviorListSO.behaviorList.Init();
     }
 }
        public virtual void StartAsClient(Scene pScene, NetworkSceneManagerSetting pSettings)
        {
            _settings = pSettings;
            SceneManager.MoveGameObjectToScene(gameObject, pScene);
            Disconnect();
            InitializeDefaults();
            NetWorker client;

            if (_settings.UseTCP)
            {
                client = new TCPClient();
                ((TCPClient)client).Connect(_settings.ClientAddress.Ip, _settings.ClientAddress.Port);
            }
            else
            {
                client = new UDPClient();
                if (_settings.ClientNATAddress == null || _settings.ClientNATAddress.Ip == null || _settings.ClientNATAddress.Ip.Trim().Length == 0)
                {
                    ((UDPClient)client).Connect(_settings.ClientAddress.Ip, _settings.ClientAddress.Port);
                }
                else
                {
                    ((UDPClient)client).Connect(_settings.ClientAddress.Ip, _settings.ClientAddress.Port, _settings.ClientNATAddress.Ip, _settings.ClientNATAddress.Port);
                }
            }

            if (!client.IsBound)
            {
                RaiseNetworkSceneFailedToBind(this, gameObject.scene);
                return;
            }

            UnregisterEventsClient();
            _networker = client;
            RegisterEventsClient();
            SceneReady(gameObject.scene);
            SceneManager.MoveGameObjectToScene(gameObject, gameObject.scene);
            RaiseNetworkSceneStart(this, gameObject.scene);
        }
        public virtual void StartAsServer(Scene pScene, NetworkSceneManagerSetting pSettings)
        {
            _settings = pSettings;
            SceneManager.MoveGameObjectToScene(gameObject, pScene);
            Disconnect();
            InitializeDefaults();
            NetWorker server;

            if (_settings.UseTCP)
            {
                server = new TCPServer(_settings.MaxConnections);
                ((TCPServer)server).Connect(_settings.ServerAddress.Ip, _settings.ServerAddress.Port);
            }
            else
            {
                server = new UDPServer(_settings.MaxConnections);
                if (_settings.ServerNATAddress == null || _settings.ServerNATAddress.Ip == null || _settings.ServerNATAddress.Ip.Trim().Length == 0)
                {
                    ((UDPServer)server).Connect(_settings.ServerAddress.Ip, _settings.ServerAddress.Port);
                }
                else
                {
                    ((UDPServer)server).Connect(_settings.ServerAddress.Ip, _settings.ServerAddress.Port, _settings.ServerNATAddress.Ip, _settings.ServerNATAddress.Port);
                }
            }

            if (!server.IsBound)
            {
                RaiseNetworkSceneFailedToBind(this, pScene);
                return;
            }

            UnregisterEventsServer();
            _networker = server;
            RegisterEventsServer();
            SceneReady(pScene);
            RaiseNetworkSceneStart(this, pScene);
        }
예제 #9
0
 public NodeNetworkSceneTemplate(uint pNodeId, int pBuildIndex, string pSceneName, RPCVector3 pSceneOffset, NetworkSceneManagerSetting pNetworkSceneManagerSetting)
     : base(pBuildIndex, pSceneName, pSceneOffset, pNetworkSceneManagerSetting)
 {
     _nodeId = pNodeId;
 }
예제 #10
0
 public virtual ushort GetPortFromSetting(NetworkSceneManagerSetting pSetting)
 {
     return((_isServer) ? pSetting.ServerAddress.Port : pSetting.ClientAddress.Port);
 }