public void SaveFiles(VersionUpdateInfo versionUpdateInfo)
    {
        GameBuilder.DoSaveVersionFile(_appVersion,
                                      PlatformEditorUtils.GetBuildToolVersionDir(_buildTarget) + "/" + VersionConst.VersionFileName);

        SaveUpdateInfo(versionUpdateInfo);

        CopyToDiffPath();
    }
Esempio n. 2
0
    /// <summary>
    /// 构建设置
    /// </summary>
    /// <param name="para"></param>
    private static void SetupSetting(GameBuilderParameter para)
    {
        Debug.Log("SetupSetting");
        BuildTarget      buildTarget      = para.BuildTarget;
        BuildTargetGroup buildTargetGroup = PlatformEditorUtils.GetSelectedBuildTargetGroup(buildTarget);

        //EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, buildTarget);
        EditorUserBuildSettings.SwitchActiveBuildTarget(buildTarget);

        // 仅当有出包时才处理
        if (para.BuildMode != BuildMode.Patch)
        {
            // 版本号
            PlayerSettings.bundleVersion = para.BuildVersion.GetVersionString();
            //PlayerSettings.applicationIdentifier = para.BundleIdentifier;

            if (buildTarget == BuildTarget.Android)
            {
                PlayerSettings.Android.bundleVersionCode = para.BuildVersion.GetVersionCode();

                if (para.ExportProject)
                {
                    EditorUserBuildSettings.androidBuildSystem =
                        para.UseGradle ? AndroidBuildSystem.Gradle : AndroidBuildSystem.ADT;
                }
                else
                {
                    EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Internal;
                }
            }
            else if (buildTarget == BuildTarget.iOS)
            {
                PlayerSettings.iOS.buildNumber = para.BuildVersion.GetVersionCode().ToString();
            }

            //-如果是多线程渲染版本开启多线程渲染-//
            //PlayerSettings.SetMobileMTRendering(buildTargetGroup, para.Multithreaded);
            PlayerSettings.MTRendering = para.Multithreaded;

            //-打包之前先设置一下 预定义标签, 这时设置的宏,后面的代码不能马上生效,但BuildPlayer可以生效
            string macroDefines = para.MacroDefines;
            if (!String.IsNullOrEmpty(macroDefines))
            {
                macroDefines = para.UseMono2X ?
                               BuilderEditorUtils.AddMacro(macroDefines, "USE_MONO") :
                               BuilderEditorUtils.RemoveMacro(macroDefines, "USE_MONO");

                PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, macroDefines);
            }

            DoMonoSetting(para.UseMono2X, buildTargetGroup);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 获得构建版本
    /// </summary>
    /// <param name="versionOption"></param>
    /// <param name="customizeVersion"></param>
    /// <param name="buildTarget"></param>
    /// <returns></returns>
    public static AppVersion GetBuildVersion(VersionOption versionOption, AppVersion customizeVersion, BuildTarget buildTarget)
    {
        AppVersion lastBuildVersion = GetLastBuildVersion(buildTarget);
        AppVersion newVersion       = lastBuildVersion;

        switch (versionOption)
        {
        case VersionOption.PromotePatch:
        {
            if (lastBuildVersion == AppVersion.InitVersion)
            {
                Debug.Log("try check is first version build");
                // 是否是第一个版本,如果是就不增加补丁位。为了处理第一次打包
                string dir = PlatformEditorUtils.GetBuildToolVersionPatchDir(buildTarget, AppVersion.InitVersion);
                if (!Directory.Exists(dir) || Directory.GetDirectories(dir).Length == 0)
                {
                    Debug.Log("it's first version build");
                    break;
                }
            }
            newVersion.Revision += 1;
        }
        break;

        case VersionOption.PromoteMinorVersion:
        {
            newVersion.MinorVersion += 1;
            newVersion.Revision      = 0;
        }
        break;

        case VersionOption.PromoteLargeVersion:
        {
            newVersion.MajorVersion += 1;
            newVersion.MinorVersion  = 0;
            newVersion.Revision      = 0;
        }
        break;

        case VersionOption.CustomizeVersion:
        {
            newVersion = customizeVersion;
        }
        break;

        default:
            throw new ArgumentOutOfRangeException("versionOption", versionOption, null);
        }

        Debug.LogFormat("GetBuildVersion lastBuildVersion:{0}  newVersion:{1}", lastBuildVersion, newVersion);
        return(newVersion);
    }
Esempio n. 4
0
    /// <summary>
    /// 获得补丁版本
    /// </summary>
    public static AppVersion GetLastBuildVersion(BuildTarget buildTarget)
    {
        string path = PlatformEditorUtils.GetBuildToolVersionDir(buildTarget) + "/" + VersionConst.VersionFileName;

        if (!File.Exists(path))
        {
            return(new AppVersion());
        }

        string versionStr = File.ReadAllText(path);

        return(new AppVersion(versionStr));
    }
    /// <summary>
    /// 获得先前的版本时间戳目录
    /// </summary>
    /// <returns></returns>
    private string GetPreviousLastestVersionPath(AppVersion previousVersion)
    {
        string previousVersionOutputRoot = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, previousVersion);

        var previousPaths = Directory.GetDirectories(previousVersionOutputRoot);

        if (previousPaths.Length == 0)
        {
            Debug.LogError("could not found previous version info:" + previousVersionOutputRoot);
            return(string.Empty);
        }

        // 根据时间戳升序,跟字符串序是一样
        Array.Sort(previousPaths);

        return(previousPaths[previousPaths.Length - 1]);
    }
    void OnError()
    {
        Debug.Log("补丁构建失败:" + _appVersion);
        FileUtils.DelDir(_currentBuildVersionRootPath);


        string path = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, _appVersion);

        if (Directory.Exists(path) && Directory.GetDirectories(path).Length == 0)
        {
            FileUtils.DelDir(path);
        }

        path = PlatformEditorUtils.GetBuildToolVersionMajorMinorDir(_buildTarget, _appVersion);
        if (Directory.Exists(path) && Directory.GetDirectories(path).Length == 0)
        {
            FileUtils.DelDir(path);
        }
    }
    public VersionPatchBuilder(BuildTarget buildTarget, AppVersion appVersion, long buildNum)
    {
        _appVersion      = appVersion;
        _buildNum        = buildNum;
        _buildTarget     = buildTarget;
        VersionOutputDir = PlatformEditorUtils.GetBuildToolVersionDir(buildTarget);
        FileUtils.CreateDirectory(VersionOutputDir);

        string versionOutputRoot = PlatformEditorUtils.GetBuildToolVersionPatchDir(_buildTarget, _appVersion);

        FileUtils.CreateDirectory(versionOutputRoot);

        _timeVersionDirName = string.Format("{0:yyyy-MM-dd hh_mm_ss}({1})", DateTime.Now, buildNum);

        // 以当前的时间戳来命名文件夹
        _currentBuildVersionRootPath = versionOutputRoot + "/" + _timeVersionDirName;

        FileUtils.CreateDirectory(_currentBuildVersionRootPath);
        FileUtils.CreateDirectory(PatchDir);
        FileUtils.CreateDirectory(SnapshotDir);
    }
    /// <summary>
    /// 记录assetbundle的信息
    /// 为了加速,所以直接用assetbundle的hash. 只要meta文件不变,生成的assetbundle不会变
    /// 这里还要注意,lua是拷贝到temp目录,所以temp目录也不能删除。不然lua的assetbundle都会不一样
    /// </summary>
    /// <param name="fileList"></param>
    private void RecordAssetbundleInfos(List <string> fileList)
    {
        var assetbundle = AssetBundle.LoadFromFile(VersionConst.StreamingVersionPath + "/" + PlatformEditorUtils.GetPlatformDesc(_buildTarget));

        if (assetbundle != null)
        {
            var assetBundleManifest = assetbundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;
            if (assetBundleManifest != null)
            {
                var allAssetBundles = assetBundleManifest.GetAllAssetBundles();
                Debug.Log("allAssetBundles:" + allAssetBundles.Length);
                foreach (var oneAssetBundle in allAssetBundles)
                {
                    var hash = assetBundleManifest.GetAssetBundleHash(oneAssetBundle);
                    fileList.Add(string.Format("{0}|{1}", oneAssetBundle, hash.ToString()));
                }

                assetbundle.Unload(true);
            }
            else
            {
                Debug.LogError("LoadAsset AssetBundleManifest error:");
            }
        }
        else
        {
            Debug.LogError("cannt AssetBundle.LoadFromFile from :");
        }
    }
    private void BuildGame()
    {
        if (_hotFixOption == HotFixOption.Customize && string.IsNullOrEmpty(_hotFixUrl))
        {
            Debug.LogError("hotFixUrl is empty");
            return;
        }

        var buildPath = string.Empty;

        if (_buildMode != BuildMode.Patch)
        {
            buildPath = EditorUtility.SaveFilePanel(
                "SaveFile",
                PlayerPrefs.GetString("build_play_save_path"),
                _appName,
                _exportProject ? string.Empty : PlatformEditorUtils.GetAppExt(_buildTarget).Substring(1));

            if (string.IsNullOrEmpty(buildPath))
            {
                Debug.LogError("buildPath is empty");
                return;
            }

            PlayerPrefs.SetString("build_play_save_path", buildPath.Replace(_appName, string.Empty));
        }

        var buildOptions = BuildOptions.None;

        if (_development)
        {
            buildOptions |= BuildOptions.Development;
        }

        if (_exportProject)
        {
            buildOptions |= BuildOptions.AcceptExternalModificationsToPlayer;
        }

        GameBuilder.GameBuilderParameter para =
            new GameBuilder.GameBuilderParameter
        {
            BuildMode   = _buildMode,
            BuildTarget = _buildTarget,
            CopyFmod    = true,
            IncreativeBuildAssetBundles = _increativeBuildAssetBundles,
            BundleCompress   = _bundleCompress,
            ApplyAllRule     = _applyAllRule,
            BuildVersion     = GameBuilder.GetBuildVersion(_versionOption, _customizeVersion, _buildTarget),
            BuildOptions     = buildOptions,
            OutputPath       = buildPath,
            UseMono2X        = _useMono2X,
            ExportProject    = _exportProject,
            UseGradle        = _useGradle,
            BundleIdentifier = _bundleIdentifier,
            Multithreaded    = true,
            EnableHotFix     = _hotFixOption != HotFixOption.None,
            HotFixUrl        = GameBuilder.GetHotFixUrl(_hotFixOption, _hotFixUrl),
            BuildNumber      = DateTimeToUnixTimestamp(DateTime.Now),
        };

        GameBuilder.BuildGame(para);
    }