language:unity:빌드_스크립트
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| language:unity:빌드_스크립트 [2020/01/10 16:42] – 만듦 kieuns | language:unity:빌드_스크립트 [2024/04/23 22:44] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ====== 공통 ====== | ||
| + | 그냥 복붙용 코드 보는게 나을듯. | ||
| + | |||
| + | ===== 빌드용 커맨드 ===== | ||
| + | |||
| + | ====== AOS ====== | ||
| + | |||
| + | ===== 빌드용 커맨드 ===== | ||
| + | |||
| + | 맥용 터미널에서 호출하는 예시. 아래는 보기 좋게 줄 구분이 되어 있지만 실제 쓸때는 한줄이어야 함. | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | <code bash> | ||
| + | -quit -batchmode | ||
| + | -projectPath $WORKSPACE/ | ||
| + | -executeMethod BuildProc.aos_release | ||
| + | -logFile $WORKSPACE/ | ||
| + | -CustomArgs: | ||
| + | </ | ||
| + | |||
| + | * **quit**: 빌드 끝내면 프로세스 종료하도록 | ||
| + | * **batchmode**: | ||
| + | * **projectPath**: | ||
| + | * **executeMethod**: | ||
| + | * **logFile**: | ||
| + | * **CustomArgs**: | ||
| + | |||
| + | 젠킨스옵션 | ||
| + | |||
| + | * **%%$WORKSPACE%%** : 현재 JOB의 작업 폴더 | ||
| + | * **%%$JOB_BASE_NAME%%** : 현재의 젠킨스 잡 이름 | ||
| + | * **%%$BUILD_NUMBER%%** : 현재 빌드 번호 | ||
| + | |||
| + | ===== 스크립트 ===== | ||
| + | |||
| + | <code csharp> | ||
| + | #if UNITY_EDITOR | ||
| + | using UnityEditor; | ||
| + | #endif | ||
| + | using UnityEngine; | ||
| + | using UnityEditor.Build.Reporting; | ||
| + | |||
| + | // MonoBehaviour 은 없어도 되는듯? | ||
| + | public class BuildProc : MonoBehaviour | ||
| + | { | ||
| + | // 메뉴에 추가해서 테스트 해볼 수 있게 | ||
| + | [MenuItem(" | ||
| + | public static void aos_release() | ||
| + | { | ||
| + | // CommandLineReader 별도 클래스를 써서, 추가 파라미터를 받아온다. | ||
| + | | ||
| + | // ' | ||
| + | string _build_path = CommandLineReader.GetCustomArgument(" | ||
| + | Debug.Log(" | ||
| + | Debug.Log(" | ||
| + | |||
| + | // 프로젝트 세팅 외에 이렇게 씬을 직접 넣어야 하는지는 미지수. 테스트 필요. | ||
| + | BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); | ||
| + | buildPlayerOptions.scenes = new[] { " | ||
| + | |||
| + | // 최종 파일을 어디에 저장할 것인가? | ||
| + | if(_build_path == "" | ||
| + | else { buildPlayerOptions.locationPathName = _build_path; | ||
| + | |||
| + | Debug.Log(" | ||
| + | |||
| + | // 안드로이드용 설정 | ||
| + | buildPlayerOptions.target = BuildTarget.Android; | ||
| + | buildPlayerOptions.options = BuildOptions.None; | ||
| + | |||
| + | // | ||
| + | // 안드로이드 빌드할때 필요한 인증키와 암호. 코드 안에서 설정 가능하다. 좋군. | ||
| + | // | ||
| + | PlayerSettings.Android.keyaliasName = " | ||
| + | PlayerSettings.Android.keyaliasPass = " | ||
| + | PlayerSettings.Android.keystoreName = " | ||
| + | PlayerSettings.Android.keystorePass = " | ||
| + | |||
| + | // 빌드 고고 | ||
| + | BuildReport _report = BuildPipeline.BuildPlayer(buildPlayerOptions); | ||
| + | BuildSummary summary = _report.summary; | ||
| + | |||
| + | if(summary.result == BuildResult.Succeeded) { | ||
| + | Debug.Log(" | ||
| + | } | ||
| + | else if(summary.result == BuildResult.Failed) { | ||
| + | Debug.Log(" | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // | ||
| + | // 나머지 부분은 ios라서 아래쪽에 | ||
| + | // | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== iOS ====== | ||
| + | |||
| + | ios용 빌드는, Xcode용 프로젝트를 export 하는 것으로 작업이 끝난다. | ||
| + | |||
| + | Xcode 빌드는 직접하거나, | ||
| + | |||
| + | ===== 빌드용 커맨드 ===== | ||
| + | |||
| + | 맥용 터미널에서 호출하는 예시. 아래는 보기 좋게 줄 구분이 되어 있지만 실제 쓸때는 한줄이어야 함. | ||
| + | |||
| + | <code bash> | ||
| + | -batchmode -quit | ||
| + | -executeMethod BuildProc.ios_release | ||
| + | -projectPath $WORKSPACE/ | ||
| + | -logFile $WORKSPACE/ | ||
| + | -CustomArgs: | ||
| + | </ | ||
| + | |||
| + | 빌드 파라미터 설명은 위와([[# | ||
| + | ===== 스크립트 ===== | ||
| + | |||
| + | <code csharp> | ||
| + | { | ||
| + | [MenuItem(" | ||
| + | public static void ios_release() | ||
| + | { | ||
| + | if(Application.platform != RuntimePlatform.OSXEditor) { Debug.Log(" | ||
| + | |||
| + | string _build_path = CommandLineReader.GetCustomArgument(" | ||
| + | Debug.Log(" | ||
| + | Debug.Log(" | ||
| + | |||
| + | // 씬을 추가해야 하는가? 는 나중에 테스트 해보기로. | ||
| + | BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); | ||
| + | buildPlayerOptions.scenes = new[] { " | ||
| + | |||
| + | if(_build_path == "" | ||
| + | else { buildPlayerOptions.locationPathName = _build_path; | ||
| + | |||
| + | Debug.Log(" | ||
| + | |||
| + | // 개발 플랫폼 설정 | ||
| + | buildPlayerOptions.target = BuildTarget.iOS; | ||
| + | buildPlayerOptions.options = BuildOptions.None; | ||
| + | |||
| + | // 추가 옵션 없이 바로 빌드 고 | ||
| + | BuildReport _report = BuildPipeline.BuildPlayer(buildPlayerOptions); | ||
| + | BuildSummary summary = _report.summary; | ||
| + | |||
| + | if(summary.result == BuildResult.Succeeded) { | ||
| + | Debug.Log(" | ||
| + | } | ||
| + | else if(summary.result == BuildResult.Failed) { | ||
| + | Debug.Log(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== 그외 : CommandLineReader ====== | ||
| + | |||
| + | * CommandLineReader 클래스는 귀찮으니 여기에도 복사해둠. | ||
| + | |||
| + | ++++ CommandLineReader.cs (클릭하면 열림) | | ||
| + | |||
| + | <file csharp CommandLineReader.cs> | ||
| + | #region Author | ||
| + | / | ||
| + | Author: EpixCode (Keven Poulin) | ||
| + | Website: http:// | ||
| + | GitHub: https:// | ||
| + | Twitter: https:// | ||
| + | LinkedIn: http:// | ||
| + | ************************************************************************************************************/ | ||
| + | #endregion | ||
| + | |||
| + | #region Copyright | ||
| + | / | ||
| + | Copyright (C) 2013 EpixCode | ||
| + | |||
| + | Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
| + | and associated documentation files (the " | ||
| + | including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
| + | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished | ||
| + | to do so, subject to the following conditions: | ||
| + | |||
| + | The above copyright notice and this permission notice shall be included in all copies or substantial | ||
| + | portions of the Software. | ||
| + | |||
| + | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
| + | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| + | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| + | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| + | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| + | ************************************************************************************************************/ | ||
| + | #endregion | ||
| + | |||
| + | #region Class Documentation | ||
| + | / | ||
| + | Class Name: | ||
| + | Namespace: | ||
| + | Type: Util, Static | ||
| + | Definition: | ||
| + | CommandLineReader.cs give the ability to access [Custom Arguments] sent | ||
| + | through the command line. Simply add your custom arguments under the | ||
| + | keyword ' | ||
| + | Example: | ||
| + | C:\Program Files (x86)\Unity\Editor\Unity.exe [ProjectLocation] -executeMethod [Your entrypoint] -quit -CustomArgs: | ||
| + | | ||
| + | ************************************************************************************************************/ | ||
| + | #endregion | ||
| + | |||
| + | #region Using | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | using System.Linq; | ||
| + | using UnityEngine; | ||
| + | #endregion | ||
| + | |||
| + | public class CommandLineReader | ||
| + | { | ||
| + | //Config | ||
| + | private const string CUSTOM_ARGS_PREFIX = " | ||
| + | private const char CUSTOM_ARGS_SEPARATOR = ' | ||
| + | | ||
| + | public static string[] GetCommandLineArgs() | ||
| + | { | ||
| + | return Environment.GetCommandLineArgs(); | ||
| + | } | ||
| + | | ||
| + | public static string GetCommandLine() | ||
| + | { | ||
| + | string[] args = GetCommandLineArgs(); | ||
| + | | ||
| + | if (args.Length > 0) | ||
| + | { | ||
| + | return string.Join(" | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Debug.LogError(" | ||
| + | return ""; | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | public static Dictionary< | ||
| + | { | ||
| + | Dictionary< | ||
| + | string[] commandLineArgs = GetCommandLineArgs(); | ||
| + | string[] customArgs; | ||
| + | string[] customArgBuffer; | ||
| + | string customArgsStr = ""; | ||
| + | | ||
| + | try | ||
| + | { | ||
| + | customArgsStr = commandLineArgs.Where(row => row.Contains(CUSTOM_ARGS_PREFIX)).Single(); | ||
| + | } | ||
| + | catch (Exception e) | ||
| + | { | ||
| + | Debug.LogError(" | ||
| + | return customArgsDict; | ||
| + | } | ||
| + | | ||
| + | customArgsStr = customArgsStr.Replace(CUSTOM_ARGS_PREFIX, | ||
| + | customArgs = customArgsStr.Split(CUSTOM_ARGS_SEPARATOR); | ||
| + | | ||
| + | foreach (string customArg in customArgs) | ||
| + | { | ||
| + | customArgBuffer = customArg.Split(' | ||
| + | if (customArgBuffer.Length == 2) | ||
| + | { | ||
| + | customArgsDict.Add(customArgBuffer[0], | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Debug.LogWarning(" | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | return customArgsDict; | ||
| + | } | ||
| + | | ||
| + | public static string GetCustomArgument(string argumentName) | ||
| + | { | ||
| + | Dictionary< | ||
| + | | ||
| + | if (customArgsDict.ContainsKey(argumentName)) | ||
| + | { | ||
| + | return customArgsDict[argumentName]; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Debug.LogError(" | ||
| + | return ""; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ++++ | ||