private void GenerateGameEvent() { string filePath = Application.dataPath + GameEventPath; if (File.Exists(filePath)) { string content = File.ReadAllText(filePath); Match match = Regex.Match(content, GameEventReplace); string matchValue = match.Value; string oldGenerateEvent = match.Groups["STR"].Value; StringBuilder newGenerateEvent = new StringBuilder("#region 工具迁移事件"); newGenerateEvent.AppendLine(oldGenerateEvent); GenerateGameEventModule(newGenerateEvent); newGenerateEvent.Append("\t#endregion 工具迁移事件"); content = content.Replace(matchValue, newGenerateEvent.ToString()); File.WriteAllText(filePath, content); } else { GameDebuger.LogError("CanNotFindPath: " + filePath); } }
private List <string> GetBtnComponentList(bool pNeedTip = true) { ; List <string> tBtnComponentList = null; if (null != _exportInfoDic && _exportInfoDic.Count > 0) { var tEnum = _exportInfoDic.GetEnumerator(); UIComponentInfo tUIComponentInfo = null; while (tEnum.MoveNext()) { tUIComponentInfo = tEnum.Current.Value; if (null != tUIComponentInfo && tUIComponentInfo.comType == "Button") { if (null == tBtnComponentList) { tBtnComponentList = new List <string>(); } tBtnComponentList.Add(tUIComponentInfo.memberName); } } } if ((null == tBtnComponentList || tBtnComponentList.Count <= 0) && pNeedTip) { GameDebuger.Log("界面中没有按钮组件,不设置按钮相关事件监听和回掉。"); } return(tBtnComponentList); }
private static bool ReplaceWithRegexForTargetPathFileList(List <string> pAllCodesFileList, Regex pRegexToMatch, string pRegexToReplaceTo, string pTip = "代码操作", Regex pInvalidContentRegex = null) { if (null == pAllCodesFileList || pAllCodesFileList.Count <= 0) { GameDebuger.LogError("检测没有继承MonolessViewController或MonoViewController的Controller失败,其他文件列表为空!"); return(false); } string tFileFullPath = string.Empty; for (int tCounter = 0, tLen = pAllCodesFileList.Count; tCounter < tLen; tCounter++) { tFileFullPath = pAllCodesFileList[tCounter]; UnityEditor.EditorUtility.DisplayCancelableProgressBar(pTip, string.Format("{0}:{1}", pTip, tFileFullPath), (float)tCounter / (float)tLen); try { ReplaceWithRegexForTargetPathFile(tFileFullPath, pRegexToMatch, pRegexToReplaceTo, pInvalidContentRegex); } catch (Exception e) { GameDebuger.LogError(string.Format("{0} 异常,tFileFullPath:{1},错误码:{2}", pTip, tFileFullPath, e.Message)); } } UnityEditor.EditorUtility.ClearProgressBar(); return(true); }
public static string GetUniqueFilePathByAssetDatabase(string pFileNameWithOutExtension, string pFilePathDir = null, string pTypeName = "script") { if (string.IsNullOrEmpty(pFileNameWithOutExtension)) { return(null); } // if (pFileNameWithOutExtension == "SkillCellController") // GameDebuger.LogError("来了!"); List <string> tFiles = GetAllFilesInDirectory(pFilePathDir, ".cs", @"\.meta", @"/" + pFileNameWithOutExtension + @".cs"); if (null == tFiles || tFiles.Count != 1) { GameDebuger.LogError(string.Format("文件查找失败,pFileNameWithOutExtension:{0},pFilePathDir:{1} !", pFileNameWithOutExtension, pFilePathDir)); return(null); } return(tFiles[0]); // string[] tGUIDs = UnityEditor.AssetDatabase.FindAssets(string.Format("t:script {0}", pFileNameWithOutExtension), pFilePathDir); // if (null == tGUIDs || tGUIDs.Length <= 0) // { // GameDebuger.LogError(string.Format("通过 AssetDatabase 查找唯一资源 {0} 失败!", pFileNameWithOutExtension)); // return null; // } // int tLen = tGUIDs.Length; // string matPath = null; // for (int tCounter = 0; tCounter < tLen; tCounter++) // { // matPath = RefactorConst.PROJECT_PATH + AssetDatabase.GUIDToAssetPath(tGUIDs[tCounter]); // if (Path.GetFileNameWithoutExtension(matPath) != pFileNameWithOutExtension) // continue; // return matPath; // } // return null; }
private void UpdateFileContent(string pFilePath) { if (!string.IsNullOrEmpty(pFilePath) && File.Exists(pFilePath)) { string tFileContent = File.ReadAllText(pFilePath); if (!string.IsNullOrEmpty(tFileContent)) { tFileContent = tFileContent.Replace(KEY_WORD_MODULE_NAME, mModuleName).Replace(KEY_WORD_AUTHOR, mAuthor).Replace(KEY_WORD_CREATED_TIME, mCreateTime); File.WriteAllText(pFilePath, tFileContent); GameDebuger.Log(string.Format("Generate File {0} success !", pFilePath)); } } }
public static string ExcuteRegexReplace(Regex pRegexToMatch, string pRegexToReplaceTo, string pFileContent, string pTip = "") { if (!pRegexToMatch.IsMatch(pFileContent)) { if (string.IsNullOrEmpty(pTip)) { return(pFileContent); } GameDebuger.LogError(pTip); return(pFileContent); } pFileContent = pRegexToMatch.Replace(pFileContent, pRegexToReplaceTo); return(pFileContent); }
private void GenerateFile(string pTemplatePath, string pCreatedFilePath) { if (File.Exists(pTemplatePath)) { if (!File.Exists(pCreatedFilePath)) { Refactor.RefactorUtils.CreateFileDirectory(pCreatedFilePath, false); FileUtil.CopyFileOrDirectory(pTemplatePath, pCreatedFilePath); UpdateFileContent(pCreatedFilePath); } else { GameDebuger.Log(string.Format("Generate File canceled for file is already exists. File Path:{0}", pCreatedFilePath)); } } }
private string GenerateFileByCopyFromTempDirToModuleDir(string pTemplateFileName) { var tFilePath = string.Empty; if (string.IsNullOrEmpty(mModuleFileDir)) { GameDebuger.LogWarning(string.Format("GenerateFileByCopyFromTempDirToModuleDir failed for mModuleFileDir is null, pTemplateFileName:{0}", pTemplateFileName)); } else { var tTemplateFilePath = string.Format("{0}{1}Module/{2}", Refactor.RefactorConst.PROJECT_PATH + VIEWCODE_GENERATED_PATH, KEY_WORD_MODULE_NAME, pTemplateFileName); tFilePath = string.Format("{0}{1}/{2}", mModuleFileDir, string.Empty, pTemplateFileName.Replace(KEY_WORD_MODULE_NAME, mModuleName)); GenerateFile(tTemplateFilePath, tFilePath); } return(tFilePath); }
public static void OneKeyBuildAll(bool pForMobile, bool commandLine = false) { Debug.Log("Begin JSB OneKeyBuildAllStep1"); cmd = commandLine; try { if (!cmd && EditorUtility.DisplayDialogComplex("TIP", "One Key Build Js Code,This may take about 20 MIN. Are you sure to continue ?", "OK", "CANCEL", String.Empty) != 0) { return; } if (EditorApplication.isCompiling) { const string tips = "Please wait EditorApplication Compiling"; if (!cmd) { EditorUtility.DisplayDialog("TIP", tips, "OK"); } return; } if (!cmd && CheckTempJSBCodeRoot()) { CodeManagerTool.RevertUnUsedMonoCode(); } mOneKeyBuildAll = true; EditorUtility.DisplayCancelableProgressBar("OneKeyBuildAll", "GenerateJSCSBindings", 0.2f); CSGenerator.GenerateJSCSBindings(mOneKeyBuildAll); EditorUtility.DisplayCancelableProgressBar("OneKeyBuildAll", "GenerateJsTypeInfo", 0.4f); GenerateJsTypeInfo(); JsonData jsonData = new JsonData(); jsonData["pForMobile"] = pForMobile; jsonData["cmd"] = cmd; EditorPrefs.SetString(GetPrefsKey(), jsonData.ToJson()); } catch (Exception e) { GameDebuger.LogError(string.Format("OneKeyBuildAll failed , e:{0}", e)); EditorUtility.ClearProgressBar(); } //finally //{ // EditorUtility.ClearProgressBar(); //} }
public static void LoadPathList() { string sFileContent = File.ReadAllText(_savePathFile); string[] strs = sFileContent.Split('\n'); GameDebuger.Log(sFileContent); foreach (var str in strs) { string[] list = str.Split(' '); GameDebuger.Log(str + "\n"); if (list.Length != 2) { continue; } view2ScriptPath[list[0]] = list[1].Replace("\\", "/"); } }
public static bool UpdateProxyFileFromStaticToInstance(string pProxyFileFullPath) { if (File.Exists(pProxyFileFullPath)) { string tFileContent = File.ReadAllText(pProxyFileFullPath); if (!string.IsNullOrEmpty(tFileContent)) { tFileContent = tFileContent.Replace("public static ", "public "); if (!string.IsNullOrEmpty(tFileContent)) { File.WriteAllText(pProxyFileFullPath, tFileContent); GameDebuger.Log(string.Format(" Proxy 内容已更新。pProxyFileFullPath:{0}", pProxyFileFullPath)); return(true); } } } return(false); }
//检索文档中模板代码段,复制之并替换模块名字为目标名字 private static void UpdateFileCopyCodeBetweenKeyWord(string pFilePath, string pPrefixKeyWord, string pInValidKeyWord = "", string pModuleName = KEY_WORD_MODULE_NAME, string pAuthor = KEY_WORD_AUTHOR, string pCreateTime = KEY_WORD_CREATED_TIME) { if (string.IsNullOrEmpty(pModuleName) || pModuleName == KEY_WORD_MODULE_NAME) { return; } if (!string.IsNullOrEmpty(pFilePath) && File.Exists(pFilePath)) { string tFileContent = File.ReadAllText(pFilePath); if (tFileContent.IndexOf(pInValidKeyWord) != -1) { GameDebuger.Log(string.Format("文件更新取消,存在禁止关键词,pModuleName:{0},pInValidKeyWord:{1}", pModuleName, pInValidKeyWord)); return; } UpdateFileContentCopyCodeBetweenKeyWord(ref tFileContent, pPrefixKeyWord, 0, pModuleName, pAuthor, pCreateTime); File.WriteAllText(pFilePath, tFileContent); } }
public void LoadUIViewByScript() { var _path = GetPathNameFromConfig(); if (string.IsNullOrEmpty(_path) || !File.Exists(_path)) { return; } var sFileContent = File.ReadAllText(_path); if (string.IsNullOrEmpty(sFileContent)) { return; } var contentMat = Regex.Match(sFileContent, @"protected override void InitElementBinding\s*\(\)[\n\s]*\{[\n\s]*([\n\s\S]+?)[\n\s]*\}"); if (!contentMat.Success) { Debug.LogError("匹配出错!"); return; } var sContent = contentMat.Groups[1].Value; var sLines = sContent.Split('\n'); var pat1 = @"(\S+) = root\.FindScript<(\S+)>\(""(\S+)?""\)"; var pat2 = @"(\S+) = root\.FindTrans\(""(\S+)?""\);"; var pat3 = @"(\S+) = root\.FindGameObject\(""(\S+)?""\);"; var pat4 = @"(\S+) = root\.GetComponent<(\S+)>\(\)"; var pat5 = @"(\S+) = root\.Find\(""(\S+)""\)(\S*);"; var comPattern = @"\.GetComponent<(\S+)>\(\)"; Match mat; foreach (string sLine in sLines) { if (string.IsNullOrEmpty(sLine) || sLine.Contains("var root = this.gameObject")) { continue; } var name = string.Empty; var type = string.Empty; var path = string.Empty; mat = Regex.Match(sLine, pat1); if (mat.Success) { name = mat.Groups[1].Value; type = mat.Groups[2].Value; path = mat.Groups[3].Value; } else if ((mat = Regex.Match(sLine, pat2)).Success) { name = mat.Groups[1].Value; path = mat.Groups[2].Value; type = "Transform"; } else if ((mat = Regex.Match(sLine, pat3)).Success) { name = mat.Groups[1].Value; path = mat.Groups[2].Value; type = "GameObject"; } else if ((mat = Regex.Match(sLine, pat4)).Success) { name = mat.Groups[1].Value; type = mat.Groups[2].Value; path = ""; } else if ((mat = Regex.Match(sLine, pat5)).Success) { name = mat.Groups[1].Value; path = mat.Groups[2].Value; type = mat.Groups[3].Value; if (string.IsNullOrEmpty(type)) { type = "Transform"; } else if (type.EndsWith("gameObject")) { type = "GameObject"; } else if (type.Contains("GetComponent")) { var comMat = Regex.Match(sLine, comPattern); if (comMat == null || !comMat.Success) { Debug.LogError("未匹配的类型"); } type = comMat.Groups[1].Value; } else { Debug.LogError("未匹配的类型:" + sLine); } } else { GameDebuger.LogError(" 匹配出错:" + sLine); continue; } if (path.Contains(" ")) { GameDebuger.LogError(string.Format("路径中有空格!path:{0}", path)); path = path.Replace(" ", string.Empty); } if (string.IsNullOrEmpty(name)) { continue; } var item = new UIComponentInfo(UIPrefabRoot, name, path, type); if (!_exportInfoDic.ContainsKey(item.uid)) { _exportInfoDic.Add(item.uid, item); } var itemTrans = UIPrefabRoot.Find(item.path); _validatedInfoDic.Add(item.uid, (itemTrans != null)); } }
public static void ShowNotificationStr(this EditorWindow pEditorWindow, string pMessage) { GameDebuger.Log("ShowNotification:" + pMessage); pEditorWindow.ShowNotification(new GUIContent(pMessage)); }