Example #1
0
        /// <summary>
        /// 输出打包信息(导出的XCode工程 打包ipa文件时使用).
        /// </summary>
        /// <param name="iProjectName">工程名.</param>
        /// <param name="iProjectVersion">工程版本.</param>
        private static void OutputBuildInfo(
            string iProjectName, string iProjectVersion)
        {
            const string funcBlock = "ProjectBuild.OutputBuildInfo()";

            BuildLogger.OpenBlock(funcBlock);

            string filePath = string.Format("{0}/../Shell/BuildInfo", Application.dataPath);

            if (File.Exists(filePath) == true)
            {
                File.Delete(filePath);
            }
            FileStream fStrm = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);


            string buildInfo = string.Format("{0}:{1}:{2}",
                                             BuildParameters.BuildTime, iProjectName, iProjectVersion);

            BuildLogger.LogMessage("BuildInfo:{0}", buildInfo);

            // 获得字节数组
            byte[] data = System.Text.Encoding.Default.GetBytes(buildInfo);
            // 写入
            fStrm.Write(data, 0, data.Length);
            // 清空缓冲区、关闭流
            if (null != fStrm)
            {
                fStrm.Flush();
                fStrm.Close();
                fStrm.Dispose();
            }

            BuildLogger.CloseBlock();
        }
        /// <summary>
        /// 追加宏(iOS).
        /// </summary>
        static void AddAndroidDefines()
        {
            const string funcBlock = "DefinesSetting.AddAndroidDefines()";

            BuildLogger.OpenBlock(funcBlock);

            string[] _defines = BuildParameters.Defines;
            SetDefines(_defines, BuildTargetGroup.Android);

            BuildLogger.CloseBlock();
        }
        static void Import()
        {
            const string funcBlock = "HuaweiSDKEditor.Import()";

            BuildLogger.OpenBlock(funcBlock);

            HuaweiSDKSettings settings = HuaweiSDKSettings.GetInstance();

            if (settings != null)
            {
                settings.ImportFromJsonFile();
            }

            BuildLogger.CloseBlock();
        }
        static void Clear()
        {
            const string funcBlock = "HuaweiSDKEditor.Clear()";

            BuildLogger.OpenBlock(funcBlock);

            HuaweiSDKSettings settings = HuaweiSDKSettings.GetInstance();

            if (settings != null)
            {
                settings.Clear();
            }

            BuildLogger.CloseBlock();
        }
Example #5
0
        static void Export()
        {
            const string funcBlock = "TiangeSDKSettingsEditor.Export()";

            BuildLogger.OpenBlock(funcBlock);

            TiangeSDKSettings settings = TiangeSDKSettings.GetInstance();

            if (settings != null)
            {
                settings.ExportToJsonFile();
            }

            BuildLogger.CloseBlock();
        }
Example #6
0
        /// <summary>
        /// 清空目录(Application.streamingAssetsPath)
        /// </summary>
        public static bool ClearStreamingAssets()
        {
            const string funcBlock = "AssetBundle.ClearStreamingAssets()";

            BuildLogger.OpenBlock(funcBlock);

            if (Directory.Exists(Application.streamingAssetsPath) == true)
            {
                string[] files = Directory.GetFiles(Application.streamingAssetsPath);
                foreach (string loop in files)
                {
                    File.Delete(loop);
                    BuildLogger.LogMessage("[Delete File] -> {0}", loop);
                    if (File.Exists(loop) == true)
                    {
                        BuildLogger.LogMessage("[Delete File Failed] -> {0}", loop);
                    }
                }

                string[] subDirs = Directory.GetDirectories(Application.streamingAssetsPath);
                foreach (string subDir in subDirs)
                {
                    files = Directory.GetFiles(subDir);
                    foreach (string loop in files)
                    {
                        BuildLogger.LogMessage("[Delete File] -> {0}", loop);
                        File.Delete(loop);
                        if (File.Exists(loop) == true)
                        {
                            BuildLogger.LogMessage("[Delete File Failed] -> {0}", loop);
                        }
                    }
                    files = Directory.GetFiles(subDir);
                    if ((files != null) && (files.Length <= 0))
                    {
                        BuildLogger.LogMessage("[Delete Directory] -> {0}", subDir);
                        Directory.Delete(subDir);
                        if (Directory.Exists(subDir) == true)
                        {
                            BuildLogger.LogMessage("[Delete Directory Failed] -> {0}", subDir);
                        }
                    }
                }
            }

            BuildLogger.CloseBlock();
            return(true);
        }
