public override string GenerateCode() { object trackedBundleVersionInfo = CreateInstance("TrackedBundleVersionInfo"); if (trackedBundleVersionInfo == null) { if (!BundleVersionChecker.CopyTrackedBundleVersionInfo()) { // doesn't make sense without TrackedBundleVersionInfo return(null); } } int versionInfoIndex = 0; ArrayList history = GetHistoryFromLastVersionObject(); string oldVersionsToAdd = ""; string code = Line(0, "using System.Collections;", 2); code += Line(0, "public class " + className); code += Line(0, "{"); code += Line(1, "public static readonly string bundleIdentifier = \"" + bundleIdentifier + "\";", 2); if (history != null) { foreach (object versionObject in history) { string trackedVersion = GetVersionFromVersionInfoObject(versionObject); string f = FormatVersionConstantNames(trackedVersion); code += Line(1, "public static readonly TrackedBundleVersionInfo " + f + " = new TrackedBundleVersionInfo (\"" + trackedVersion + "\", " + versionInfoIndex + ");"); oldVersionsToAdd += Line(2, "history.Add (" + f + ");"); versionInfoIndex++; } } // Add a constant for the current label too: code += Line(1, "public static readonly TrackedBundleVersionInfo " + FormatVersionConstantNames(bundleVersion) + " = new TrackedBundleVersionInfo (\"" + bundleVersion + "\", " + versionInfoIndex + ");"); code += Line(1, ""); code += Line(1, "public ArrayList history = new ArrayList ();", 2); code += Line(1, "public TrackedBundleVersionInfo " + Current + " = new TrackedBundleVersionInfo (\"" + bundleVersion + "\", " + versionInfoIndex + ");", 2); code += Line(1, "public " + className + "() {"); code += oldVersionsToAdd; code += Line(2, "history.Add (" + Current + ");"); code += Line(1, "}", 2); code += "}"; return(code); }
public static void UpdateBundleVersion() { BundleVersionChecker.UpdateBundleVersion(); }
public override string GenerateCode() { object trackedBundleVersionInfoObject = CreateInstance("TrackedBundleVersionInfo"); if (trackedBundleVersionInfoObject == null) { // we are creating TrackedBundleVersion.cs the very first time if (!BundleVersionChecker.CopyTrackedBundleVersionInfo()) { // doesn't make sense without TrackedBundleVersionInfo return(null); } } int versionInfoIndex = 0; ArrayList history = GetHistoryFromLastVersionObject(); string oldVersionsToAdd = ""; string code = Line(0, "using System.Collections;", 2); code += Line(0, "// GENERATED CODE."); code += Line(0, "public class " + className); code += Line(0, "{"); code += Line(1, "public static readonly string bundleIdentifier = \"" + bundleIdentifier + "\";", 2); string currentVersionInfoName = null; int currentVersionInfoIndex = -1; if (history != null) { foreach (object versionObject in history) { string trackedVersion = GetVersionFromVersionInfoObject(versionObject); string f = string.Format("{0}_{1}", FormatVersionConstantNames(trackedVersion), versionInfoIndex); code += Line(1, "public static readonly TrackedBundleVersionInfo " + f + " = new TrackedBundleVersionInfo (\"" + trackedVersion + "\", " + versionInfoIndex + ");"); oldVersionsToAdd += Line(2, "history.Add (" + f + ");"); if (trackedVersion == bundleVersion) { currentVersionInfoName = f; currentVersionInfoIndex = versionInfoIndex; } versionInfoIndex++; } } if (currentVersionInfoIndex < 0 || currentVersionInfoName == null) { // Add a constant for the current label too: currentVersionInfoName = string.Format("{0}_{1}", FormatVersionConstantNames(bundleVersion), versionInfoIndex); code += Line(1, "public static readonly TrackedBundleVersionInfo " + currentVersionInfoName + " = new TrackedBundleVersionInfo (\"" + bundleVersion + "\", " + versionInfoIndex + ");"); currentVersionInfoIndex = versionInfoIndex; } code += Line(1, ""); code += Line(1, "public static readonly TrackedBundleVersion Instance = new TrackedBundleVersion ();", 2); code += Line(1, "public static TrackedBundleVersionInfo Current { get { return Instance.current; } }", 2); // TODO_kay: Workaround to get current Android bundleVersionCode, provide historic information in the future code += Line(1, "public static int CurrentBuildVersion { get { return " + PlayerSettings.Android.bundleVersionCode + "; } }", 2); code += Line(1, "public ArrayList history = new ArrayList ();", 2); code += Line(1, "public TrackedBundleVersionInfo " + Current + " = " + currentVersionInfoName + ";", 2); code += Line(1, "public " + className + "() {"); code += oldVersionsToAdd; if (currentVersionInfoIndex == versionInfoIndex) { // default case: current version is the most recent so it is not yet contained in history; // after a version number rollback the current entry is already contained in history code += Line(2, "history.Add (" + Current + ");"); } code += Line(1, "}", 2); code += "}"; return(code); }
public static void ExportiPhonePublic(string subBucket = null) { string[] args = System.Environment.GetCommandLineArgs(); if (args == null || args.Length == 0) { return; } Debug.Log("ExportiPhonePublic: " + string.Join(", ", args)); List <string> fileList = new List <string>(); List <string> versionList = new List <string>(); Regex regExp = new Regex(@"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"); foreach (string fileName in args) { if (fileName.EndsWith(".u3d")) { fileList.Add(fileName); } else { if (regExp.IsMatch(fileName)) { string bundleVersionCode = BundleVersionChecker.BundleVersion2Code(fileName); if (!versionList.Contains(bundleVersionCode)) { versionList.Add(bundleVersionCode); } } } } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS); string bundleVersion = args[args.Length - 3]; PlayerSettings.bundleVersion = bundleVersion; PlayerSettings.iOS.buildNumber = args[args.Length - 2]; BundleVersionChecker.UpdateBundleVersion(); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(); AssetDatabase.Refresh(); ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); string folder = args[args.Length - 1]; foreach (string bundleVersionCode in versionList) { string outFolderName = PathUtil.Platform + bundleVersionCode; if (!string.IsNullOrEmpty(subBucket)) { outFolderName = subBucket + "/" + outFolderName; } string strOut = Path.GetFullPath(Path.Combine(folder, outFolderName)); if (Directory.Exists(strOut) == false) { Directory.CreateDirectory(strOut); } Debug.Log("资源导出目录:" + strOut); ExportAssetBundle.GenerateResPublic(bundleVersionCode, strOut, fileList.ToArray()); } }
public static void ExportAndroidLuaPublic(string subBucket = null) { string[] args = System.Environment.GetCommandLineArgs(); if (args == null || args.Length == 0) { return; } Debug.Log(string.Join(",", args)); List <string> fileList = new List <string>(); List <string> versionList = new List <string>(); Regex regExp = new Regex(@"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"); foreach (string fileName in args) { if (fileName.EndsWith(".u3d")) { fileList.Add(fileName); } else { if (regExp.IsMatch(fileName)) { string bundleVersionCode = BundleVersionChecker.BundleVersion2Code(fileName); if (!versionList.Contains(bundleVersionCode)) { versionList.Add(bundleVersionCode); } } } } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); //PlayerSettings.bundleIdentifier = "xin.unwrap.xiami"; string bundleVersion = args[args.Length - 2]; PlayerSettings.bundleVersion = bundleVersion; //PlayerSettings.SetPropertyInt("ScriptingBackend", (int)ScriptingImplementation.IL2CPP, BuildTarget.Android); BundleVersionChecker.UpdateBundleVersion(); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(); AssetDatabase.Refresh(); ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); string folder = args[args.Length - 1]; foreach (string bundleVersionCode in versionList) { string outFolderName = PathUtil.Platform + bundleVersionCode; if (!string.IsNullOrEmpty(subBucket)) { outFolderName = subBucket + "/" + outFolderName; } string strOut = Path.GetFullPath(Path.Combine(folder, outFolderName)); if (Directory.Exists(strOut) == false) { Directory.CreateDirectory(strOut); } Debug.Log("导出目录:" + strOut); ExportAssetBundle.GenerateDataPublic(strOut, fileList.ToArray()); } }
//这里封装了一个简单的通用方法。 static void BulidTarget(string name, string target) { string app_name = name; string target_dir = Application.dataPath + "/TargetAndroid"; string target_name = app_name + ".apk"; BuildTargetGroup targetGroup = BuildTargetGroup.Android; BuildTarget buildTarget = BuildTarget.Android; string applicationPath = Application.dataPath.Replace("/Assets", ""); if (target == "Android") { target_dir = applicationPath + "/TargetAndroid"; targetGroup = BuildTargetGroup.Android; } if (target == "IOS") { target_dir = applicationPath + "/TargetIOS"; target_name = app_name; targetGroup = BuildTargetGroup.iOS; buildTarget = BuildTarget.iOS; } if (target == "Test") { target_dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); targetGroup = BuildTargetGroup.Android; buildTarget = BuildTarget.Android; } //每次build删除之前的残留 if (Directory.Exists(target_dir)) { if (File.Exists(target_name)) { File.Delete(target_name); } } else { Directory.CreateDirectory(target_dir); } //==================这里是比较重要的东西======================= switch (name) { case "QQ": PlayerSettings.applicationIdentifier = "com.game.qq"; PlayerSettings.bundleVersion = "v0.0.1"; PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "QQ"); break; case "UC": PlayerSettings.applicationIdentifier = "com.game.uc"; PlayerSettings.bundleVersion = "v0.0.1"; PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "UC"); break; case "CMCC": PlayerSettings.applicationIdentifier = "com.game.cmcc"; PlayerSettings.bundleVersion = "v0.0.1"; PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "CMCC"); break; case "SocketTest": PlayerSettings.applicationIdentifier = "com.xc.Test"; string version = PlayerSettings.bundleVersion; int ver = int.Parse(version.Split(new string[] { "v0.0." }, StringSplitOptions.RemoveEmptyEntries)[0]); ver++; version = "v0.0." + ver; BundleVersionChecker.CreateNewBuildVersionClassFile(version); PlayerSettings.bundleVersion = version; PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "SanWang"); break; } //==================这里是比较重要的东西======================= //开始Build场景,等待吧~ GenericBuild(SCENES, target_dir + "/" + target_name, targetGroup, buildTarget, BuildOptions.None); }
public void OnPreprocessBuild(BuildReport report) { BundleVersionChecker.RefreshNow(); }