Ver código fonte

提取语言标签

LiuQilin 7 anos atrás
pai
commit
f96ee23a00

+ 9 - 0
Assets/Script/Extension/ExtensionString.cs

@@ -21,6 +21,15 @@ public static class ExtensionString
         return str.Remove(startIndex, endIndex - startIndex + 1);
     }
 
+    public static string ReplaceByLength(this string str, int index, int length, string newStr)
+    {
+        str = str.Remove(index, length);
+
+        str = str.Insert(index, newStr);
+
+        return str;
+    }
+
     public static string Replace(this string str, int startIndex, int endIndex, string newStr)
     {
         if (startIndex > endIndex)

+ 2 - 2
Assets/Script/Tool/LabelUtility/LabelUtility.cs

@@ -213,7 +213,7 @@ public class LabelUtility : MonoBehaviour
     {
         string path = AssetDatabase.GetAssetPath(Script);
         string fileStr = File.ReadAllText(path);
-        string pattern = "(?<=Language\\.GetStr\\()[^\\)]*(?=\\))|(?<=MulLanStr\\()[^\\)]*(?=\\))";
+        string pattern = "(?<=Language\\.GetStr\\()[^\\)]+(?=\\))|(?<=MulLanStr\\()[^\\)]+(?=\\))";
         Match match = Regex.Match(fileStr, pattern);
         while (match.Success)
         {
@@ -224,7 +224,7 @@ public class LabelUtility : MonoBehaviour
             }
             else
             {
-                fileStr = fileStr.Replace(match.Index, match.Length, $"LanguageLabel.{strings[0]}__{strings[1]}");
+                fileStr = fileStr.ReplaceByLength(match.Index, match.Length, $"LanguageLabel.{strings[0]}__{strings[1]}");
                 match = Regex.Match(fileStr, pattern);
             }
         }