Example #7
0
        static void BuildForAndroid()
        {
            const string funcBlock = "AssetBundlesBuild.BuildForAndroid()";

            BuildLogger.OpenBlock(funcBlock);

            // 开始打包Bundles
            UtilsAsset.StartBuildBundles();

            BuildAssetBundle(BuildTarget.Android, true);

            // 生成上传用的Shell
            CreateUploadShell();

            // 开始打包Bundles
            UtilsAsset.EndBuildBundles();

            BuildLogger.CloseBlock();
        }
Example #8
0
        /// <summary>
        /// 打包前将非资源对象,移动到临时文件夹.
        /// </summary>
        public static void MoveUnResources()
        {
            const string funcBlock = "AssetBundle.MoveUnResources()";

            BuildLogger.OpenBlock(funcBlock);

//			AssetBundlesConfig bcConfig = AssetBundlesConfig.ReadConfig();
//
//			foreach(BundleUnResource urpi in bcConfig.UnResources)
//			{
//				bool isDir = false;
//				string dirName = "";
//				string allDirName = "";
//				if(urpi.Path.Contains(".") == false)
//				{
//					isDir = true;
//					int index = urpi.Path.LastIndexOf("/");
//					allDirName = urpi.Path.Substring(0, index);
//					index = allDirName.LastIndexOf("/");
//					dirName = allDirName.Substring(index + 1, allDirName.Length - index - 1);
//
//					string pathTempDir = Application.dataPath + unResourcesPathTempDir + dirName;
//					allDirName = allDirName.Replace("Assets/", "/");
//					allDirName = Application.dataPath + allDirName;
//
//					FileUtil.DeleteFileOrDirectory(allDirName);
//					FileUtil.DeleteFileOrDirectory(allDirName + ".meta");
//
//					//FileUtil.MoveFileOrDirectory(allDirName, pathTempDir);
//					//FileUtil.MoveFileOrDirectory(allDirName + ".meta", pathTempDir + ".meta");
//				}
//				else
//				{
//					UtilsLog.Error ("MoveUnResources", "just dir" + urpi.Path);
//				}
//
//			}
//
//			AssetDatabase.Refresh();

            BuildLogger.CloseBlock();
        }
        static HuaweiSDKSettings CreateSettings()
        {
            const string funcBlock = "HuaweiSDKEditor.CreateSettings()";

            BuildLogger.OpenBlock(funcBlock);

            string curDir = GetCurDir();

            if (Directory.Exists(curDir) == false)
            {
                return(null);
            }
            HuaweiSDKSettings settings = UtilsAsset.CreateAsset <HuaweiSDKSettings> (curDir);

            if (settings != null)
            {
                // 初始化
                settings.Init();
            }
            BuildLogger.CloseBlock();
            return(settings);
        }
