Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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;
        }
Example #4
0
 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);
 }
Example #5
0
    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();
        //}
    }
Example #6
0
    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));
        }
    }