Example #1
0
        /// <summary>
        ///     Build method that is invoked by commandline
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        public static void Build()
        {
            try
            {
                var commandLine = Environment.GetCommandLineArgs();

                Debug.LogFormat("Want to build with args: {0}", String.Join(", ", commandLine));

                var buildTargetArg =
                    CommandLineUtility.GetCommandLineValue(commandLine, "buildTarget", "local");

                if (string.IsNullOrEmpty(buildTargetArg))
                {
                    // The default above does not get filled when -t parameter is not passed
                    buildTargetArg = BuildEnvironment.Local.ToString();
                    Debug.LogWarningFormat("Using default build target value: \"{0}\".", buildTargetArg);
                }

                BuildEnvironment buildEnvironment;

                switch (buildTargetArg.ToLower())
                {
                case "cloud":
                    buildEnvironment = BuildEnvironment.Cloud;
                    break;

                case "local":
                    buildEnvironment = BuildEnvironment.Local;
                    break;

                default:
                    throw new BuildFailedException("Unknown build target value: " + buildTargetArg);
                }

                var workerTypesArg =
                    CommandLineUtility.GetCommandLineValue(commandLine, BuildConfigNames.BuildWorkerTypes,
                                                           "UnityClient,UnityGameLogic");

                var wantedWorkerPlatforms = GetWorkerPlatforms(workerTypesArg);

                LocalLaunch.BuildConfig();

                foreach (var workerPlatform in wantedWorkerPlatforms)
                {
                    BuildWorkerForEnvironment(workerPlatform, buildEnvironment);
                }
            }
            catch (Exception e)
            {
                // Log the exception so it appears in the command line, and rethrow as a BuildFailedException so the build fails.
                Debug.LogException(e);

                if (e is BuildFailedException)
                {
                    throw;
                }

                throw new BuildFailedException(e);
            }
        }
        /// <summary>
        /// Extracts the Ip address that should be used to connect via the receptionist. The order is as follows:
        /// 1. Try to extract the ip address from command line arguments passed in. This currently only works for Android.
        /// 2. If we are running on an Android Emulator: Use the Ip address necessary to connect locally.
        /// 3. If we are on a physical device (Android & iOS): Try to extract the value from the stored player preferences.
        /// 4. Check if we stored anything inside the IpAddress field and use it, if we have.
        /// 5. Return the default ReceptionistHost (localhost).
        /// </summary>
        /// <returns>Returns the Host IP.</returns>
        protected virtual string GetHostIp()
        {
            var arguments = LaunchArguments.GetArguments();
            var hostIp    =
                CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.ReceptionistHost, string.Empty);

            if (!string.IsNullOrEmpty(hostIp))
            {
                return(hostIp);
            }

            if (Application.isMobilePlatform)
            {
                switch (DeviceInfo.ActiveDeviceType)
                {
                case MobileDeviceType.Virtual:
#if UNITY_ANDROID
                    return(DeviceInfo.AndroidEmulatorDefaultCallbackIp);
#else
                    break;
#endif
                case MobileDeviceType.Physical:
                    return(PlayerPrefs.GetString(HostIpPlayerPrefsKey, IpAddress));
                }
            }

            if (!string.IsNullOrEmpty(IpAddress))
            {
                return(IpAddress);
            }

            return(RuntimeConfigDefaults.ReceptionistHost);
        }
        protected virtual void InitializeClient()
        {
            var arguments   = LaunchArguments.GetArguments();
            var environment = CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.Environment, string.Empty);

            if (string.IsNullOrEmpty(environment))
            {
                environment = PlayerPrefs.GetString(RuntimeConfigNames.Environment, string.Empty);
            }
            else
            {
                PlayerPrefs.SetString(RuntimeConfigNames.Environment, environment);
            }

            if (!string.IsNullOrEmpty(environment))
            {
                ShouldConnectLocally = environment == RuntimeConfigDefaults.LocalEnvironment;
            }

            if (ShouldConnectLocally)
            {
                IpAddress = GetHostIp();
                PlayerPrefs.SetString(HostIpPlayerPrefsKey, IpAddress);
            }
            else
            {
                PlayerPrefs.DeleteKey(HostIpPlayerPrefsKey);
            }

            PlayerPrefs.Save();
        }
        public void GetCommandLineValue_should_get_default_values_when_missing()
        {
            var testValue =
                CommandLineUtility.GetCommandLineValue(new Dictionary <string, string>(), "test-value",
                                                       TestEnum.ValueTwo);

            Assert.AreEqual(TestEnum.ValueTwo, testValue);
        }