Example #10
0
        /// <summary>
        /// 打包资源文件
        /// </summary>
        /// <param name="buildTarget">Build target.</param>
        /// <param name="needCompress">If set to <c>true</c> need compress.</param>
        private static void BuildAssetBundle(BuildTarget buildTarget, bool needCompress = false)
        {
            const string funcBlock = "AssetBundlesBuild.BuildAssetBundle()";

            BuildLogger.OpenBlock(funcBlock);

            // 设置上传的打包类型
            UploadList.GetInstance().BuildTarget = buildTarget.ToString();

            BundlesConfig bcConfig = BundlesConfig.GetInstance();

            if ((null == bcConfig) || (0 >= bcConfig.Resources.Count))
            {
                BuildLogger.LogError("BuildAssetBundle::BundlesConfig is invalid!!!");
                return;
            }

            // 清空依赖关系列表
            BundlesMap bundlesMap = BundlesMap.GetInstance();

            if (null == bundlesMap)
            {
                BuildLogger.LogError("BuildAssetBundle::bundlesMap is invalid!!!");
                return;
            }
            bundlesMap.Clear();

            List <BundleResource> allConfig = bcConfig.Resources;

            // make bundle config
            foreach (BundleResource bc in allConfig)
            {
                // filter file
                if (bc.Mode == BundleMode.OneDir)
                {
                    string    bundleId = BundlesMap.GetBundleID(bc.Path);
                    BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);

                    bm.ID   = bundleId;
                    bm.Path = bc.Path;

                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    // 遍历文件列表
                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }
                        bm.AddFile(file);
                    }

                    bundlesMap.Maps.Add(bm);
                }
                else if (bc.Mode == BundleMode.SceneOneToOne)
                {
                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }
                        // 若非场景文件,则跳过
                        if (file.EndsWith(".unity") == false)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        string    bundleId = BundlesMap.GetBundleID(file);
                        BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }

                        bm.ID   = bundleId;
                        bm.Path = bc.Path;
                        bm.Type = TBundleType.Scene;
                        bm.AddFile(file);

                        bundlesMap.Maps.Add(bm);
                    }
                }
                else if (bc.Mode == BundleMode.FileOneToOne)
                {
                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        string    bundleId = BundlesMap.GetBundleID(file);
                        BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }

                        bm.ID   = bundleId;
                        bm.Path = bc.Path;
                        bm.AddFile(file);

                        bundlesMap.Maps.Add(bm);
                    }
                }
                else if (bc.Mode == BundleMode.TopDirOneToOne)
                {
                    // 取得目录列表
                    string[] directories = Directory.GetDirectories(bc.Path);
                    if ((directories == null) || (directories.Length <= 0))
                    {
                        BuildLogger.LogWarning("The no subfolder in this path!!!(dir:{0})",
                                               bc.Path);
                        continue;
                    }

                    foreach (string dir in directories)
                    {
                        // 取得当前目录的文件列表
                        List <string> files = GetAllFiles(dir);

                        string bundleId = BundlesMap.GetBundleID(dir);
                        bundleId = BundlesMap.GetBundleID(dir);
                        if (string.IsNullOrEmpty(bundleId) == true)
                        {
                            continue;
                        }
                        BundleMap bm = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        bm.ID   = bundleId;
                        bm.Path = bc.Path;

                        foreach (string file in files)
                        {
                            // .DS_Store文件
                            if (file.EndsWith(".DS_Store") == true)
                            {
                                continue;
                            }
                            // *.meta文件
                            if (file.EndsWith(".meta") == true)
                            {
                                continue;
                            }

                            // 若为忽略文件,则跳过
                            if (bcConfig.isIgnoreFile(bc, file) == true)
                            {
                                bm.RemoveIgnorFile(file);
                                continue;
                            }

                            bm.AddFile(file);
                        }

                        bundlesMap.Maps.Add(bm);
                    }
                }
            }

            // 目录检测
            string checkDir = UploadList.GetInstance().BundlesOutputDir;

            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }
            checkDir = UploadList.GetInstance().BundlesOutputDirOfNormal;
            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }
            checkDir = UploadList.GetInstance().BundlesOutputDirOfScene;
            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }

            bool successed             = false;
            AssetBundleManifest result = null;

            string[]           allAssets = null;
            AssetBundleBuild[] targets   = null;

            // 一般Bundles
            try {
                targets = bundlesMap.GetAllNormalBundleTargets();
                BuildAssetBundleOptions options = BuildAssetBundleOptions.UncompressedAssetBundle;
                result = BuildPipeline.BuildAssetBundles(
                    UploadList.GetInstance().BundlesOutputDirOfNormal,
                    targets,
                    options,
                    buildTarget);
                BuildLogger.LogMessage(" -> BuildPipeline.BuildAssetBundles");
                if (result != null)
                {
                    allAssets = result.GetAllAssetBundles();
                    if ((allAssets != null) && (targets.Length == allAssets.Length))
                    {
                        successed = true;
                    }
                }
            } catch (Exception exp) {
                BuildLogger.LogException("BuildAssetBundles Detail : {0}", exp.Message);
                successed = false;
            }

            // 更新导出标志位
            if (successed == true)
            {
                BuildLogger.LogMessage(" -> BundlesConfig.UpdateBundleStateWhenCompleted");

                Dictionary <string, string> hashCodes = new Dictionary <string, string>();
                foreach (string asset in allAssets)
                {
                    Hash128 hashCode = result.GetAssetBundleHash(asset);
                    if (string.IsNullOrEmpty(hashCode.ToString()) == true)
                    {
                        continue;
                    }
                    string fileSuffix = UploadList.GetInstance().FileSuffix;
                    string key        = asset;
                    if (string.IsNullOrEmpty(fileSuffix) == false)
                    {
                        fileSuffix = fileSuffix.ToLower();
                        fileSuffix = string.Format(".{0}", fileSuffix);
                        key        = key.Replace(fileSuffix, "");
                    }
                    hashCodes[key] = hashCode.ToString();
                }
                // 初始化检测信息(Hash Code)
                bundlesMap.UpdateUploadList(TBundleType.Normal, hashCodes);
                BuildLogger.LogMessage(" -> BundlesMap.UpdateUploadList Normal");
            }

            // Scene Bundles
            List <SceneBundleInfo> targetScenes = bundlesMap.GetAllSceneBundleTargets();

            if ((targetScenes != null) && (targetScenes.Count > 0))
            {
                foreach (SceneBundleInfo scene in targetScenes)
                {
                    if ((scene == null) ||
                        (scene.GetAllTargets() == null) ||
                        (scene.GetAllTargets().Length <= 0))
                    {
                        continue;
                    }
                    try {
                        BuildOptions options = BuildOptions.BuildAdditionalStreamedScenes;
                        if (TBuildMode.Debug == BuildInfo.GetInstance().BuildMode)
                        {
                            options |= BuildOptions.Development;
                        }
                        string sceneState = BuildPipeline.BuildPlayer(
                            scene.GetAllTargets(),
                            UploadList.GetLocalSceneBundleFilePath(scene.BundleId),
                            buildTarget,
                            options);
                        BuildLogger.LogMessage(" -> BuildPipeline.BuildStreamedSceneAssetBundle(State:{0})", sceneState);
                    } catch (Exception exp) {
                        BuildLogger.LogException("BuildStreamedSceneAssetBundle Detail:{0}", exp.Message);
                        successed = false;
                    }
                }
            }

            // 更新导出标志位
            if (successed == true)
            {
                BuildLogger.LogMessage(" -> BundlesConfig.UpdateBundleStateWhenCompleted");

                // 初始化检测信息(Hash Code)
                bundlesMap.UpdateUploadList(TBundleType.Scene);
                BuildLogger.LogMessage(" -> BundlesMap.UpdateUploadList Scene");
            }

            BuildInfo.GetInstance().ExportToJsonFile();
            BuildLogger.LogMessage(" -> BuildInfo.ExportToJsonFile");

            BuildLogger.CloseBlock();
        }
