//[MenuItem("WCTool/AlterAssets")] static void AlterAssets() { string[] uiFiles = AppPackage.GetFiles(new string[] { GameConfigMgr.ms_sDataDir + GameConfigMgr.ms_sDataFolderName + "/" + GameConfigMgr.ms_sUIFolderName + "/" }, new string[] { "*.prefab" }, true); for (int i = 0; i < uiFiles.Length; i++) { GameObject assObj = AssetDatabase.LoadAssetAtPath(uiFiles[i], typeof(GameObject)) as GameObject; Debug.LogWarningFormat("--------- Check GameObject CanvasRenderer: {0}", uiFiles[i]); Component[] coms = assObj.GetComponents(typeof(Component)); if (coms.Length == 2) { if ((coms[0].GetType() == typeof(RectTransform) && coms[1].GetType() == typeof(CanvasRenderer)) || ((coms[0].GetType() == typeof(CanvasRenderer) && coms[1].GetType() == typeof(RectTransform)))) { CanvasRenderer crcom = null; if (coms[0].GetType() == typeof(CanvasRenderer)) { crcom = coms[0] as CanvasRenderer; } else { crcom = coms[1] as CanvasRenderer; } GameObject.DestroyImmediate(crcom, true); Debug.LogWarningFormat("This Node Only Component(CanvasRenderer) {0}", assObj.name); } } RemoveComponent(assObj); } }
public static bool BundleMap() { System.DateTime lastTime = System.DateTime.Now; string sOutDir = AppPackage.AddStamp(ms_sDataOutDir); string[] files = AppPackage.GetFiles(new string[] { ms_sMapDir }, new string[] { "*.unity" }, true); AppPackage.BundleFiles(sOutDir, files, BuildAssetBundleOptions.DeterministicAssetBundle, false); /*// 生成MD5 * Dictionary<string, string> dicMD5 = new Dictionary<string, string>(); * Dictionary<string, int> dicSize = new Dictionary<string, int>(); * string[] fls = GetFiles(new string[] { sOutDir }, new string[] { "*" + GameConfigMgr.ms_sABType }, false); * System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); * for (int i = 0; i < fls.Length; i++) * { * byte[] bt = File.ReadAllBytes(fls[i]); * int nLen = bt.Length; * string sMD5 = System.BitConverter.ToString(md5.ComputeHash(bt)); * string path = fls[i].Substring(sOutDir.Length, fls[i].Length - sOutDir.Length - GameConfigMgr.ms_sABType.Length); * dicMD5.Add(path, sMD5); * dicSize.Add(path, nLen); * File.WriteAllBytes(fls[i] + GameConfigMgr.ms_sMD5Type, System.Text.Encoding.UTF8.GetBytes(sMD5)); * } * md5.Clear();*/ System.TimeSpan costTime = System.DateTime.Now - lastTime; Debug.Log("-->> BundleMap Cost: " + (costTime.Hours * 3600 + costTime.Minutes * 60 + costTime.Seconds).ToString() + "s"); return(true); }
public static bool BundleData() { bool bSuccess = true; System.DateTime lastTime = System.DateTime.Now; string sOutDir = AppPackage.AddStamp(ms_sDataOutDir); BuildAssetBundleOptions theAssetOptions = BuildAssetBundleOptions.ForceRebuildAssetBundle; //theAssetOptions = theAssetOptions | BuildAssetBundleOptions.CompleteAssets; //theAssetOptions = theAssetOptions | BuildAssetBundleOptions.CollectDependencies; theAssetOptions = theAssetOptions | BuildAssetBundleOptions.UncompressedAssetBundle; theAssetOptions = theAssetOptions | BuildAssetBundleOptions.DeterministicAssetBundle; List <string> lstFiles = new List <string>(); string[] mediaFiles = AppPackage.GetFiles(new string[] { ms_sMediaDir }, new string[] { "*.ogg", "*.mp3" }, true); lstFiles.AddRange(mediaFiles); string[] objFiles = AppPackage.GetFiles(new string[] { ms_sObjDir }, new string[] { "*.prefab" }, true); lstFiles.AddRange(objFiles); string[] effectFiles = AppPackage.GetFiles(new string[] { ms_sEffectDir }, new string[] { "*.prefab" }, true); lstFiles.AddRange(effectFiles); string[] charFiles = AppPackage.GetFiles(new string[] { ms_sCharDir }, new string[] { "*.prefab" }, true); lstFiles.AddRange(charFiles); string[] uiFiles = AppPackage.GetFiles(new string[] { ms_sUIDir }, new string[] { "*.prefab", "*.png", "*.jpg", "*.ttf" }, true); lstFiles.AddRange(uiFiles); /*string[] cfgFiles = GetFiles(new string[] { ms_sConfigDir }, new string[] { "*.prefab", "*.json", "*.bytes" }, true); * lstFiles.AddRange(cfgFiles);*/ string[] mapFiles = AppPackage.GetFiles(new string[] { ms_sMapDir }, new string[] { "*.prefab" }, true); lstFiles.AddRange(mapFiles); AppPackage.DeleteABManifest(sOutDir + ms_sMediaDir.ToLower()); AppPackage.DeleteABManifest(sOutDir + ms_sObjDir.ToLower()); AppPackage.DeleteABManifest(sOutDir + ms_sEffectDir.ToLower()); AppPackage.DeleteABManifest(sOutDir + ms_sCharDir.ToLower()); //AppPackage.DeleteABManifest(sOutDir + ms_sConfigDir.ToLower()); AppPackage.DeleteABManifest(sOutDir + ms_sMapDir.ToLower()); AppPackage.DeleteABManifest(null, sOutDir + GameConfigMgr.ms_sABMFileName); string[] depFiles = AssetDatabase.GetDependencies(lstFiles.ToArray()); string[] files = AppPackage.GetMatch(depFiles, new string[] { "^.+\\.ogg$|^.+\\.mp3$|^.+\\.prefab$|^.+\\.png$|^.+\\.jpg$|^.+\\.ttf$|^.+\\.json$|^.+\\.bytes$|^.+\\.renderTexture$" }); AppPackage.BundleFiles(sOutDir, files, theAssetOptions, false); bSuccess &= AppPackage.BackUpABManifest(sOutDir, sOutDir + GameConfigMgr.ms_sABMFileName + GameConfigMgr.ms_sABType); if (!bSuccess) { return(false); } System.TimeSpan costTime = System.DateTime.Now - lastTime; Debug.Log("-->> BundleData Cost: " + (costTime.Hours * 3600 + costTime.Minutes * 60 + costTime.Seconds).ToString() + "s"); return(true); }
static bool LuaToByteCode(string sSrcFileDir, string sDstFileDir, string sGroupName, string[] includePath) { bool bJITExists = File.Exists(ms_sLuaJitToolPath); if (!bJITExists || !Directory.Exists(sSrcFileDir)) { string sJitErr = "no File:" + ms_sLuaJitToolPath; string sLuaErr = "no Path:" + sSrcFileDir; Debug.LogError(bJITExists ? sLuaErr : sJitErr); return(false); } //Debug.Log(sGroupName + ": Lua To CodeByte Start!"); bool bSuccess = true; System.DateTime now = System.DateTime.Now; if (Directory.Exists(sDstFileDir)) { Directory.Delete(sDstFileDir, true); } Directory.CreateDirectory(sDstFileDir); /*string sLuaCsvTmp = Application.dataPath + "/../../LuaCsvBytes/" + sGroupName + "/"; * //Debug.Log("LuaCsvTmp:" + sLuaCsvTmp); * * if (Directory.Exists(sLuaCsvTmp)) * Directory.Delete(sLuaCsvTmp, true); * Directory.CreateDirectory(sLuaCsvTmp);*/ string[] sDirs = { sSrcFileDir }; string[] sPatterns = { "*.lua", "*.csv" }; string[] sFiles = AppPackage.GetFiles(sDirs, sPatterns, false); int nCount = sFiles.Length; for (int i = 0; i < nCount; i++) { if (!IsInlcudePath(sFiles[i], includePath)) { continue; } // 客户端要支持IOS的arm64,所以直接使用源码 string sFilePath = sFiles[i].Replace("\\", "/"); string sFileName = sFilePath.Substring(sSrcFileDir.Length).Replace('/', '.') + ".bytes"; string sDstFile = sDstFileDir + "/" + sFileName; File.Copy(sFilePath, sDstFile, true); /*// 服务端使用luajit,lua文件编译成字节码,csv文件直接拷贝 * string sLSFile = sLuaCsvTmp + sFilePath.Substring(sSrcFileDir.Length); * string sBCDir = sLSFile.Substring(0, sLSFile.LastIndexOf('/')); * if (!Directory.Exists(sBCDir)) * Directory.CreateDirectory(sBCDir); * * if (sFilePath.EndsWith(".lua")) * { * // 调用luajit.exe进程打包Lua文件。1、检查lua代码的语法;2、正式服务端不能使用源码 * System.Diagnostics.Process p = new System.Diagnostics.Process(); * p.StartInfo.FileName = ms_sLuaJitToolPath; * p.StartInfo.Arguments = " -bg " + sFilePath + " " + sLSFile;//LuaJIT的命令 //p.StartInfo.Arguments = " -o " + sDstFile + " " + sFilePath; //LuaC的命令 * p.StartInfo.UseShellExecute = false; * p.StartInfo.RedirectStandardInput = true; * p.StartInfo.RedirectStandardOutput = true; * p.StartInfo.RedirectStandardError = true; * p.StartInfo.CreateNoWindow = true; * * // p.Exited += (object sender, System.EventArgs e) => { p.Close(); }; * p.Start(); * string sErrInfo = p.StandardError.ReadToEnd(); * // string sOutInfo = p.StandardOutput.ReadToEnd(); * // p.StandardInput.WriteLine("exit"); * p.WaitForExit(); * p.Close(); * * if (sErrInfo != null && sErrInfo != "") * { * bSuccess = false; * Debug.LogError(sErrInfo); * } * } * else * { * File.Copy(sFilePath, sLSFile, true); * }*/ float fProgress = i * 1.0f / nCount; EditorUtility.DisplayProgressBar("LuaCsv CodeByte", sFilePath + ": " + fProgress.ToString(), fProgress); // Debug.Log(sFilePath + " => " + sDstFile); } EditorUtility.ClearProgressBar(); System.GC.Collect(); System.TimeSpan disTime = System.DateTime.Now - now; Debug.Log(sSrcFileDir + ": " + nCount.ToString() + " Files To ByteCode! Cost " + (disTime.Hours * 3600 + disTime.Minutes * 60 + disTime.Seconds).ToString()); return(bSuccess); }
public static bool BundleLuaCsv() { System.DateTime lastTime = System.DateTime.Now; string sOutDir = AppPackage.AddStamp(ms_sDataOutDir); string sDataLuaScriptPath = ms_sDataDir + ms_sLuaScriptName; string sDataDesignerPath = ms_sDataDir + ms_sDesignerName; bool bSuccess = true; bSuccess &= AppPackage.LuaToByteCode(ms_sLuaScriptDir, sDataLuaScriptPath, ms_sLuaScriptName, ms_ArrGacLuaCheck); bSuccess &= AppPackage.LuaToByteCode(ms_sDesignerDir, sDataDesignerPath, ms_sDesignerName, new string[] { "/Config/" }); AssetDatabase.Refresh(); if (!bSuccess) { return(false); } BuildAssetBundleOptions theAssetOptions = BuildAssetBundleOptions.ForceRebuildAssetBundle; //theAssetOptions = theAssetOptions | BuildAssetBundleOptions.CompleteAssets; //theAssetOptions = theAssetOptions | BuildAssetBundleOptions.CollectDependencies; theAssetOptions = theAssetOptions | BuildAssetBundleOptions.UncompressedAssetBundle; theAssetOptions = theAssetOptions | BuildAssetBundleOptions.DeterministicAssetBundle; // Lua Handle AppPackage.DeleteABManifest(sOutDir + ms_sLuaScriptName.ToLower(), sOutDir + GameConfigMgr.ms_sLuaMFileName); string[] luaFilesList = AppPackage.GetFiles(new string[] { sDataLuaScriptPath }, new string[] { "*.bytes" }, true); AppPackage.BundleFiles(sOutDir, luaFilesList, theAssetOptions, false); bSuccess &= AppPackage.BackUpABManifest(sOutDir, sOutDir + GameConfigMgr.ms_sLuaMFileName + GameConfigMgr.ms_sABType); if (!bSuccess) { return(false); } // Csv Handle AppPackage.DeleteABManifest(sOutDir + ms_sDesignerName.ToLower(), sOutDir + GameConfigMgr.ms_sCsvMFileName); string[] csvFilesList = AppPackage.GetFiles(new string[] { sDataDesignerPath }, new string[] { "*.bytes" }, true); AppPackage.BundleFiles(sOutDir, csvFilesList, theAssetOptions, false); bSuccess &= AppPackage.BackUpABManifest(sOutDir, sOutDir + GameConfigMgr.ms_sCsvMFileName + GameConfigMgr.ms_sABType); if (!bSuccess) { return(false); } //Clean LuaCsv Temp Files if (Directory.Exists(sDataLuaScriptPath)) { Directory.Delete(sDataLuaScriptPath, true); File.Delete(sDataLuaScriptPath + ms_sMetaExt); } if (Directory.Exists(sDataDesignerPath)) { Directory.Delete(sDataDesignerPath, true); File.Delete(sDataDesignerPath + ms_sMetaExt); } AssetDatabase.Refresh(); System.TimeSpan costTime = System.DateTime.Now - lastTime; Debug.Log("-->> BundleLuaCsv Cost: " + (costTime.Hours * 3600 + costTime.Minutes * 60 + costTime.Seconds).ToString() + "s"); return(true); }