Example #5
0
        private string GetReceptionistHostFromArguments()
        {
            var arguments = LaunchArguments.GetArguments();
            var hostIp    =
                CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.ReceptionistHost, string.Empty);

            return(hostIp);
        }
        public void GetCommandLineValue_should_convert_enum_values()
        {
            var testValue = CommandLineUtility.GetCommandLineValue(new Dictionary <string, string>
            {
                { "test-value", "ValueOne" }
            }, "test-value", TestEnum.Zero);

            Assert.AreEqual(TestEnum.ValueOne, testValue);
        }
Example #7
0
        /// <summary>
        ///     Build method that is invoked by commandline
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        public static void Build()
        {
            try
            {
                var commandLine    = Environment.GetCommandLineArgs();
                var buildTargetArg = CommandLineUtility.GetCommandLineValue(commandLine, "buildTarget", "local");

                BuildEnvironment buildEnvironment;
                switch (buildTargetArg.ToLower())
                {
                case "cloud":
                    buildEnvironment = BuildEnvironment.Cloud;
                    break;

                case "local":
                    buildEnvironment = BuildEnvironment.Local;
                    break;

                default:
                    throw new BuildFailedException("Unknown build target value: " + buildTargetArg);
                }

                var workerTypesArg =
                    CommandLineUtility.GetCommandLineValue(commandLine, BuildWorkerTypes,
                                                           "UnityClient,UnityGameLogic");

                var wantedWorkerTypes = workerTypesArg.Split(',');
                foreach (var wantedWorkerType in wantedWorkerTypes)
                {
                    var buildTargetsForWorker           = GetBuildTargetsForWorkerForEnvironment(wantedWorkerType, buildEnvironment);
                    var buildTargetsMissingBuildSupport = BuildSupportChecker.GetBuildTargetsMissingBuildSupport(buildTargetsForWorker);

                    if (buildTargetsMissingBuildSupport.Length > 0)
                    {
                        throw new BuildFailedException(BuildSupportChecker.ConstructMissingSupportMessage(wantedWorkerType, buildEnvironment, buildTargetsMissingBuildSupport));
                    }
                }

                LocalLaunch.BuildConfig();

                foreach (var wantedWorkerType in wantedWorkerTypes)
                {
                    BuildWorkerForEnvironment(wantedWorkerType, buildEnvironment);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                if (e is BuildFailedException)
                {
                    throw;
                }

                throw new BuildFailedException(e);
            }
        }
        private string GetReceptionistHostFromArguments()
        {
#if UNITY_ANDROID
            var arguments = Improbable.Gdk.Mobile.Android.LaunchArguments.GetArguments();
            var hostIp    =
                CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.ReceptionistHost, string.Empty);
            return(hostIp);
#else
            return(string.Empty);
#endif
        }
        public void GetCommandLineValue_should_convert_primitive_values()
        {
            var dictionary = new Dictionary <string, string>
            {
                { "bool-value", "false" },
                { "int-value", "2" },
                { "float-value", "3.0" },
                { "double-value", "15.0" },
            };

            Assert.AreEqual(false, CommandLineUtility.GetCommandLineValue <bool>(dictionary, "bool-value", true));
            Assert.AreEqual(2, CommandLineUtility.GetCommandLineValue <int>(dictionary, "int-value", 0));
            Assert.AreEqual(3.0f, CommandLineUtility.GetCommandLineValue <float>(dictionary, "float-value", 0f));
            Assert.AreEqual(15.0f, CommandLineUtility.GetCommandLineValue <double>(dictionary, "double-value", 0.0));
        }
Example #10
0
        public void Awake()
        {
            InitializeWorkerTypes();
            // Taken from DefaultWorldInitalization.cs
            SetupInjectionHooks();                                               // Register hybrid injection hooks
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); // Clean up worlds and player loop

            Application.targetFrameRate = TargetFrameRate;
            if (Application.isEditor)
            {
#if UNITY_EDITOR
                var workerConfigurations =
                    AssetDatabase.LoadAssetAtPath <ScriptableWorkerConfiguration>(ScriptableWorkerConfiguration
                                                                                  .AssetPath);
                foreach (var workerConfig in workerConfigurations.WorkerConfigurations)
                {
                    if (!workerConfig.IsEnabled)
                    {
                        continue;
                    }

                    var worker = WorkerRegistry.CreateWorker(workerConfig.Type, $"{workerConfig.Type}-{Guid.NewGuid()}",
                                                             workerConfig.Origin);
                    Workers.Add(worker);
                }

                connectionConfig = new ReceptionistConfig();
                connectionConfig.UseExternalIp = workerConfigurations.UseExternalIp;
#endif
            }
            else
            {
                var commandLineArguments = System.Environment.GetCommandLineArgs();
                Debug.LogFormat("Command line {0}", string.Join(" ", commandLineArguments.ToArray()));
                var commandLineArgs = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                var workerType      =
                    CommandLineUtility.GetCommandLineValue(commandLineArgs, RuntimeConfigNames.WorkerType,
                                                           string.Empty);
                var workerId =
                    CommandLineUtility.GetCommandLineValue(commandLineArgs, RuntimeConfigNames.WorkerId,
                                                           string.Empty);

                // because the launcher does not pass in the worker type as an argument
                var worker = workerType.Equals(string.Empty)
                    ? WorkerRegistry.CreateWorker <UnityClient>(
                    workerId: null,     // The worker id for the UnityClient will be auto-generated.
                    origin: new Vector3(0, 0, 0))
                    : WorkerRegistry.CreateWorker(workerType, workerId, new Vector3(0, 0, 0));

                Workers.Add(worker);

                connectionConfig = ConnectionUtility.CreateConnectionConfigFromCommandLine(commandLineArgs);
            }

            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];
        }