Example #11
0
        static void CreateUploadShell()
        {
            const string funcBlock = "AssetBundlesBuild.CreateUploadShell()";

            BuildLogger.OpenBlock(funcBlock);

            string filePath = string.Format("{0}/../Shell/Upload.sh", Application.dataPath);

            if (File.Exists(filePath) == true)
            {
                File.Delete(filePath);
            }
            FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);

            if (null == fs)
            {
                return;
            }
            StreamWriter sw = new StreamWriter(fs);

            if (null == sw)
            {
                if (null != fs)
                {
                    fs.Flush();
                    fs.Close();
                    fs.Dispose();
                }
                return;
            }

            // 写入文件头
            sw.WriteLine("#!/bin/bash");
            sw.Flush();

            sw.WriteLine("");
            sw.Flush();

            // 设定变量
            sw.WriteLine("# 上传根目录");
            sw.WriteLine("ROOT_DIR=bundles");
            sw.Flush();
            sw.WriteLine("# 本地上传路径");
            sw.WriteLine(string.Format("UPLOAD_FROM_ROOT_DIR={0}/StreamingAssets", Application.dataPath));
            sw.WriteLine("");
            sw.Flush();
            sw.WriteLine("# 上传目标平台");
            sw.WriteLine(string.Format("BUILD_TARGET={0}", UploadList.GetInstance().BuildTarget));
            sw.Flush();
            sw.WriteLine("# App Version");
            sw.WriteLine(string.Format("APP_VERSION={0}", UploadList.GetInstance().AppVersion));
            sw.Flush();
            sw.WriteLine("# Center Version");
            sw.WriteLine(string.Format("CENTER_VERSION={0}", UploadList.GetInstance().CenterVersion));
            sw.WriteLine("");
            sw.Flush();

            UploadServerInfo uploadServer = ServersConf.GetInstance().UploadServer;

            sw.WriteLine("# 检测上传目录");
            sw.WriteLine("# $1 上传目录");
            sw.WriteLine("checkUploadDir()");
            sw.WriteLine("{");
            sw.WriteLine("ftp -n<<!");
            sw.WriteLine(string.Format("open {0} {1}", uploadServer.IpAddresss, uploadServer.PortNo));
            sw.WriteLine(string.Format("user {0} {1}", uploadServer.AccountId, uploadServer.Pwd));
            sw.WriteLine("binary");
            sw.WriteLine("pwd");
            sw.WriteLine("if [ ! -d \"$1\" ]; then");
            sw.WriteLine("  mkdir \"$1\"");
            sw.WriteLine("fi");
            sw.WriteLine("prompt");
