Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.36 KB | None | 0 0
  1. private static string[] FindEnabledEditorScenes()
  2. {
  3. // Get a list of scenes registered in BuildSettings.
  4.  
  5. List<string> editorScenes = new List<string>();
  6. foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
  7. {
  8. if (!scene.enabled) continue;
  9. editorScenes.Add(scene.path);
  10. }
  11. return editorScenes.ToArray();
  12. }
  13.  
  14. public static void Build_Console(string ext, BuildOptions buildoptions, bool auto_resource = true)
  15. {
  16. if (auto_resource)
  17. {
  18. //Move the resource from Editor / Resources to the Resources folder according to the Define symbol (or string ext).
  19. switch (ext)
  20. {
  21. case "PC":
  22. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/PC_VERSION", "Assets/Resources/PC_VERSION");
  23. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/PC_VERSION.meta", "Assets/Resources/PC_VERSION.meta");
  24. AssetDatabase.Refresh();
  25. break;
  26.  
  27. case "AC":
  28. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/AC_VERSION", "Assets/Resources/AC_VERSION");
  29. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/AC_VERSION.meta", "Assets/Resources/AC_VERSION.meta");
  30. AssetDatabase.Refresh();
  31. break;
  32. //Reserve code for android implemetation
  33. case "MC":
  34. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/MC_VERSION", "Assets/Resources/MC_VERSION");
  35. FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/MC_VERSION.meta", "Assets/Resources/MC_VERSION");
  36. AssetDatabase.Refresh();
  37. break;
  38.  
  39. default:
  40. Debug.LogWarningFormat("{0} 에 대한 정의가 없습니다.", ext);
  41. return;
  42. }
  43. }
  44.  
  45. // Remember state ..
  46. BuildTarget bBuildTarget = EditorUserBuildSettings.activeBuildTarget;
  47.  
  48. // The actual build scene.
  49. string[] scenes = FindEnabledEditorScenes();
  50.  
  51. try
  52. {
  53. MakeCurrentDate();
  54.  
  55. // Rebuild asset bundle files
  56. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
  57. //Rtoran.AssetBundleBuilder.LoadResourceList();
  58.  
  59. //Selection.activeObject = AssetDatabase.LoadAssetAtPath("Assets/Resources", typeof(UnityEngine.Object));
  60. //Rtoran.AssetBundleBuilder.AddResourceForced(false);
  61. //Rtoran.AssetBundleBuilder.BuildAssetBundle(false);
  62.  
  63. // Later, if you have a sound file.
  64. //ForceAssetImport();
  65.  
  66. // Move resource folders
  67. //MoveResourceToMakeBundle();
  68.  
  69. //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
  70.  
  71. PlayerSettings.colorSpace = ColorSpace.Linear;
  72.  
  73. PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_2_0;
  74.  
  75. //BuildVersionAndroid(scenes, eClientVersionType.CLIENT_VERSION_GOOGLEPLAY);
  76.  
  77. string apkdataPath = Application.dataPath;
  78. string szStoreIdentity = "/WINDOWS/";
  79.  
  80. string[] arSplitDataPath = Application.dataPath.Split('/');
  81. if (arSplitDataPath.Length == 1)
  82. {
  83. arSplitDataPath = Application.dataPath.Split('\');
  84. }
  85.  
  86. string szProjectForlderName = "";
  87. if (arSplitDataPath.Length > 1)
  88. {
  89. szProjectForlderName = arSplitDataPath[arSplitDataPath.Length - 2];
  90. }
  91. m_szapkFilename = apkdataPath.Replace(szProjectForlderName + "/Assets", "RELEASE/CONSOLE" + szStoreIdentity + ext + "_" + CurrentDate + "/" + eBuildInfo.ProductName + ".exe");
  92.  
  93. string szBuildResult = BuildPipeline.BuildPlayer(scenes, m_szapkFilename, BuildTarget.StandaloneWindows, buildoptions);
  94.  
  95. string buildTypeStr = "Console 버전 빌드";
  96.  
  97. if (szBuildResult.Length > 0)
  98. {
  99. throw new Exception(buildTypeStr + " 빌드 실패: " + szBuildResult);
  100. }
  101. else
  102. {
  103. hsDebug.Log(buildTypeStr + " 빌드 성공 : " + m_szapkFilename, WW.debug.cat.FSM_CHANGE);
  104. }
  105.  
  106. // Move the resource folder back to its original location
  107. //MoveResourceFolderToTempBack();
  108.  
  109. // Done to the original state.
  110. // EditorUserBuildSettings.SwitchActiveBuildTarget(bBuildTarget);
  111.  
  112. }
  113. catch (Exception e)
  114. {
  115. hsDebug.LogError("Build Failed : " + e);
  116. //EditorUserBuildSettings.SwitchActiveBuildTarget(bBuildTarget);
  117. //OnPostMoveToUnNecessaryFiles();
  118. }
  119. finally
  120. {
  121. if (auto_resource)
  122. {
  123. //Restore the folder you moved to Resources.
  124. switch (ext)
  125. {
  126. case "PC":
  127. FileUtil.MoveFileOrDirectory("Assets/Resources/PC_VERSION", "Assets/Editor/Resources/PC_VERSION");
  128. FileUtil.MoveFileOrDirectory("Assets/Resources/PC_VERSION.meta", "Assets/Editor/Resources/PC_VERSION.meta");
  129. AssetDatabase.Refresh();
  130. break;
  131.  
  132. case "AC":
  133. FileUtil.MoveFileOrDirectory("Assets/Resources/AC_VERSION", "Assets/Editor/Resources/AC_VERSION");
  134. FileUtil.MoveFileOrDirectory("Assets/Resources/AC_VERSION.meta", "Assets/Editor/Resources/AC_VERSION.meta");
  135. AssetDatabase.Refresh();
  136. break;
  137.  
  138. //Reserve code for android implemetation
  139. case "MC":
  140. FileUtil.MoveFileOrDirectory("Assets/Resources/MC_VERSION","Assets/Editor/Resources/MC_VERSION");
  141. FileUtil.MoveFileOrDirectory("Assets/Resources/MC_VERSION", "Assets/Editor/Resources/MC_VERSION.meta");
  142. AssetDatabase.Refresh();
  143. break;
  144.  
  145. default:
  146. Debug.LogWarningFormat("{0} 에 대한 정의가 없습니다.", ext);
  147. break;
  148. }
  149. }
  150. }
  151. }
  152.  
  153. static string m_szapkFilename;
  154. static string m_szBackupApkFilename;
  155.  
  156. static void BuildVersionAndroid(string[] scenes, short eCVC, bool bRelease = true){
  157. //Lets change the platform
  158. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
  159. BuildSettingPlatform(eCVC);
  160.  
  161. string apkdataPath = Application.dataPath;
  162. int nClientVersion = (int)eCVC * 10; //need to put a 0 at the end
  163.  
  164. const string szWebApkName = eBuildInfo.ProductName;
  165. const string szApkExt = ".apk";
  166.  
  167. m_szapkFilename = szWebApkName + "_";
  168. m_szBackupApkFilename = szWebApkName + "_";
  169.  
  170. string szProjectFolderName = "";
  171.  
  172. string[] arSplitDataPath = Application.dataPath.Split('/');
  173.  
  174. if(arSplitDataPath.Length == 1){
  175. arSplitDataPath = Application.dataPath.Split('\');
  176. }
  177. if(arSplitDataPath.Length > 1){
  178. szProjectFolderName = arSplitDataPath[arSplitDataPath.Length - 2];
  179. }
  180.  
  181. string szStoreIdentity = null;
  182.  
  183. switch (eCVC){
  184. case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
  185. szStoreIdentity = "GOOGLEPLAY";
  186. break;
  187. }
  188.  
  189. m_szapkFilename = apkdataPath.Replace(szProjectFolderName + "/Assets", "RELEASE/ANDROID/" + szStoreIdentity + "/" + szWebApkName + "_" + CurrentDate + "_" + szStoreIdentity + szApkExt);
  190.  
  191. m_szBackupApkFilename = apkdataPath.Replace(szProjectFolderName + "/Assets", "BACKUP/ANDROID/" + szStoreIdentity + "/" + CurrentDate + szWebApkName + "_" + CurrentDate + "_" + szStoreIdentity + szApkExt);
  192.  
  193. // If there is a previous file before the build, clear it
  194. hsFileIO.DeleteFileName(m_szapkFilename);
  195. hsFileIO.DeleteFileName(m_szBackupApkFilename);
  196.  
  197. // Create if there is no such folder
  198. hsFileIO.CreateFolder(m_szapkFilename);
  199. hsFileIO.CreateFolder(m_szBackupApkFilename);
  200.  
  201. bool bBuildResult = false;
  202. string m_szapkDebugFilename = m_szapkFilename.Replace(".apk", "_debug.apk");
  203.  
  204. string buildTypeStr = "";
  205. string szBuildResult = "";
  206.  
  207. try{
  208. if(bRelease){
  209. buildTypeStr = "Release";
  210. //szBuildResult = BuildPipeline.BuildPlayer(scenes, m_szapkFilename, BuildTarget.Android, BuildOptions.None
  211. BuildPlayerOptions szBuildResults = new BuildPlayerOptions();
  212. szBuildResults.scenes = scenes;
  213. szBuildResults.locationPathName = m_szapkFilename;
  214. szBuildResults.target = BuildTarget.Android;
  215. szBuildResults.options = BuildOptions.None;
  216. BuildPipeline.BuildPlayer(szBuildResults);
  217. } else {
  218. buildTypeStr = "Debug";
  219.  
  220. BuildPlayerOptions szBuildResults = new BuildPlayerOptions();
  221. szBuildResults.scenes = scenes;
  222. szBuildResults.locationPathName = m_szapkDebugFilename;
  223. szBuildResults.target = BuildTarget.Android;
  224. szBuildResults.options = BuildOptions.AllowDebugging | BuildOptions.Development;
  225. BuildPipeline.BuildPlayer(szBuildResults);
  226. }
  227. }
  228.  
  229. catch (Exception ex){
  230. throw new Exception(buildTypeStr + "Build Failed Ex :" + ex);
  231. }
  232.  
  233. if(szBuildResult.Length > 0){
  234. throw new Exception(buildTypeStr + "Build Failed:" + szBuildResult);
  235. return;
  236. } else {
  237. if(bRelease){
  238. hsDebug.Log(buildTypeStr + "Build Success :" + m_szapkFilename, WW.debug.cat.FSM_CHANGE);
  239. } else {
  240. hsDebug.Log(buildTypeStr + "Build Success :" + m_szapkDebugFilename, WW.debug.cat.FSM_CHANGE);
  241. }
  242. bBuildResult = true;
  243. }
  244.  
  245. if(!bBuildResult){
  246. throw new Exception(buildTypeStr + "Build Failed" + szBuildResult);
  247. }
  248. return;
  249. }
  250.  
  251. static public void ShowExplorer(string itemPath)
  252. {
  253. itemPath = itemPath.Replace(@"/", @""); // explorer doesn't like front slashes
  254. System.Diagnostics.Process.Start("explorer.exe", "/select," + itemPath);
  255. }
  256.  
  257. static void AndroidManifestChanger(short eCVC)
  258. {
  259. //hsDebug.LogError("Start AndroidManifestChanger : " + eCVC + " , ClientVersion.Instance.StoreVersion : " + eCVC);
  260. //try
  261.  
  262. //{
  263. string storename = "";
  264. switch (eCVC)
  265. {
  266. case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
  267. {
  268. storename = "Google";
  269. }
  270. break;
  271. }
  272.  
  273. string strDefaultLoadPath = "";// = "Plugins/Android/AndroidManifest.txt";
  274.  
  275. CXmlDataAccesor.GetDefaultLoadingXmlPath(out strDefaultLoadPath, false);
  276.  
  277. string szFileFullPath_Manifest = "";
  278. szFileFullPath_Manifest = strDefaultLoadPath + "StoreCategorize\{0}\AndroidManifest.xml";
  279.  
  280. szFileFullPath_Manifest = string.Format(szFileFullPath_Manifest, storename);
  281.  
  282. string szAfterManifestFolder = strDefaultLoadPath + "Assets\Plugins\Android\AndroidManifest.xml";
  283.  
  284. if (!hsFileIO.IsExistFile(szFileFullPath_Manifest))
  285. {
  286. Debug.LogError(szFileFullPath_Manifest + " - none");
  287. return;
  288. }
  289. else
  290. {
  291. if (hsFileIO.IsExistFile(szAfterManifestFolder))
  292. hsFileIO.DeleteFileName(szAfterManifestFolder);
  293.  
  294. hsFileIO.CopyFile(szFileFullPath_Manifest, szAfterManifestFolder);
  295. }
  296.  
  297. //Plugin jar file Copy whole folder ... Let's leave ... dhkim
  298. string szFileFullPath_Jar = "";
  299. string szAfterJarFolder = "Assets\Plugins\Android\";
  300.  
  301.  
  302. //dhkim OOOOoooo and Rtoran organize all the plugins files to be replaced at build time
  303. for (int i = 0; i < eBuildInfo.RtoranLibFileName.Length; i++ )
  304. hsFileIO.DeleteFileName(szAfterJarFolder + "libs\" + eBuildInfo.RtoranLibFileName[i]);
  305.  
  306. switch (eCVC)
  307. {
  308. case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
  309. szFileFullPath_Jar = "StoreCategorize\PluginsLibsRtoran\";
  310.  
  311. for (int i = 0; i < eBuildInfo.RtoranLibFileName.Length; i++)
  312. {
  313. string _filename = eBuildInfo.RtoranLibFileName[i];
  314. hsFileIO.CopyFile(szFileFullPath_Jar + _filename, szAfterJarFolder + "libs\" + _filename);
  315. }
  316. break;
  317. }
  318.  
  319. for (int i = 0; i < eBuildInfo.IconFileName.Length; i++)
  320. {
  321. string _filename = eBuildInfo.IconFileName[i];
  322. hsFileIO.CopyFile(szFileFullPath_Jar + _filename, "Assets\UIResources\System - Non Atlas\" + _filename);
  323. }
  324.  
  325. /*
  326. //Plugin jar file Copy whole folder ... Let's leave ... dhkim
  327. switch (eCVC)
  328. {
  329. case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
  330. {
  331. ClientVersion.Instance.StoreVersion = ClientVersion.eStoreType.GOOGLE;
  332. ClientVersion.Instance.PublisherNick = "g";
  333. ClientVersion.Instance.VersionCode = (int)ClientVersion.ePlatformVersion.RtoranGoogleVersionCode;
  334. }
  335. break;
  336. default:
  337. {
  338. ClientVersion.Instance.StoreVersion = ClientVersion.eStoreType.GOOGLE;
  339. ClientVersion.Instance.PublisherNick = "g";
  340. ClientVersion.Instance.VersionCode = (int)ClientVersion.ePlatformVersion.RtoranGoogleVersionCode;
  341. }
  342. break;
  343. }
  344.  
  345. //hsDebug.Log("ClientVersion.Instance.VersionCode = " + ClientVersion.Instance.VersionCode, WW.debug.cat.FSM_CHANGE);
  346.  
  347. //// Save client version
  348. ClientVersion.Instance.CreateVersion();
  349. */
  350. //}
  351. }
  352.  
  353. private static string UTF8ByteArrayToString(Byte[] characters)
  354. {
  355. UTF8Encoding encoding = new UTF8Encoding();
  356. return encoding.GetString(characters);
  357. }
  358.  
  359. private static byte[] StringToUTF8ByteArray(String pXmlString)
  360. {
  361. UTF8Encoding encoding = new UTF8Encoding();
  362. return encoding.GetBytes(pXmlString);
  363. }
Add Comment
Please, Sign In to add comment