/// <summary> /// /// </summary> /// <param name="parameters"></param> public static void Build(AutomationParameters parameters) { var buildTarget = (BuildTarget)System.Enum.Parse(typeof(BuildTarget), parameters.Get("targetPlatform")); var scenesToBuild = new HashSet <string>(EditorBuildSettings.scenes.Select(x => x.path)); var additionalScenes = parameters.Get("scenesToBuild").Split(';'); foreach (var scene in additionalScenes) { scenesToBuild.Add(scene); } var buildOptions = BuildOptions.None; if (parameters.Has("showBuiltPlayer")) { buildOptions |= BuildOptions.ShowBuiltPlayer; } var options = new BuildPlayerOptions { scenes = scenesToBuild.ToArray(), target = buildTarget, targetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget), locationPathName = parameters.Get("outputPath"), options = buildOptions, }; BuildPipeline.BuildPlayer(options); }
/// <summary> /// /// </summary> private static void RunAutomation() { var commandLineArgs = System.Environment.GetCommandLineArgs(); var properties = new Dictionary <string, string>(); for (var i = 0; i < commandLineArgs.Length; ++i) { if (commandLineArgs[i].StartsWith("-")) { if (i < commandLineArgs.Length - 1) { if (commandLineArgs[i + 1].StartsWith("-")) { properties[commandLineArgs[i].TrimStart('-')] = string.Empty; } else { properties[commandLineArgs[i].TrimStart('-')] = commandLineArgs[i + 1]; ++i; } } properties[commandLineArgs[i].TrimStart('-')] = string.Empty; } } parameters = new AutomationParameters(properties); string automationMethod; if (parameters.TryGet(nameof(automationMethod), out automationMethod)) { var split = automationMethod.Split('.'); var typeName = string.Join(".", split.Take(split.Length - 1).ToArray()); var methodName = split[split.Length - 1]; Debug.Log($"Trying to find method '{methodName}' in type '{typeName}'."); var type = System.Type.GetType(typeName); var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); var methodParameters = method.GetParameters(); if (methodParameters.Length == 0) { method.Invoke(null, null); } else if (methodParameters.Length == 1 && methodParameters[0].ParameterType == typeof(AutomationParameters)) { method.Invoke(null, new object[] { parameters }); } else { Debug.LogError($"Could not invoke '{automationMethod}' due to unrecognized signature."); } } else { Debug.LogWarning("No Automation Method to execute..."); } }
/// <summary> /// /// </summary> /// <param name="parameters"></param> private static void CreateBuildInfo(AutomationParameters parameters) { var version = parameters.Get("buildVersion"); var commit = parameters.Get("buildCommit"); var buildInfo = ScriptableObject.CreateInstance <BuildInfo>(); buildInfo.version = version; buildInfo.commit = commit; DeleteBuildInfo(); UnityEditor.AssetDatabase.CreateAsset(buildInfo, BuildInfoAssetPath); UnityEditor.AssetDatabase.SaveAssets(); Debug.Log($"Created BuildInfo file for version '{version}'."); }