//			sw.WriteLine("ls -l");
            sw.WriteLine("close");
            sw.WriteLine("bye");
            sw.WriteLine("!");
            sw.WriteLine("}");
            sw.WriteLine("");
            sw.Flush();

            sw.WriteLine("# 文件上传函数");
            sw.WriteLine("# $1 本地上传目录");
            sw.WriteLine("# $2 上传目标目录");
            sw.WriteLine("# $3 上传目标文件");
            sw.WriteLine("upload()");
            sw.WriteLine("{");
            sw.WriteLine("ftp -n<<!");
            sw.WriteLine(string.Format("open {0} {1}", uploadServer.IpAddresss, uploadServer.PortNo));
            sw.WriteLine(string.Format("user {0} {1}", uploadServer.AccountId, uploadServer.Pwd));
            sw.WriteLine("binary");
            sw.WriteLine("cd \"$2\"");
            sw.WriteLine("lcd \"$1\"");
            sw.WriteLine("pwd");
            sw.WriteLine("prompt");
            sw.WriteLine("put \"$3\"");
//			sw.WriteLine("ls -l");
            sw.WriteLine("close");
            sw.WriteLine("bye");
            sw.WriteLine("!");
            sw.WriteLine("}");
            sw.WriteLine("");
            sw.Flush();


            sw.WriteLine("# 检测目录");
            sw.WriteLine("checkUploadDir $ROOT_DIR");
            sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET");
            sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION");
            sw.WriteLine("");
            sw.Flush();

            sw.WriteLine("# 上传资源文件");
            List <UploadItem> Targets = UploadList.GetInstance().Targets;

            UploadItem[] _normals = Targets
                                    .Where(o => (TBundleType.Normal == o.BundleType))
                                    .OrderBy(o => o.No)
                                    .ToArray();
            if (0 < _normals.Length)
            {
                sw.WriteLine("# 检测一般文件目录");
                sw.WriteLine(string.Format("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", TBundleType.Normal.ToString()));

                sw.WriteLine("# 一般文件");
                foreach (UploadItem loop in _normals)
                {
                    string fileName = UploadList.GetLocalBundleFileName(loop.ID, loop.FileType);
                    sw.WriteLine(string.Format("upload $UPLOAD_FROM_ROOT_DIR/{0} $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0} {1}",
                                               TBundleType.Normal.ToString(), fileName));
                }
                sw.WriteLine("");
                sw.Flush();
            }

            UploadItem[] _scenes = Targets
                                   .Where(o => (TBundleType.Scene == o.BundleType))
                                   .OrderBy(o => o.No)
                                   .ToArray();
            if (0 < _scenes.Length)
            {
                sw.WriteLine("# 检测场景文件目录");
                sw.WriteLine(string.Format("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", TBundleType.Scene.ToString()));
                sw.WriteLine("# 场景文件");
                foreach (UploadItem loop in _scenes)
                {
                    string fileName = UploadList.GetLocalBundleFileName(loop.ID, loop.FileType);
                    sw.WriteLine(string.Format("upload $UPLOAD_FROM_ROOT_DIR/{0} $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0} {1}",
                                               TBundleType.Scene.ToString(), fileName));
                }
                sw.WriteLine("");
                sw.Flush();
            }

            // 导出依赖文件
            BundlesMap.GetInstance().ExportToJsonFile(string.Format("{0}/StreamingAssets", Application.dataPath));
            sw.WriteLine("# 上传依赖文件");
            sw.WriteLine("upload $UPLOAD_FROM_ROOT_DIR $ROOT_DIR/$BUILD_TARGET/$APP_VERSION BundlesMapData.json");

            // 导出上传列表文件
            UploadList.GetInstance().ExportToJsonFile(string.Format("{0}/StreamingAssets", Application.dataPath));
            sw.WriteLine("# 上传上传列表文件");
            sw.WriteLine("upload $UPLOAD_FROM_ROOT_DIR $ROOT_DIR/$BUILD_TARGET/$APP_VERSION UploadListData.json");

            if (0 < Targets.Count)
            {
                sw.WriteLine("# 清空上传文件");
                sw.WriteLine(string.Format("rm -rfv $UPLOAD_FROM_ROOT_DIR", TBundleType.Normal.ToString()));
                sw.WriteLine("");
                sw.Flush();
            }

            sw.WriteLine("");
            sw.Flush();

            if (null != fs)
            {
                fs.Flush();
                fs.Close();
                fs.Dispose();
            }

            if (null != sw)
            {
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }

            BuildLogger.CloseBlock();
        }
