Ejemplo n.º 1
0
        protected virtual ReceptionistConfig GetReceptionistConfig(string workerType)
        {
            ReceptionistConfig config;

            if (Application.isEditor)
            {
                config = new ReceptionistConfig
                {
                    WorkerType    = workerType,
                    WorkerId      = $"{workerType}-{Guid.NewGuid()}",
                    UseExternalIp = UseExternalIp
                };
            }
            else
            {
                var commandLineArguments = Environment.GetCommandLineArgs();
                var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                config = ReceptionistConfig.CreateConnectionConfigFromCommandLine(commandLineArgs);
                config.UseExternalIp = UseExternalIp;
                if (!commandLineArgs.ContainsKey(RuntimeConfigNames.WorkerId))
                {
                    config.WorkerId = $"{workerType}-{Guid.NewGuid()}";
                }
            }

            return(config);
        }
        public void CreateConnectionConfigFromCommandLine_should_provide_defaults_for_missing_values()
        {
            var parsedArgs = new Dictionary <string, string>();
            var config     = ReceptionistConfig.CreateConnectionConfigFromCommandLine(parsedArgs);

            Assert.AreEqual(RuntimeConfigDefaults.ReceptionistHost, config.ReceptionistHost);
            Assert.AreEqual(RuntimeConfigDefaults.ReceptionistPort, config.ReceptionistPort);
            Assert.AreEqual(RuntimeConfigDefaults.LinkProtocol, config.LinkProtocol);
        }
Ejemplo n.º 3
0
        public void Awake()
        {
            // Taken from DefaultWorldInitalization.cs
            SetupInjectionHooks();                                               // Register hybrid injection hooks
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); // Clean up worlds and player loop

            Application.targetFrameRate = targetFrameRate;
            Worker.OnConnect           += w => Debug.Log($"{w.WorkerId} is connecting");
            Worker.OnDisconnect        += w => Debug.Log($"{w.WorkerId} is disconnecting");

            // Setup template to use for player on connecting client
            PlayerLifecycleConfig.CreatePlayerEntityTemplate = PlayerTemplate.CreatePlayerEntityTemplate;

            if (Application.isEditor)
            {
                var config = new ReceptionistConfig
                {
                    WorkerType = SystemConfig.UnityGameLogic,
                };
                CreateWorker(config, new Vector3(500, 0, 0));
                config = new ReceptionistConfig
                {
                    WorkerType = SystemConfig.UnityClient,
                };
                CreateWorker(config, Vector3.zero);
            }
            else
            {
                var commandLineArguments = Environment.GetCommandLineArgs();
                Debug.LogFormat("Command line {0}", string.Join(" ", commandLineArguments.ToArray()));
                var commandLineArgs = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                var config          = ConnectionUtility.CreateConnectionConfigFromCommandLine(commandLineArgs);
                CreateWorker(config, Vector3.zero);
            }

            if (World.AllWorlds.Count <= 0)
            {
                throw new InvalidConfigurationException(
                          "No worlds have been created, due to invalid worker types being specified. Check the config in" +
                          "Improbable -> Configure editor workers.");
            }

            var worlds = World.AllWorlds.ToArray();

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worlds);
            // Systems don't tick if World.Active isn't set
            World.Active = worlds[0];
        }
        public void CreateConnectionConfigFromCommandLine_should_parse_correctly()
        {
            const string host        = "myhost";
            const short  port        = 10;
            var          networkType = NetworkConnectionType.Tcp.ToString();

            var parsedArgs = new Dictionary <string, string>
            {
                { RuntimeConfigNames.ReceptionistHost, host },
                { RuntimeConfigNames.ReceptionistPort, port.ToString() },
                { RuntimeConfigNames.LinkProtocol, networkType }
            };

            var config = ReceptionistConfig.CreateConnectionConfigFromCommandLine(parsedArgs);

            Assert.AreEqual(host, config.ReceptionistHost);
            Assert.AreEqual(port, config.ReceptionistPort);
            Assert.AreEqual(networkType, config.LinkProtocol.ToString());
        }