Esempio n. 1
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();
        }
Esempio n. 2
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();
        }