Example #12
0
        static void BuildForAndroid()
        {
            const string funcBlock = "ProjectBuild.BuildForAndroid()";

            BuildLogger.OpenBlock(funcBlock);

            // 设定打包信息
            SetBuildInfoFromParameters();

            TBuildMode buildMode = BuildInfo.GetInstance().BuildMode;

            BuildLogger.LogMessage("BuildMode:{0}", buildMode.ToString());

            // 输出格式({ProjectName}_v{ProjectVersion}_{buildNumber}_YYYYMMDDHHMMSS.apk)
            string buildTime = BuildParameters.BuildTime;

            // 输出路径
            // 游戏输出目录(Android):{OutputDir}/Android/{ProjectName}
            string outputDir = GetOutputDir(BuildTarget.Android, BuildParameters.OutputDir);

            if (outputDir == null)
            {
                BuildLogger.LogException("Create Dir Failed.!!(Dir:{0})",
                                         BuildParameters.OutputDir);
                throw new ApplicationException();
            }

            // 打包选项
            BuildOptions buildOptionTmp = BuildOptions.None;

            if (TBuildMode.Debug == buildMode)
            {
                buildOptionTmp |= BuildOptions.Development;
                buildOptionTmp |= BuildOptions.AllowDebugging;
                buildOptionTmp |= BuildOptions.ConnectWithProfiler;
            }
            else
            {
                bool isCheatMode = BuildParameters.IsCheatMode;
                if (true == isCheatMode)
                {
                    buildOptionTmp |= BuildOptions.Development;
                }
            }
            BuildLogger.LogMessage("BuildOption:{0}", ((int)buildOptionTmp).ToString());

            // 版本号
            string buildVersion = BuildInfo.GetInstance().BuildVersion;

            if (string.IsNullOrEmpty(buildVersion) == false)
            {
                PlayerSettings.bundleVersion = buildVersion;
            }
            BuildLogger.LogMessage("BuildVersion:{0}", buildVersion);

            // buildVersionCode
            int buildVersionCode = BuildInfo.GetInstance().BuildVersionCode;

            PlayerSettings.Android.bundleVersionCode = buildVersionCode;
            BuildLogger.LogMessage("BundleVersionCode:{0}", buildVersionCode.ToString());

            // 中心服务器版本号
            string centerVersion = BuildInfo.GetInstance().CenterVersion;

            BuildLogger.LogMessage("CenterVersion:{0}", centerVersion);

            // 工程名
            string projectName = BuildInfo.GetInstance().BuildName;

            BuildLogger.LogMessage("ProjectName:{0}", projectName);

            // 游戏名字
            string gameName = BuildParameters.GameName;

            if (true == string.IsNullOrEmpty(gameName))
            {
                gameName = projectName;
            }
            PlayerSettings.productName = gameName;
            BuildLogger.LogMessage("GameName:{0}", gameName);

            // BuildID
            string buildID = BuildInfo.GetInstance().BuildID;

            if (false == string.IsNullOrEmpty(buildID))
            {
#if UNITY_5_5_OR_NEWER
                PlayerSettings.applicationIdentifier = buildID;
#else
                PlayerSettings.bundleIdentifier = buildID;
#endif
            }
            BuildLogger.LogMessage("BuildID:{0}", buildID);

            // 初始化
            InitForAndroidBuild();
            BuildLogger.LogMessage(" --> InitForAndroidBuild()");

            // Apk输出路径
            int buildNumber = BuildInfo.GetInstance().BuildNumber;
            BuildLogger.LogMessage("BuildNumber:{0}", buildNumber.ToString());

            string apkPath = string.Format("{0}/{1}_{2}_v{3}_-_{4}_{5}.apk",
                                           outputDir,
                                           projectName,
                                           buildMode,
                                           buildVersion,
                                           buildTime, buildID);
            if (0 < buildNumber)
            {
                apkPath = string.Format("{0}/{1}_{2}_v{3}_{4}_{5}_{6}.apk",
                                        outputDir,
                                        projectName,
                                        buildMode,
                                        buildVersion,
                                        buildNumber,
                                        buildTime, buildID);
            }
            BuildLogger.LogMessage("Apk File Path:{0}", apkPath);

            // 输出打包信息
            OutputBuildInfo(buildVersion, projectName);

            // 开发者模式
            if (BuildOptions.Development == buildOptionTmp)
            {
                // 打包之前,移除非资源对象
                AssetBundles.Common.MoveUnResources();
            }

            // Android下IL2CPP不支持,所以设置回Mono
            PlayerSettings.SetPropertyInt("ScriptingBackend", (int)ScriptingImplementation.Mono2x, BuildTarget.Android);

            string error = BuildPipeline.BuildPlayer(GetBuildScenes(), apkPath, BuildTarget.Android, buildOptionTmp);

            // 开发者模式
            if (BuildOptions.Development == buildOptionTmp)
            {
                // 打包之后,恢复非资源对象
                AssetBundles.Common.MoveBackUnResources();
            }

            if (error != null && !error.Equals("") && !(error.Length == 0))
            {
                BuildLogger.LogException("Android Build Failed!!!(error:{0})", error);
                BuildLogger.CloseBlock();
                throw new ApplicationException();
            }
            else
            {
                BuildLogger.LogMessage("Android Build Successed.");
            }
            BuildLogger.CloseBlock();
        }
