Exemplo n.º 1
0
    static void Init()
    {
        JpCharCheckerWindow jpCharCheckerWindow = (JpCharCheckerWindow)GetWindow <JpCharCheckerWindow>();

        jpCharCheckerWindow.Show();
        initCachedDict();
    }
Exemplo n.º 2
0
        public static void SetLocalizationKey(string assetPath, string localizeCompGUID, string localizeCompFileID)
        {
            ClearConsole();
            string formatedGUID = string.Format("guid: {0},", localizeCompGUID);
            string fullPath     = Path.Combine(Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')), assetPath);

            string[] lines    = System.IO.File.ReadAllLines(fullPath);
            string   fullText = System.IO.File.ReadAllText(fullPath);

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Contains(localizeCompFileID) && lines[i].Contains(localizeCompGUID))
                {
                    while (i < lines.Length)
                    {
                        if (lines[i].Contains("--- !u!"))                           //发现下一个控件时跳出
                        {
                            break;
                        }

                        if (lines[i].Contains("m_Text:") && lines[i].Contains("\""))
                        {
                            string mTextValue = Regex.Unescape(lines[i].Split('\"')[1]);
                            JpCharCheckerWindow.LocalizeDataPair dataPair = JpCharCheckerWindow.GetDataPair(mTextValue);
                            if (dataPair.key != -1)
                            {
                                Debug.LogError("Find : " + dataPair.keyString);
                                //删除掉可能LocalizationKey
                                if (lines[i + 1].Contains("m_LocalizationKey:"))
                                {
                                    lines[i + 1] = string.Empty;
                                }
                                if (lines[i + 2].Contains("m_KeyString:"))
                                {
                                    lines[i + 2] = string.Empty;
                                }
                                string localizationDataFormat = "\n  m_LocalizationKey: {0}\n  m_KeyString: {1}";
                                string localizationDataString = string.Format(localizationDataFormat, dataPair.key, Regex.Escape(dataPair.keyString));
                                lines[i] = lines[i].Insert(lines[i].Length, localizationDataString);
                            }
                            else
                            {
                                Debug.LogErrorFormat("The string [{0}] cannot find the key:", mTextValue);
                            }
                        }
                        i++;
                    }
                }
            }
            string text = string.Join("\n", lines);

            System.IO.File.WriteAllText(fullPath, text);
            AssetDatabase.Refresh();
        }