public static void Build()
    {
        //var args = new string[]{"-buildtarget","IOS","-buildpath","Builds/ios"};
        var args = Environment.GetCommandLineArgs();

        var cancel = false;

        var buildTarget = CommandlineParseUtils.GetArgumentData(args, "-buildtarget");

        if (string.IsNullOrEmpty(buildTarget))
        {
            Debug.LogWarning("no build platform set (use \"-buildtarget <buildtarget>\")");
            cancel = true;
        }

        var buildPath = CommandlineParseUtils.GetArgumentData(args, "-buildpath");

        if (string.IsNullOrEmpty(buildPath))
        {
            Debug.LogWarning("no build path set (use \"-buildpath <platform>\")");
            cancel = true;
        }

        if (cancel)
        {
            Debug.LogWarning("Build canceled (not enough information)");
            return;
        }

        var buildTargetParsed = (BuildTarget)Enum.Parse(typeof(BuildTarget), buildTarget, true);

        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();

        buildPlayerOptions.locationPathName = buildPath;
        buildPlayerOptions.target           = buildTargetParsed;
        buildPlayerOptions.scenes           = EditorBuildSettingsScene.GetActiveSceneList(EditorBuildSettings.scenes);
        buildPlayerOptions.options          = BuildOptions.None;

        Debug.Log($"Starting build: buildTarget='{buildTargetParsed}' buildPath='{buildPath}'");

        BuildReport  report  = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = report.summary;


        if (summary.result == BuildResult.Succeeded)
        {
            Debug.Log($"Build succeeded: {(summary.totalSize * 1e-6)} MB {summary.totalTime:hh\\:mm\\:ss}");
        }

        if (summary.result == BuildResult.Failed)
        {
            throw new UnityException("Build failed");             //throw exception to make sure exit code is not 0
        }
    }
    public void OnPreprocessBuild(BuildReport report)
    {
        //var args = new string[]{"-android_app_bundle","1"};
        var args = System.Environment.GetCommandLineArgs();

        if (!CommandlineParseUtils.HasArgument(args, "-android_app_bundle"))
        {
            return;
        }

        var useBundleStr = CommandlineParseUtils.GetArgumentData(args, "-android_app_bundle");
        var useBundle    = int.Parse(useBundleStr) == 1;

        switch (report.summary.platform)
        {
        case BuildTarget.Android:
            oldUseBundle = EditorUserBuildSettings.buildAppBundle;
            EditorUserBuildSettings.buildAppBundle = useBundle;
            Debug.Log($"Temporarily set buildAppBundle to {useBundle}");
            break;
        }
    }
    public void OnPreprocessBuild(BuildReport report)
    {
        //var args = new string[]{"-obb","0"};
        var args = System.Environment.GetCommandLineArgs();

        if (!CommandlineParseUtils.HasArgument(args, "-obb"))
        {
            return;
        }

        var useObbStr = CommandlineParseUtils.GetArgumentData(args, "-obb");
        var useObb    = int.Parse(useObbStr) == 1;

        switch (report.summary.platform)
        {
        case BuildTarget.Android:
            oldUseObb = PlayerSettings.Android.useAPKExpansionFiles;
            PlayerSettings.Android.useAPKExpansionFiles = useObb;
            Debug.Log($"Temporarily set useAPKExpansionFiles to {useObb}");
            break;
        }
    }
示例#4
0
    public void OnPreprocessBuild(BuildReport report)
    {
        //var args = new string[]{"-buildversion","15"};
        var args = System.Environment.GetCommandLineArgs();

        if (!CommandlineParseUtils.HasArgument(args, "-buildversion"))
        {
            return;
        }

        var buildVersionStr = CommandlineParseUtils.GetArgumentData(args, "-buildversion");
        var buildVersion    = int.Parse(buildVersionStr);

        switch (report.summary.platform)
        {
        case BuildTarget.Android:
            oldBuildVersion = PlayerSettings.Android.bundleVersionCode;
            PlayerSettings.Android.bundleVersionCode = buildVersion;
            Debug.Log($"Temporarily set build version to {buildVersion}");
            break;
        }
    }