static void GetMusicRes(bool need = false) { if (allsound == null || need) { List <string> needName = new List <string>(); needName.Add(EMPTY_TIPS); List <string> path = new List <string>(); var guids = AssetDatabase.FindAssets("t:AudioClip"); allsoundPath = new Dictionary <string, string>(); foreach (string guid in guids) { string p = AssetDatabase.GUIDToAssetPath(guid); var im = AssetImporter.GetAtPath(p); if (im != null && !string.IsNullOrEmpty(im.assetBundleName)) { var abFileName = CUtils.GetAssetName(im.assetBundleName); string k = CUtils.GetAssetName(p); if (k.Equals(abFileName)) //assetbundle name equals asset name is music { needName.Add(k); allsoundPath.Add(k, p); } } } allsound = needName; } }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".txt"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { abPath = Path.Combine(outPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, outPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileCrc = CrcCheck.GetLocalFileCrc(abPath); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(outPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileInfo finfo = new FileInfo(abPath); finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }
static public string GetLabelsByPath(string abPath) { string folder = null; var allLabels = HugulaSettingEditor.instance.AssetLabels; foreach (var labelPath in allLabels) { if (abPath.StartsWith(labelPath)) { folder = CUtils.GetAssetName(labelPath).ToLower(); } } return(folder); }
public static string GetLabelsByPath(string abPath) { string folder = null; var allLabels = instance.ExtensionPath; foreach (var labelPath in allLabels) { if (abPath.StartsWith(labelPath + "/")) { folder = CUtils.GetAssetName(labelPath).ToLower(); } } return(folder); }
public static uint CreateStreamingFileManifest(AssetBundleManifest assetBundleManifest) { var allABs = assetBundleManifest.GetAllAssetBundles(); var bundlesWithVariant = assetBundleManifest.GetAllAssetBundlesWithVariant(); var streamingManifest = ScriptableObject.CreateInstance(typeof(FileManifest)) as FileManifest; //读取 bundlesWithVariant var MyVariant = new string[bundlesWithVariant.Length]; for (int i = 0; i < bundlesWithVariant.Length; i++) { var curSplit = bundlesWithVariant[i].Split('.'); MyVariant[i] = bundlesWithVariant[i]; } //读取abinfo List <ABInfo> allABInfos = new List <ABInfo>(); foreach (var abs in allABs) { var abInfo = new ABInfo(abs, 0, 0, 0); var dependencies = assetBundleManifest.GetAllDependencies(abs); abInfo.dependencies = dependencies; allABInfos.Add(abInfo); } //fill data streamingManifest.allAbInfo = allABInfos; streamingManifest.allAssetBundlesWithVariant = bundlesWithVariant; streamingManifest.appNumVersion = CodeVersion.APP_NUMBER; streamingManifest.newAppNumVersion = CodeVersion.APP_NUMBER; streamingManifest.version = CodeVersion.APP_VERSION; //create asset string tmpPath = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); EditorUtils.CheckDirectory(tmpPath); var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string assetPath = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset"; AssetDatabase.CreateAsset(streamingManifest, assetPath); //build assetbundle string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); streamingManifest.WriteToFile("Assets/" + EditorUtils.TmpPath + "BuildStreamingAssetsManifest.txt"); Debug.LogFormat("FileManifest Path = {0}/{1};", CUtils.realStreamingAssetsPath, crc32outfilename); return(0); }
public static void exportLanguage() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Config/Lan") && p.EndsWith(".csv") ).ToArray(); BuildScript.CheckstreamingAssetsPath(); foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + Common.CHECK_ASSETBUNDLE_SUFFIX); BuildScript.BuildABs(new string[] { abPath }, null, abName, BuildAssetBundleOptions.None); Debug.Log(name + " " + abName + " export"); } }
public static void exportLanguage() { string assetPath = "Assets/Lan/"; var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith(assetPath) && p.EndsWith(".csv") ).ToArray(); BuildScript.CheckstreamingAssetsPath(); foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + "." + Common.LANGUAGE_SUFFIX); BuildScript.BuildABs(new string[] { abPath }, null, abName, BuildAssetBundleOptions.CompleteAssets); Debug.Log(name + " " + abName + " export"); } }
static void GetMusicRes(bool need = false) { if (allsound == null || need) { List <string> needName = new List <string>(); needName.Add(EMPTY_TIPS); List <string> path = new List <string>(); var guids = AssetDatabase.FindAssets("t:AudioClip"); allsoundPath = new Dictionary <string, string>(); foreach (string guid in guids) { string p = AssetDatabase.GUIDToAssetPath(guid); string k = CUtils.GetAssetName(p); needName.Add(k); allsoundPath.Add(k, p); } allsound = needName; } }
public static void exportLanguage() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Config/Lan") && p.EndsWith(".csv") ).ToArray(); BuildScript.CheckstreamingAssetsPath(); // BuildScript.ch foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + Common.CHECK_ASSETBUNDLE_SUFFIX); Hugula.BytesAsset bytes = (Hugula.BytesAsset)ScriptableObject.CreateInstance(typeof(Hugula.BytesAsset)); bytes.bytes = File.ReadAllBytes(abPath); string bytesPath = string.Format("Assets/Tmp/{0}.asset", name); AssetDatabase.CreateAsset(bytes, bytesPath); BuildScript.BuildABs(new string[] { bytesPath }, null, abName, SplitPackage.DefaultBuildAssetBundleOptions); Debug.Log(name + " " + abName + " export"); } }
public static void ExportLanguage() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Config/Lan") && p.EndsWith(".csv") ).ToArray(); // EditorUtils.CheckstreamingAssetsPath(); EditorUtils.CheckDirectory("Assets/LuaBytes/lan_bundle"); var dests = new List <string>(); foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + Common.CHECK_ASSETBUNDLE_SUFFIX); Hugula.BytesAsset bytes = (Hugula.BytesAsset)ScriptableObject.CreateInstance(typeof(Hugula.BytesAsset)); bytes.bytes = File.ReadAllBytes(abPath); string bytesPath = string.Format("Assets/LuaBytes/lan_bundle/{0}.asset", name); dests.Add(bytesPath); AssetDatabase.CreateAsset(bytes, bytesPath); // BuildScript.BuildABs(new string[] { bytesPath }, null, abName, SplitPackage.DefaultBuildAssetBundleOptions); // Debug.Log(name + " " + abName + " export"); } AssetDatabase.Refresh(); var setting = AASEditorUtility.LoadAASSetting(); var group = AASEditorUtility.FindGroup(LAN_GROUP_NAME, AASEditorUtility.DefaltGroupSchema[0]); //setting.FindGroup(LUA_GROUP_NAME); AASEditorUtility.ClearGroup(LAN_GROUP_NAME); //清空 foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lan_csv", true); } }
public void CUtilsGetAssetName() { string url, name; url = "extends/ex_ui_bottom.u3d?adsdf=sdfdfa&dafsd"; //lastFileIndex23,lastDotIndex20,lastQueIndex0 name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, "ex_ui_bottom"); url = CUtils.GetRealStreamingAssetsPath() + "/extends/ex_ui_bottom?as=1d2%dfd3"; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, "ex_ui_bottom"); url = "ex_ui_bottom.u3d?as=1d2%dfd3"; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreNotEqual(name, url); url = "ex_ui_bottom"; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, "ex_ui_bottom"); url = CUtils.GetRealStreamingAssetsPath() + "/ex_ui_bottom.u3d"; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, "ex_ui_bottom"); url = CUtils.platform; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, url); url = CUtils.GetRealStreamingAssetsPath() + "/" + CUtils.platform; name = CUtils.GetAssetName(url); Debug.Log(".............." + name); Assert.AreEqual(name, CUtils.platform); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { resOutPath = Path.Combine(outPath, ResFolderName); ExportResources.CheckDirectory(resOutPath); abPath = Path.Combine(resOutPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileSize = 0; uint fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(resOutPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); if (File.Exists(newName)) { File.Delete(newName); } FileInfo finfo = new FileInfo(abPath); if (!firstExists) //如果没有首包 { string destFirst = Path.Combine(outPath, crc32outfilename); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); // finfo.CopyTo(destFirst); } finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }
public static void exportLua() { checkLuaExportPath(); BuildScript.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var childrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = Application.dataPath.Replace("Assets", ""); Debug.Log("luajit path = " + luacPath); string crypName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory DirectoryDelete(Application.dataPath + OutLuaPath); CheckDirectory(Application.dataPath + OutLuaPath); float allLen = childrens.Length; float i = 0; List <string> exportNames = new List <string>(); foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_"); outfilePath = Application.dataPath + OutLuaPath + crypName; exportNames.Add("Assets" + OutLuaPath + crypName); sb.Append(fileName); sb.Append("="); sb.Append(crypName); sb.Append("\n"); #if Nlua || UNITY_IPHONE arg = "-o " + outfilePath + " " + filePath; // luac File.Copy(filePath, outfilePath, true); // source code copy #else arg = "-b " + filePath + " " + outfilePath; //for jit //Debug.Log(arg); //System.Diagnostics.Process.Start(luacPath, arg);//jit File.Copy(filePath, outfilePath, true);// source code copy #endif i++; EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); EditorUtility.DisplayProgressBar(title, "build lua", 0.99f); //u5 打包 CheckDirectory(Path.Combine(Application.dataPath, OutLuaPath)); BuildScript.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle); EditorUtility.DisplayProgressBar(title, "Encrypt lua", 0.99f); //Encrypt string tarName = Application.dataPath + OutLuaPath + "luaout.bytes"; string md5Name = CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME); string realOutPath = Path.Combine(BuildScript.GetOutPutPath(), md5Name); byte[] by = File.ReadAllBytes(tarName); byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV()); File.WriteAllBytes(realOutPath, Encrypt); Debug.Log(realOutPath + " export"); EditorUtility.ClearProgressBar(); }
public static void GenerateAssetBundlesMd5Mapping(string[] allAssets) { string info = "Generate AssetBundles Md5Mapping "; EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0); string speciallyPath = "Assets/Config/Lan/"; string luaPath = "Assets/Lua/"; AssetImporter import = null; float i = 0; float allLen = allAssets.Length; string name = ""; string nameMd5 = ""; //name mapping StringBuilder nameSb = new StringBuilder(); //asset map StringBuilder sb = new StringBuilder(); sb.AppendLine("return {"); foreach (string path in allAssets) { import = AssetImporter.GetAtPath(path); string line = string.Empty; if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false) { string abName = import.assetBundleName; name = CUtils.GetAssetName(path).ToLower(); if (!string.IsNullOrEmpty(import.assetBundleVariant)) { abName = import.assetBundleName + "." + import.assetBundleVariant; // line = "{\"" + import.assetBundleName + "\" = { size = \"" + name + "\", path = \"" + path + "\"}},"; } line = "[\"" + abName + "\"] = { size = " + GetAssetbundleSize(abName) + ", path = \"" + path + "\"},"; sb.AppendLine(line); nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name); if (name.Contains(" ")) { Debug.LogWarning(name + " contains space"); } } else if (import != null && path.Contains(speciallyPath)) { name = CUtils.GetAssetName(path).ToLower(); string md5name = CUtils.GetRightFileName(name) + Common.CHECK_ASSETBUNDLE_SUFFIX; line = "[\"" + md5name + "\"] = { size = " + GetAssetbundleSize(md5name) + ", path = \"" + path + "\"},"; sb.AppendLine(line); nameSb.AppendFormat("{0}={1}\r\n", md5name, name); } else if (import != null && path.Contains(luaPath)) { string luaname = path.Replace(luaPath, "").Replace("\\", ".").Replace("/", "."); string luacname = luaname.Replace(".lua", "").Replace(".", "+"); string luaMd5Name = CUtils.GetRightFileName(luacname); line = "[\"" + luaMd5Name + "\"] = { size = " + GetAssetbundleSize(luaMd5Name + ".bytes") + ", path = \"" + path + "\"},"; sb.AppendLine(line); nameSb.AppendFormat("{0}={1}\r\n", luaMd5Name, luaname); } EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } string[] special = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME }; foreach (string p in special) { name = EditorUtils.GetAssetBundleName(p); nameMd5 = CUtils.GetRightFileName(name); string line = "[\"" + nameMd5 + "\"] ={ size = 0, path = \"" + p + "\" },"; sb.AppendLine(line); nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name); } sb.AppendLine("}"); string tmpPath = Path.Combine(Application.dataPath, EditorUtils.TmpPath); EditorUtils.CheckDirectory(tmpPath); EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + EditorUtils.TmpPath + "Md5Mapping.txt", 0.99f); string outPath = Path.Combine(tmpPath, "md5_asset_mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } outPath = Path.Combine(tmpPath, "md5_name_mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(nameSb.ToString()); } EditorUtility.ClearProgressBar(); Debug.Log(info + " Complete! Assets/" + EditorUtils.TmpPath + "md5_asset_mapping.txt"); }
public static void doExportLua(string[] childrens) { BuildScript.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = CurrentRootFolder; //Application.dataPath.Replace("Assets", ""); string crypName = "", crypEditorName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory if (checkChildrens.Length == childrens.Length) { DirectoryDelete(OutLuaPath); } CheckDirectory(OutLuaPath); float allLen = childrens.Length; float i = 0; System.Diagnostics.Process luaProccess = new System.Diagnostics.Process(); luaProccess.StartInfo.CreateNoWindow = true; luaProccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luaProccess.StartInfo.FileName = luacPath; System.Diagnostics.Process luajit32Proccess = new System.Diagnostics.Process(); luajit32Proccess.StartInfo.CreateNoWindow = true; luajit32Proccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luajit32Proccess.StartInfo.FileName = luajit32Path; luajit32Proccess.StartInfo.WorkingDirectory = luaWorkingPath; System.Diagnostics.Process luajit64Proccess = new System.Diagnostics.Process(); luajit64Proccess.StartInfo.CreateNoWindow = true; luajit64Proccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luajit64Proccess.StartInfo.FileName = luajit64Path; luajit64Proccess.StartInfo.WorkingDirectory = luaWorkingPath; Debug.Log("luajit32Path:" + luajit32Path); Debug.Log("luajit64Path:" + luajit64Path); Debug.Log("luacPath:" + luacPath); string streamingAssetsPath = OutLuaBytesPath; //Path.Combine(CurrentRootFolder, LuaTmpPath); DirectoryDelete(streamingAssetsPath); CheckDirectory(streamingAssetsPath); Debug.Log(streamingAssetsPath); luaProccess.StartInfo.WorkingDirectory = luaWorkingPath; foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", ".bytes").Replace("\\", "+").Replace("/", "+"); crypEditorName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "+").Replace("/", "+"); if (!string.IsNullOrEmpty(luajit32Path))// luajit32 { string override_name = CUtils.GetRightFileName(crypName); string override_lua = Path.Combine(streamingAssetsPath, override_name); arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); luajit32Proccess.StartInfo.Arguments = arg; luajit32Proccess.Start(); luajit32Proccess.WaitForExit(); sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luajit64Path)) //luajit64 { string crypName_64 = CUtils.InsertAssetBundleName(crypName, "_64"); string override_name = CUtils.GetRightFileName(crypName_64); string override_lua = Path.Combine(streamingAssetsPath, override_name); arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); luajit64Proccess.StartInfo.Arguments = arg; luajit64Proccess.Start(); luajit64Proccess.WaitForExit(); sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luacPath)) //for editor { string override_name = CUtils.GetRightFileName(crypEditorName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64")); string override_lua = Path.Combine(OutLuaPath, override_name); #if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN arg = "-o " + override_lua + " " + filePath; //for lua #else arg = "-b " + filePath + " " + override_lua; //for jit #endif // Debug.Log(arg); luaProccess.StartInfo.Arguments = arg; luaProccess.Start(); luaProccess.WaitForExit(); sb.AppendLine("[\"" + crypEditorName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } i++; EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(100); //out md5 mapping file string tmpPath = BuildScript.GetAssetTmpPath(); ExportResources.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); }
private static IEnumerator LoadMessageBox(MessageBoxInfo m_messageBoxInfo) { #if MESSAGEBOX_DEBUG Debug.LogFormat("LoadMessageBox .LoadAssetCoroutine {0} ,frame={1} ", m_messageBoxInfo, Time.frameCount); #endif var req = ResourcesLoader.LoadAssetCoroutine(CUtils.GetRightFileName(MESSAGEBOX_ABNAME), CUtils.GetAssetName(MESSAGEBOX_ABNAME), typeof(GameObject), int.MaxValue); yield return(req); #if MESSAGEBOX_DEBUG Debug.LogFormat("LoadMessageBox LoadAssetCoroutine is done {0},frame={1} ", req, Time.frameCount); #endif var obj = (GameObject)req.data; #if MESSAGEBOX_DEBUG Debug.LogFormat("LoadMessageBox obj req.GetAsset<GameObject> {0} ,frame={1} ", obj, Time.frameCount); #endif var ins = GameObject.Instantiate(obj); m_messageBox = ins.GetComponent <MessageBox> (); m_isloading = false; DontDestroyOnLoad(ins); m_messageBox.ShowContent(m_messageBoxInfo.text, m_messageBoxInfo.caption, m_messageBoxInfo.btns); }
private static IEnumerator LoadMessageBox() { var req = ResourcesLoader.LoadAssetCoroutine(CUtils.GetRightFileName(MESSAGEBOX_ABNAME), CUtils.GetAssetName(MESSAGEBOX_ABNAME), typeof(GameObject), int.MaxValue); yield return(req); var obj = req.GetAsset <GameObject>(); var ins = GameObject.Instantiate(obj); var msgbox = ins.GetComponent <MessageBox>(); SetContent(msgbox, m_messageBoxInfo); }
public static void GenerateAssetBundlesUpdateFile(string[] allBundles) { string title = "Generate Update File "; string info = "Compute crc32"; EditorUtility.DisplayProgressBar(title, info, 0.1f); #region 读取首包 CrcCheck.Clear(); bool firstExists = false; DirectoryInfo firstDir = new DirectoryInfo(Application.dataPath); string firstPath = Path.Combine(firstDir.Parent.Parent.FullName, Common.FirstOutPath); string readPath = Path.Combine(firstPath, CUtils.GetAssetPath("")); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; TextAsset ta = ab.LoadAllAssets <TextAsset>()[0]; //ta.text Debug.Log(ta); string context = ta.text; string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); CrcCheck.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value)); } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } ab.Unload(true); firstExists = true; } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); #endregion #region 生成校验列表 Dictionary <string, uint> updateList = new Dictionary <string, uint>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("return {"); var selected = string.Empty; float i = 0; float allLen = allBundles.Length; //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); foreach (var str in allBundles) { string url = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str); uint outCrc = 0; Debug.Log(str); string abName = str.Replace("\\", "/"); string key = CUtils.GetAssetBundleName(abName); if (!ignore.ContainsKey(key) && CrcCheck.CheckLocalFileWeakCrc(url, out outCrc) == false) //如果不一致需要更新 { updateList.Add(abName, outCrc); //记录导出记录 sb.AppendLine("[\"" + key + "\"] = " + outCrc + ","); } EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } sb.AppendLine("}"); //Debug.Log (sb.ToString ()); CrcCheck.Clear(); //输出到临时目录 var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = Path.Combine(Application.dataPath, TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate file list", "write file to " + assetPath, 0.99f); string outPath = Path.Combine(tmpPath, crc32filename + ".txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); //(fileCrc32ListName + ".u3d"); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); string topath = Path.Combine(GetOutPutPath(), crc32outfilename); Debug.Log(info + " assetbunle build complate! " + topath); #endregion #region 生成版本号 //生成版本号码 string crc32Path = "file://" + Path.Combine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); //CUtils.GetAssetFullPath (fileCrc32ListName+".u3d"); WWW loaderVer = new WWW(crc32Path); if (!string.IsNullOrEmpty(loaderVer.error)) { Debug.LogError(loaderVer.error); return; } uint crcVer = Crc32.Compute(loaderVer.bytes); loaderVer.Dispose(); tmpPath = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath("")); outPath = Path.Combine(tmpPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME)); Debug.Log("verion to path=" + outPath); //json 化version{ code,crc32,version} StringBuilder verJson = new StringBuilder(); verJson.Append("{"); verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ","); verJson.Append(@"""crc32"":" + crcVer.ToString() + ","); verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ""); verJson.Append("}"); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(verJson.ToString()); } Debug.Log(info + " Complete! ver=" + crcVer.ToString() + " path " + outPath); BuildScript.BuildAssetBundles(); #endregion #region copy更新文件导出 if (updateList.Count > 0) { info = "copy updated file "; string updateOutPath = Path.Combine(firstPath, CUtils.GetAssetPath("") + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm")); DirectoryInfo outDic = new DirectoryInfo(updateOutPath); if (outDic.Exists) { outDic.Delete(); } outDic.Create(); if (!firstExists) { updateList.Clear(); //如果没有首包,只导出校验文件。 } updateList.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), 0); updateList.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), crcVer); string sourcePath; string outfilePath; i = 1; allLen = updateList.Count; string key = ""; foreach (var k in updateList) { key = CUtils.GetAssetBundleName(k.Key); sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key); if (k.Value != 0) { if (key.Equals(CUtils.platformFloder)) { key = key + "_" + k.Value.ToString() + "." + Common.ASSETBUNDLE_SUFFIX; } else { key = CUtils.InsertAssetBundleName(key, "_" + k.Value.ToString());// } } outfilePath = Path.Combine(updateOutPath, key); FileHelper.CheckCreateFilePathDirectory(outfilePath); File.Copy(sourcePath, outfilePath, true);// source code copy EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); } #endregion EditorUtility.ClearProgressBar(); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(FileManifest sb, string fileListName, bool firstExists = false, bool copyToResFolder = false) { sb.appNumVersion = CodeVersion.APP_NUMBER; var crc32filename = CUtils.GetAssetName(fileListName); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); AssetDatabase.CreateAsset(sb, assetPath); string crc32outfilename = CUtils.GetRightFileName(fileListName); // Debug.Log("write to path=" + outPath); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy crc list FileInfo finfo = new FileInfo(abPath); var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } if (resType == CopyResType.OneResFolder) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 string newName = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } // CrcCheck.Clear(); //copy first crc list if (!firstExists && File.Exists(abPath)) //如果没有首包 copy first package { string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.LogFormat("abpath={0},destFirst={1}:", abPath, destFirst); File.Copy(abPath, destFirst, true); } EditorUtility.ClearProgressBar(); // File.Delete(assetPath); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }
public static void doExportLua(string[] childrens) { EditorUtils.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = CurrentRootFolder; //Application.dataPath.Replace("Assets", ""); string crypName = "", crypEditorName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory if (checkChildrens.Length == childrens.Length) { EditorUtils.DirectoryDelete(OutLuaPath); } EditorUtils.CheckDirectory(OutLuaPath); float allLen = childrens.Length; float i = 0; Debug.Log("luajit32Path:" + luajit32Path); Debug.Log("luajit64Path:" + luajit64Path); Debug.Log("luacPath:" + luacPath); string OutLuaBytesPath = EditorUtils.GetLuaBytesResourcesPath(); string luabytesParentPath = OutLuaBytesPath.Substring(0, OutLuaBytesPath.LastIndexOf("/")); string streamingAssetsPath = Path.Combine(CurrentRootFolder, OutLuaBytesPath); //Path.Combine(CurrentRootFolder, LuaTmpPath); EditorUtils.DirectoryDelete(luabytesParentPath); EditorUtils.CheckDirectory(luabytesParentPath); EditorUtils.CheckDirectory(streamingAssetsPath); Debug.Log(streamingAssetsPath); List <System.Diagnostics.Process> listPc = new List <System.Diagnostics.Process>(); List <string> luabytesAssets32 = new List <string>(); List <string> luabytesAssets64 = new List <string>(); foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", ".bytes").Replace("\\", "+").Replace("/", "+"); crypEditorName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.ASSETBUNDLE_SUFFIX).Replace("\\", "+").Replace("/", "+"); if (!string.IsNullOrEmpty(luajit32Path))// luajit32 { string override_name = CUtils.GetRightFileName(crypName); string override_lua = streamingAssetsPath + "/" + override_name; arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); listPc.Add(CreateProcess(arg, luajit32Path)); luabytesAssets32.Add(Path.Combine(OutLuaBytesPath, override_name)); sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luajit64Path)) //luajit64 { string crypName_64 = CUtils.InsertAssetBundleName(crypName, "_64"); string override_name = CUtils.GetRightFileName(crypName_64); string override_lua = streamingAssetsPath + "/" + override_name; arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); listPc.Add(CreateProcess(arg, luajit64Path)); luabytesAssets64.Add(Path.Combine(OutLuaBytesPath, override_name)); sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luacPath)) //for editor { string override_name = CUtils.GetRightFileName(crypEditorName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64")); string override_lua = OutLuaPath + "/" + override_name; #if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN arg = "-o " + override_lua + " " + filePath; //for lua #else arg = "-b " + filePath + " " + override_lua; //for jit #endif // Debug.Log(arg); listPc.Add(CreateProcess(arg, luacPath)); sb.AppendLine("[\"" + crypEditorName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } i++; // EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } //compile lua int total = listPc.Count; int workThreadCount = System.Environment.ProcessorCount * 2 + 2; int batchCount = (int)System.Math.Ceiling(total / (float)workThreadCount); for (int batchIndex = 0; batchIndex < batchCount; ++batchIndex) { int processIndex; int offset = batchIndex * workThreadCount; for (processIndex = 0; processIndex < workThreadCount; ++processIndex) { int fileIndex = offset + processIndex; if (fileIndex >= total) { break; } var ps = listPc[fileIndex]; ps.Start(); } bool fail = false; fileName = null; string arguments = null; for (int j = offset; j < offset + processIndex; ++j) { var ps = listPc[j]; ps.WaitForExit(); EditorUtility.DisplayProgressBar(title, info + "=>" + j.ToString() + "/" + total.ToString(), j / total); if (ps.ExitCode != 0 && !fail) { fail = true; fileName = ps.StartInfo.FileName; arguments = ps.StartInfo.Arguments; } ps.Dispose(); } if (fail) { throw new System.Exception(string.Format("Luajit Compile Fail.FileName={0},Arg={1}", fileName, arguments)); } } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(100); // AssetDatabase.Refresh(); //all luabytes in one asset // var luaBytesAsset = ScriptableObject.CreateInstance<LuaBytesAsset>(); // foreach (var file in luabytesAssets32) // { // var bytes = File.ReadAllBytes(file); // var fn = CUtils.GetAssetName(file); // luaBytesAsset.GenerateBytes(bytes, fn); // Debug.LogFormat("lua 32 bytes name ={0},len={1}", fn, bytes.Length); // } // string luaAssetPath = Path.Combine(luabytesParentPath, Common.LUA_BUNDLE_NAME_X86 + ".asset"); // AssetDatabase.DeleteAsset(luaAssetPath); // AssetDatabase.CreateAsset(luaBytesAsset, luaAssetPath); // Debug.LogFormat("lua32:{0}", luaAssetPath); // if (luabytesAssets64.Count > 0) // { // var luaBytesAsset64 = ScriptableObject.CreateInstance<LuaBytesAsset>(); // foreach (var file in luabytesAssets64) // { // var bytes = File.ReadAllBytes(file); // var fn = CUtils.GetAssetName(file); // luaBytesAsset.GenerateBytes(bytes, fn); // Debug.LogFormat("lua 64 bytes name ={0},len={1}", fn, bytes.Length); // } // luaAssetPath = Path.Combine(luabytesParentPath, Common.LUA_BUNDLE_NAME_X64 + ".asset"); // AssetDatabase.DeleteAsset(luaAssetPath); // AssetDatabase.CreateAsset(luaBytesAsset64, luaAssetPath); // Debug.LogFormat("lua64:{0}", luaAssetPath); // } //out md5 mapping file string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); }
private static IEnumerator LoadMessageBox() { var req = ResourcesLoader.LoadAssetCoroutine(CUtils.GetRightFileName(MESSAGEBOX_ABNAME), CUtils.GetAssetName(MESSAGEBOX_ABNAME), typeof(GameObject), int.MaxValue); yield return(req); var obj = req.GetAsset <GameObject> (); var ins = GameObject.Instantiate(obj); m_messageBox = ins.GetComponent <MessageBox> (); m_isloading = false; DontDestroyOnLoad(ins); m_messageBox.ShowContent(m_messageBoxInfo.text, m_messageBoxInfo.caption, m_messageBoxInfo.btns); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, bool copyToResFolder = false) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); // Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy first crc list string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); if (!firstExists) //如果没有首包 copy first package { string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); } //copy crc list FileInfo finfo = new FileInfo(abPath); var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } if (resType == CopyResType.OneResFolder) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 string newName = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } CrcCheck.Clear(); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }
public static void doExportLua(string[] childrens, bool android_ab_build = false) { BuildScript.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = CurrentRootFolder; //Application.dataPath.Replace("Assets", ""); string crypName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory if (checkChildrens.Length == childrens.Length) { DirectoryDelete(OutLuaPath); } CheckDirectory(OutLuaPath); float allLen = childrens.Length; float i = 0; System.Diagnostics.Process luaProccess = new System.Diagnostics.Process(); luaProccess.StartInfo.CreateNoWindow = true; luaProccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luaProccess.StartInfo.FileName = luacPath; System.Diagnostics.Process luajit32Proccess = new System.Diagnostics.Process(); luajit32Proccess.StartInfo.CreateNoWindow = true; luajit32Proccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luajit32Proccess.StartInfo.FileName = luajit32Path; luajit32Proccess.StartInfo.WorkingDirectory = luaWorkingPath; System.Diagnostics.Process luajit64Proccess = new System.Diagnostics.Process(); luajit64Proccess.StartInfo.CreateNoWindow = true; luajit64Proccess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; luajit64Proccess.StartInfo.FileName = luajit64Path; luajit64Proccess.StartInfo.WorkingDirectory = luaWorkingPath; Debug.Log("luajit32Path:" + luajit32Path); Debug.Log("luajit64Path:" + luajit64Path); Debug.Log("luacPath:" + luacPath); #if UNITY_ANDROID string streamingAssetsPath = Path.Combine(CurrentRootFolder, LuaTmpPath); DirectoryDelete(streamingAssetsPath); CheckDirectory(streamingAssetsPath); #else string streamingAssetsPath = CUtils.realStreamingAssetsPath; #endif Debug.Log(streamingAssetsPath); luaProccess.StartInfo.WorkingDirectory = luaWorkingPath; List <string> exportNames = new List <string>(); foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "+").Replace("/", "+"); if (!string.IsNullOrEmpty(luajit32Path))// luajit32 { string override_name = CUtils.GetRightFileName(crypName); string override_lua = Path.Combine(streamingAssetsPath, override_name); arg = "-b " + filePath + " " + override_lua; //for jit luajit32Proccess.StartInfo.Arguments = arg; luajit32Proccess.Start(); luajit32Proccess.WaitForExit(); #if UNITY_ANDROID Debug.Log(luajit32Proccess.StartInfo.FileName + " " + arg); exportNames.Add(Path.Combine(LuaTmpPath, override_name)); #endif sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luajit64Path)) //luajit64 { string crypName_64 = CUtils.InsertAssetBundleName(crypName, "_64"); string override_name = CUtils.GetRightFileName(crypName_64); string override_lua = Path.Combine(streamingAssetsPath, override_name); arg = "-b " + filePath + " " + override_lua; //for jit luajit64Proccess.StartInfo.Arguments = arg; luajit64Proccess.Start(); luajit64Proccess.WaitForExit(); sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luacPath)) //for editor { string override_name = CUtils.GetRightFileName(crypName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64")); string override_lua = Path.Combine(OutLuaPath, override_name); #if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN arg = "-o " + override_lua + " " + filePath; //for lua #else arg = "-b " + filePath + " " + override_lua; //for jit #endif luaProccess.StartInfo.Arguments = arg; luaProccess.Start(); luaProccess.WaitForExit(); sb.AppendLine("[\"" + crypName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } i++; EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(100); //AssetDatabase.Refresh(); //out md5 mapping file string tmpPath = BuildScript.GetAssetTmpPath(); ExportResources.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } // #if UNITY_ANDROID if (android_ab_build) { title = "lua bytes to asset"; allLen = exportNames.Count; i = 0; string luaStreamingAssetsPath = "Assets" + CUtils.realStreamingAssetsPath.Replace(Application.dataPath, ""); Debug.Log(luaStreamingAssetsPath); // AssetImporter import = null; List <AssetBundleBuild> abbs = new List <AssetBundleBuild>(); foreach (var luapath in exportNames) { try { byte[] luabytes = File.ReadAllBytes(luapath); string assetName = Path.GetFileName(luapath);//CUtils.GetAssetBundleName(luapath); var bytesAsset = ScriptableObject.CreateInstance <BytesAsset>(); bytesAsset.bytes = luabytes; string assetPath = luapath.Replace("." + Common.LUA_LC_SUFFIX, ".asset"); AssetDatabase.CreateAsset(bytesAsset, assetPath); AssetBundleBuild abb = new AssetBundleBuild(); abb.assetBundleName = assetName; abb.assetNames = new string[] { assetPath }; abbs.Add(abb); i++; EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } catch (System.Exception e) { Debug.LogError(e.ToString()); } } title = "lua asset to assetbundle"; allLen = abbs.Count; i = 0; // foreach (var abb in abbs) // { // BuildScript.BuildABs(abb.assetNames, null, abb.assetBundleName, BuildAssetBundleOptions.None); // i++; // EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); // } title = "build lua assetbundle "; EditorUtility.DisplayProgressBar(title, info + "=>", 1); BuildScript.BuildABs(abbs.ToArray(), null, BuildAssetBundleOptions.None); } #endif EditorUtility.ClearProgressBar(); }
//加载热更新文件 public IEnumerator LoadRomoteFileList(VerionConfig remoteVer) { yield return(null); SetProgressTxt(Localization.Get("main_web_server_crc_list")); //--加载服务器校验列表。") var crc = remoteVer.crc32.ToString(); var asset_name = CUtils.GetAssetName(UPDATED_LIST_NAME); var assetbundleName = asset_name + Common.CHECK_ASSETBUNDLE_SUFFIX; var fileName = CUtils.InsertAssetBundleName(assetbundleName, "_" + crc); var url = CUtils.PathCombine(remoteVer.cdn_host[1], fileName); //server_ver.cdn_host[1] .. "/" .. file_name UnityWebRequest req = UnityWebRequest.Get(url); var async = req.SendWebRequest(); yield return(async); if (req.responseCode == 200) { SetProgressTxt(Localization.Get("main_compare_crc_list")); //校验列表对比中。" var bytes = req.downloadHandler.data; FileHelper.SavePersistentFile(bytes, UPDATED_TEMP_LIST_NAME); //--保存server端临时文件 var ab = LuaHelper.LoadFromMemory(bytes); var romoteManifest = ab.LoadAllAssets() [1] as FileManifest; ab.Unload(false); print("server file list is down"); if (!CUtils.isRelease) { Debug.Log(romoteManifest); Debug.Log(ManifestManager.fileManifest); } //开始加载热更新文件 var change = BackGroundDownload.instance.AddDiffManifestTask(ManifestManager.fileManifest, romoteManifest, OnProgressEvent, OnBackgroundComplete); Debug.Log("need load file size:" + change); if (change > 0) { var is_wifi = Application.internetReachability == UnityEngine.NetworkReachability.ReachableViaLocalAreaNetwork; UnityEngine.Events.UnityAction BeginLoad = () => { BackGroundDownload.instance.alwaysDownLoad = true; BackGroundDownload.instance.loadingCount = 4; BackGroundDownload.instance.Begin(); MessageBox.Destroy(); }; if (is_wifi) { BeginLoad(); } else { var tips = Localization.GetFormat("main_download_from_webserver", string.Format("{0:.00}", change / 1048576)); MessageBox.Show(tips, "", "", BeginLoad); //提示手动下载 } } } else //加载失败重新加载 { yield return(null); var tips = Localization.Get("main_web_server_error"); MessageBox.Show(tips, "", "", () => { StartCoroutine(LoadRomoteFileList(remoteVer)); } ); } }