Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static string[] FindEnabledEditorScenes()
- {
- // Get a list of scenes registered in BuildSettings.
- List<string> editorScenes = new List<string>();
- foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
- {
- if (!scene.enabled) continue;
- editorScenes.Add(scene.path);
- }
- return editorScenes.ToArray();
- }
- public static void Build_Console(string ext, BuildOptions buildoptions, bool auto_resource = true)
- {
- if (auto_resource)
- {
- //Move the resource from Editor / Resources to the Resources folder according to the Define symbol (or string ext).
- switch (ext)
- {
- case "PC":
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/PC_VERSION", "Assets/Resources/PC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/PC_VERSION.meta", "Assets/Resources/PC_VERSION.meta");
- AssetDatabase.Refresh();
- break;
- case "AC":
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/AC_VERSION", "Assets/Resources/AC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/AC_VERSION.meta", "Assets/Resources/AC_VERSION.meta");
- AssetDatabase.Refresh();
- break;
- //Reserve code for android implemetation
- case "MC":
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/MC_VERSION", "Assets/Resources/MC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Editor/Resources/MC_VERSION.meta", "Assets/Resources/MC_VERSION");
- AssetDatabase.Refresh();
- break;
- default:
- Debug.LogWarningFormat("{0} 에 대한 정의가 없습니다.", ext);
- return;
- }
- }
- // Remember state ..
- BuildTarget bBuildTarget = EditorUserBuildSettings.activeBuildTarget;
- // The actual build scene.
- string[] scenes = FindEnabledEditorScenes();
- try
- {
- MakeCurrentDate();
- // Rebuild asset bundle files
- EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
- //Rtoran.AssetBundleBuilder.LoadResourceList();
- //Selection.activeObject = AssetDatabase.LoadAssetAtPath("Assets/Resources", typeof(UnityEngine.Object));
- //Rtoran.AssetBundleBuilder.AddResourceForced(false);
- //Rtoran.AssetBundleBuilder.BuildAssetBundle(false);
- // Later, if you have a sound file.
- //ForceAssetImport();
- // Move resource folders
- //MoveResourceToMakeBundle();
- //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
- PlayerSettings.colorSpace = ColorSpace.Linear;
- PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_2_0;
- //BuildVersionAndroid(scenes, eClientVersionType.CLIENT_VERSION_GOOGLEPLAY);
- string apkdataPath = Application.dataPath;
- string szStoreIdentity = "/WINDOWS/";
- string[] arSplitDataPath = Application.dataPath.Split('/');
- if (arSplitDataPath.Length == 1)
- {
- arSplitDataPath = Application.dataPath.Split('\');
- }
- string szProjectForlderName = "";
- if (arSplitDataPath.Length > 1)
- {
- szProjectForlderName = arSplitDataPath[arSplitDataPath.Length - 2];
- }
- m_szapkFilename = apkdataPath.Replace(szProjectForlderName + "/Assets", "RELEASE/CONSOLE" + szStoreIdentity + ext + "_" + CurrentDate + "/" + eBuildInfo.ProductName + ".exe");
- string szBuildResult = BuildPipeline.BuildPlayer(scenes, m_szapkFilename, BuildTarget.StandaloneWindows, buildoptions);
- string buildTypeStr = "Console 버전 빌드";
- if (szBuildResult.Length > 0)
- {
- throw new Exception(buildTypeStr + " 빌드 실패: " + szBuildResult);
- }
- else
- {
- hsDebug.Log(buildTypeStr + " 빌드 성공 : " + m_szapkFilename, WW.debug.cat.FSM_CHANGE);
- }
- // Move the resource folder back to its original location
- //MoveResourceFolderToTempBack();
- // Done to the original state.
- // EditorUserBuildSettings.SwitchActiveBuildTarget(bBuildTarget);
- }
- catch (Exception e)
- {
- hsDebug.LogError("Build Failed : " + e);
- //EditorUserBuildSettings.SwitchActiveBuildTarget(bBuildTarget);
- //OnPostMoveToUnNecessaryFiles();
- }
- finally
- {
- if (auto_resource)
- {
- //Restore the folder you moved to Resources.
- switch (ext)
- {
- case "PC":
- FileUtil.MoveFileOrDirectory("Assets/Resources/PC_VERSION", "Assets/Editor/Resources/PC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Resources/PC_VERSION.meta", "Assets/Editor/Resources/PC_VERSION.meta");
- AssetDatabase.Refresh();
- break;
- case "AC":
- FileUtil.MoveFileOrDirectory("Assets/Resources/AC_VERSION", "Assets/Editor/Resources/AC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Resources/AC_VERSION.meta", "Assets/Editor/Resources/AC_VERSION.meta");
- AssetDatabase.Refresh();
- break;
- //Reserve code for android implemetation
- case "MC":
- FileUtil.MoveFileOrDirectory("Assets/Resources/MC_VERSION","Assets/Editor/Resources/MC_VERSION");
- FileUtil.MoveFileOrDirectory("Assets/Resources/MC_VERSION", "Assets/Editor/Resources/MC_VERSION.meta");
- AssetDatabase.Refresh();
- break;
- default:
- Debug.LogWarningFormat("{0} 에 대한 정의가 없습니다.", ext);
- break;
- }
- }
- }
- }
- static string m_szapkFilename;
- static string m_szBackupApkFilename;
- static void BuildVersionAndroid(string[] scenes, short eCVC, bool bRelease = true){
- //Lets change the platform
- EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
- BuildSettingPlatform(eCVC);
- string apkdataPath = Application.dataPath;
- int nClientVersion = (int)eCVC * 10; //need to put a 0 at the end
- const string szWebApkName = eBuildInfo.ProductName;
- const string szApkExt = ".apk";
- m_szapkFilename = szWebApkName + "_";
- m_szBackupApkFilename = szWebApkName + "_";
- string szProjectFolderName = "";
- string[] arSplitDataPath = Application.dataPath.Split('/');
- if(arSplitDataPath.Length == 1){
- arSplitDataPath = Application.dataPath.Split('\');
- }
- if(arSplitDataPath.Length > 1){
- szProjectFolderName = arSplitDataPath[arSplitDataPath.Length - 2];
- }
- string szStoreIdentity = null;
- switch (eCVC){
- case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
- szStoreIdentity = "GOOGLEPLAY";
- break;
- }
- m_szapkFilename = apkdataPath.Replace(szProjectFolderName + "/Assets", "RELEASE/ANDROID/" + szStoreIdentity + "/" + szWebApkName + "_" + CurrentDate + "_" + szStoreIdentity + szApkExt);
- m_szBackupApkFilename = apkdataPath.Replace(szProjectFolderName + "/Assets", "BACKUP/ANDROID/" + szStoreIdentity + "/" + CurrentDate + szWebApkName + "_" + CurrentDate + "_" + szStoreIdentity + szApkExt);
- // If there is a previous file before the build, clear it
- hsFileIO.DeleteFileName(m_szapkFilename);
- hsFileIO.DeleteFileName(m_szBackupApkFilename);
- // Create if there is no such folder
- hsFileIO.CreateFolder(m_szapkFilename);
- hsFileIO.CreateFolder(m_szBackupApkFilename);
- bool bBuildResult = false;
- string m_szapkDebugFilename = m_szapkFilename.Replace(".apk", "_debug.apk");
- string buildTypeStr = "";
- string szBuildResult = "";
- try{
- if(bRelease){
- buildTypeStr = "Release";
- //szBuildResult = BuildPipeline.BuildPlayer(scenes, m_szapkFilename, BuildTarget.Android, BuildOptions.None
- BuildPlayerOptions szBuildResults = new BuildPlayerOptions();
- szBuildResults.scenes = scenes;
- szBuildResults.locationPathName = m_szapkFilename;
- szBuildResults.target = BuildTarget.Android;
- szBuildResults.options = BuildOptions.None;
- BuildPipeline.BuildPlayer(szBuildResults);
- } else {
- buildTypeStr = "Debug";
- BuildPlayerOptions szBuildResults = new BuildPlayerOptions();
- szBuildResults.scenes = scenes;
- szBuildResults.locationPathName = m_szapkDebugFilename;
- szBuildResults.target = BuildTarget.Android;
- szBuildResults.options = BuildOptions.AllowDebugging | BuildOptions.Development;
- BuildPipeline.BuildPlayer(szBuildResults);
- }
- }
- catch (Exception ex){
- throw new Exception(buildTypeStr + "Build Failed Ex :" + ex);
- }
- if(szBuildResult.Length > 0){
- throw new Exception(buildTypeStr + "Build Failed:" + szBuildResult);
- return;
- } else {
- if(bRelease){
- hsDebug.Log(buildTypeStr + "Build Success :" + m_szapkFilename, WW.debug.cat.FSM_CHANGE);
- } else {
- hsDebug.Log(buildTypeStr + "Build Success :" + m_szapkDebugFilename, WW.debug.cat.FSM_CHANGE);
- }
- bBuildResult = true;
- }
- if(!bBuildResult){
- throw new Exception(buildTypeStr + "Build Failed" + szBuildResult);
- }
- return;
- }
- static public void ShowExplorer(string itemPath)
- {
- itemPath = itemPath.Replace(@"/", @""); // explorer doesn't like front slashes
- System.Diagnostics.Process.Start("explorer.exe", "/select," + itemPath);
- }
- static void AndroidManifestChanger(short eCVC)
- {
- //hsDebug.LogError("Start AndroidManifestChanger : " + eCVC + " , ClientVersion.Instance.StoreVersion : " + eCVC);
- //try
- //{
- string storename = "";
- switch (eCVC)
- {
- case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
- {
- storename = "Google";
- }
- break;
- }
- string strDefaultLoadPath = "";// = "Plugins/Android/AndroidManifest.txt";
- CXmlDataAccesor.GetDefaultLoadingXmlPath(out strDefaultLoadPath, false);
- string szFileFullPath_Manifest = "";
- szFileFullPath_Manifest = strDefaultLoadPath + "StoreCategorize\{0}\AndroidManifest.xml";
- szFileFullPath_Manifest = string.Format(szFileFullPath_Manifest, storename);
- string szAfterManifestFolder = strDefaultLoadPath + "Assets\Plugins\Android\AndroidManifest.xml";
- if (!hsFileIO.IsExistFile(szFileFullPath_Manifest))
- {
- Debug.LogError(szFileFullPath_Manifest + " - none");
- return;
- }
- else
- {
- if (hsFileIO.IsExistFile(szAfterManifestFolder))
- hsFileIO.DeleteFileName(szAfterManifestFolder);
- hsFileIO.CopyFile(szFileFullPath_Manifest, szAfterManifestFolder);
- }
- //Plugin jar file Copy whole folder ... Let's leave ... dhkim
- string szFileFullPath_Jar = "";
- string szAfterJarFolder = "Assets\Plugins\Android\";
- //dhkim OOOOoooo and Rtoran organize all the plugins files to be replaced at build time
- for (int i = 0; i < eBuildInfo.RtoranLibFileName.Length; i++ )
- hsFileIO.DeleteFileName(szAfterJarFolder + "libs\" + eBuildInfo.RtoranLibFileName[i]);
- switch (eCVC)
- {
- case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
- szFileFullPath_Jar = "StoreCategorize\PluginsLibsRtoran\";
- for (int i = 0; i < eBuildInfo.RtoranLibFileName.Length; i++)
- {
- string _filename = eBuildInfo.RtoranLibFileName[i];
- hsFileIO.CopyFile(szFileFullPath_Jar + _filename, szAfterJarFolder + "libs\" + _filename);
- }
- break;
- }
- for (int i = 0; i < eBuildInfo.IconFileName.Length; i++)
- {
- string _filename = eBuildInfo.IconFileName[i];
- hsFileIO.CopyFile(szFileFullPath_Jar + _filename, "Assets\UIResources\System - Non Atlas\" + _filename);
- }
- /*
- //Plugin jar file Copy whole folder ... Let's leave ... dhkim
- switch (eCVC)
- {
- case eClientVersionType.CLIENT_VERSION_GOOGLEPLAY:
- {
- ClientVersion.Instance.StoreVersion = ClientVersion.eStoreType.GOOGLE;
- ClientVersion.Instance.PublisherNick = "g";
- ClientVersion.Instance.VersionCode = (int)ClientVersion.ePlatformVersion.RtoranGoogleVersionCode;
- }
- break;
- default:
- {
- ClientVersion.Instance.StoreVersion = ClientVersion.eStoreType.GOOGLE;
- ClientVersion.Instance.PublisherNick = "g";
- ClientVersion.Instance.VersionCode = (int)ClientVersion.ePlatformVersion.RtoranGoogleVersionCode;
- }
- break;
- }
- //hsDebug.Log("ClientVersion.Instance.VersionCode = " + ClientVersion.Instance.VersionCode, WW.debug.cat.FSM_CHANGE);
- //// Save client version
- ClientVersion.Instance.CreateVersion();
- */
- //}
- }
- private static string UTF8ByteArrayToString(Byte[] characters)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- return encoding.GetString(characters);
- }
- private static byte[] StringToUTF8ByteArray(String pXmlString)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- return encoding.GetBytes(pXmlString);
- }
Add Comment
Please, Sign In to add comment