Example #13
0
        static void ExportXcodeProject()
        {
            const string funcBlock = "ProjectBuild.ExportXcodeProject()";

            BuildLogger.OpenBlock(funcBlock);

            // 设定打包信息
            SetBuildInfoFromParameters();
            // 平台类型
            BuildInfo.GetInstance().PlatformType = TPlatformType.iOS;

            TBuildMode buildMode = BuildInfo.GetInstance().BuildMode;

            BuildLogger.LogMessage("BuildMode:{0}", buildMode.ToString());

            // 初始化
            InitForExportXcodeProject();
            BuildLogger.LogMessage(" --> InitForExportXcodeProject()");

            // 预定义宏
            //PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, "GAMELINK");

            // 游戏输出目录(iOS):{OutputDir}/iOS/{ProjectName}
            string outputDir = GetOutputDir(BuildTarget.iOS, null);

            if (outputDir == null)
            {
                BuildLogger.LogException("Create Dir Failed.!!(Dir:{0})",
                                         BuildParameters.OutputDir);
                throw new ApplicationException();
            }

            // 打包选项
            BuildOptions buildOptionTmp = BuildOptions.None;

            if (TBuildMode.Debug == buildMode)
            {
                buildOptionTmp |= BuildOptions.Development;
                buildOptionTmp |= BuildOptions.AllowDebugging;
                buildOptionTmp |= BuildOptions.ConnectWithProfiler;
            }
            else
            {
                bool isCheatMode = BuildParameters.IsCheatMode;
                if (true == isCheatMode)
                {
                    buildOptionTmp |= BuildOptions.Development;
                }
            }
            BuildLogger.LogMessage("BuildOption:{0}", ((int)buildOptionTmp).ToString());

            // 工程名
            string projectName = BuildInfo.GetInstance().BuildName;

            BuildLogger.LogMessage("ProjectName:{0}", projectName);

            // 游戏名字
            string gameName = BuildParameters.GameName;

            if (true == string.IsNullOrEmpty(gameName))
            {
                gameName = projectName;
            }
            PlayerSettings.iOS.applicationDisplayName = gameName;
            BuildLogger.LogMessage("GameName:{0}", gameName);

            // BuildID
            string buildID = BuildInfo.GetInstance().BuildID;

            if (false == string.IsNullOrEmpty(buildID))
            {
#if UNITY_5_5_OR_NEWER
                PlayerSettings.applicationIdentifier = buildID;
#else
                PlayerSettings.bundleIdentifier = buildID;
#endif
            }
            BuildLogger.LogMessage("BuildID:{0}", buildID);

            // 版本号
            string buildVersion = BuildInfo.GetInstance().BuildVersion;
            PlayerSettings.bundleVersion = buildVersion;
            BuildLogger.LogMessage("BuildVersion:{0}", buildVersion);

            // 中心服务器版本号
            string centerVersion = BuildInfo.GetInstance().CenterVersion;
            BuildLogger.LogMessage("CenterVersion:{0}", centerVersion);

            // XCode工程目录
            string XcodeProject = string.Format("{0}/XcodeProject", outputDir);

            // 输出打包信息
            OutputBuildInfo(buildVersion, projectName);

            // 开发者模式
            if (BuildOptions.Development == buildOptionTmp)
            {
                // 打包之前,将非资源对象,临时移动到临时文件夹
                AssetBundles.Common.MoveUnResources();
            }

            // 打包成XCode工程目录
                        #if UNITY_5_OR_NEWER
            string error = BuildPipeline.BuildPlayer(
                GetBuildScenes(),
                XcodeProject,
                BuildTarget.iOS, buildOptionTmp);
                        #else
            string error = BuildPipeline.BuildPlayer(
                GetBuildScenes(),
                XcodeProject,
                BuildTarget.iOS, buildOptionTmp);
                        #endif

            // 开发者模式
            if (BuildOptions.Development == buildOptionTmp)
            {
                // 恢复非资源性文件
                AssetBundles.Common.MoveBackUnResources();
            }

            // 存在错误则,打包编译失败
            if (error != null && !error.Equals("") && !(error.Length == 0))
            {
                BuildLogger.LogException("iOS Build Failed!!!(error:{0})", error);
                BuildLogger.CloseBlock();
                throw new ApplicationException();
            }
            else
            {
                BuildLogger.LogMessage("iOS Build Successed.");
            }
            BuildLogger.CloseBlock();
        }