Exemplo n.º 1
0
    //编译更新资源,走自动更新
    //[MenuItem("Tools/AutoBuild", false, 0)]
    public static void AutoBuildResUpdate()
    {
        bool   isBuildRes = false;
        string temp       = GetJenkinsParameter("isBuildRes");

        if (!string.IsNullOrEmpty(temp))
        {
            isBuildRes = bool.Parse(temp);
        }
        temp = GetJenkinsParameter("channel");
        if (!string.IsNullOrEmpty(temp))
        {
            channelType = (GameChannel.ChannelType)Enum.Parse(typeof(GameChannel.ChannelType), temp);
        }
        if (isBuildRes)
        {
            buildTarget = EditorUserBuildSettings.activeBuildTarget;

            PackageTool.AutoBuildPack(buildTarget, channelType);
            PackageTool.BuildAssetBundlesForCurrentChannel();
            Debug.Log("BuildRes done ");
        }
    }
Exemplo n.º 2
0
    public static void AutoBuildApk()
    {
        buildTarget = EditorUserBuildSettings.activeBuildTarget;
        bool   isDelAllRes = false;
        string temp        = GetJenkinsParameter("isDelAllRes");

        if (!string.IsNullOrEmpty(temp))
        {
            isDelAllRes = bool.Parse(temp);
        }
        bool isBuildRes = false;

        temp = GetJenkinsParameter("isBuildRes");
        if (!string.IsNullOrEmpty(temp))
        {
            isBuildRes = bool.Parse(temp);
        }
        bool genXluaCode = false;

        temp = GetJenkinsParameter("genXluaCode");
        if (!string.IsNullOrEmpty(temp))
        {
            genXluaCode = bool.Parse(temp);
        }
        bool isCpp = false;

        temp = GetJenkinsParameter("isCpp");
        if (!string.IsNullOrEmpty(temp))
        {
            isCpp = bool.Parse(temp);
        }
        if (isDelAllRes)
        {
            string outputPath2 = PackageUtils.GetCurBuildSettingAssetBundleOutputPath();
            GameUtility.SafeDeleteDir(outputPath2);
            Debug.Log(string.Format("Clear done : {0}", outputPath2));
        }
        temp = GetJenkinsParameter("channel");
        if (!string.IsNullOrEmpty(temp))
        {
            channelType = (GameChannel.ChannelType)Enum.Parse(typeof(GameChannel.ChannelType), temp);
        }
        if (isBuildRes)
        {
            PackageTool.AutoBuildPack(buildTarget, channelType);
            PackageTool.BuildAssetBundlesForCurrentChannel();
            Debug.Log("BuildRes done ");
            PackageUtils.CopyCurSettingAssetBundlesToStreamingAssets(buildTarget);
        }
        if (genXluaCode)
        {
            PackageTool.GenXLuaCode(buildTarget);
        }
        Debug.Log("开始构建安装包参数");
        string res_url = GetJenkinsParameter("res_url");

        if (!string.IsNullOrEmpty(res_url))
        {
            var path = AssetBundles.LaunchAssetBundleServer.GetStreamingAssetBundleServerUrl();
            GameUtility.SafeWriteAllText(path, res_url);
            Debug.Log(res_url);
        }

        GameChannel.BaseChannel channel = GameChannel.ChannelManager.instance.CreateChannel(channelType.ToString());
        if (isCpp)
        {
            PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
        }
        else
        {
            PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);
        }
        PlayerSettings.stripEngineCode            = false;
        PlayerSettings.SplashScreen.showUnityLogo = false;
        if (channel != null)
        {
#if UNITY_5_6_OR_NEWER
            PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, channel.GetBundleID());
#else
            PlayerSettings.bundleIdentifier = channel.GetBundleID();
#endif
            PlayerSettings.productName = channel.GetProductName();
            PlayerSettings.companyName = channel.GetCompanyName();
        }

        string savePath = "E:\\APK";
        string appName  = GetJenkinsParameter("apkName") + ".apk";
        if (string.IsNullOrEmpty(appName))
        {
            appName = "zhj";
        }
        if (channel.IsGooglePlay())
        {
            savePath = Path.Combine(savePath, "GooglePlay");
            GameUtility.SafeDeleteDir(savePath);
            BuildPipeline.BuildPlayer(BuildPlayer.GetBuildScenes(), savePath, buildTarget, BuildOptions.AcceptExternalModificationsToPlayer);
        }
        else
        {
            Debug.Log("开始打包");
            savePath = Path.Combine(savePath, appName);
            BuildPipeline.BuildPlayer(BuildPlayer.GetBuildScenes(), savePath, buildTarget, BuildOptions.None);
        }

        Debug.Log(string.Format("Build android player for : {0} done! output :{1}", channelType.ToString(), savePath));
        //bool.Parse(GetJenkinsParameter("GetJenkinsParameter"));
    }