Example #11
0
        /// <summary>
        ///     Build method that is invoked by commandline
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        public static void Build()
        {
            try
            {
                var commandLine    = Environment.GetCommandLineArgs();
                var buildTargetArg = CommandLineUtility.GetCommandLineValue(commandLine, "buildTarget", "local");

                BuildEnvironment buildEnvironment;
                switch (buildTargetArg.ToLower())
                {
                case "cloud":
                    buildEnvironment = BuildEnvironment.Cloud;
                    break;

                case "local":
                    buildEnvironment = BuildEnvironment.Local;
                    break;

                default:
                    throw new BuildFailedException("Unknown build target value: " + buildTargetArg);
                }

                var workerTypesArg =
                    CommandLineUtility.GetCommandLineValue(commandLine, BuildWorkerTypes,
                                                           "UnityClient,UnityGameLogic");

                var desiredWorkerTypes  = workerTypesArg.Split(',');
                var filteredWorkerTypes = BuildSupportChecker.FilterWorkerTypes(buildEnvironment, desiredWorkerTypes);

                if (desiredWorkerTypes.Length != filteredWorkerTypes.Length)
                {
                    throw new BuildFailedException(
                              "Unable to complete build. Missing build support. Check logs for specific errors.");
                }

                ScriptingImplementation scriptingBackend;
                var wantedScriptingBackend =
                    CommandLineUtility.GetCommandLineValue(commandLine, "scriptingBackend", "mono");
                switch (wantedScriptingBackend)
                {
                case "mono":
                    scriptingBackend = ScriptingImplementation.Mono2x;
                    break;

                case "il2cpp":
                    scriptingBackend = ScriptingImplementation.IL2CPP;
                    break;

                default:
                    throw new BuildFailedException("Unknown scripting backend value: " + wantedScriptingBackend);
                }

                LocalLaunch.BuildConfig();

                foreach (var wantedWorkerType in filteredWorkerTypes)
                {
                    BuildWorkerForEnvironment(wantedWorkerType, buildEnvironment, scriptingBackend);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                if (e is BuildFailedException)
                {
                    throw;
                }

                throw new BuildFailedException(e);
            }
        }
Example #12
0
        /// <summary>
        ///     Build method that is invoked by commandline
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        public static void Build()
        {
            try
            {
                var commandLine    = Environment.GetCommandLineArgs();
                var buildTargetArg = CommandLineUtility.GetCommandLineValue(commandLine, "buildTarget", "local");

                BuildEnvironment buildEnvironment;
                switch (buildTargetArg.ToLower())
                {
                case "cloud":
                    buildEnvironment = BuildEnvironment.Cloud;
                    break;

                case "local":
                    buildEnvironment = BuildEnvironment.Local;
                    break;

                default:
                    throw new BuildFailedException("Unknown build target value: " + buildTargetArg);
                }

                var workerTypesArg =
                    CommandLineUtility.GetCommandLineValue(commandLine, BuildWorkerTypes,
                                                           "UnityClient,UnityGameLogic");
                var wantedWorkerTypes = workerTypesArg.Split(',');

                ScriptingImplementation scriptingBackend;
                var wantedScriptingBackend =
                    CommandLineUtility.GetCommandLineValue(commandLine, "scriptingBackend", "mono");
                switch (wantedScriptingBackend)
                {
                case "mono":
                    scriptingBackend = ScriptingImplementation.Mono2x;
                    break;

                case "il2cpp":
                    scriptingBackend = ScriptingImplementation.IL2CPP;
                    break;

                default:
                    throw new BuildFailedException("Unknown scripting backend value: " + wantedScriptingBackend);
                }

                var buildsSucceeded = BuildWorkers(wantedWorkerTypes, buildEnvironment, scriptingBackend);

                if (!buildsSucceeded)
                {
                    throw new BuildFailedException("Not all builds were completed successfully. See the log for more information.");
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                if (e is BuildFailedException)
                {
                    throw;
                }

                throw new BuildFailedException(e);
            }
        }