Example #1
0
    public static void AutoFindCode()
    {
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        // 重置字典数据
        _dictionaryStr = "";
        _txtKey.Clear();
        _txtValue.Clear();
        _valueRepeatCount = 0;
        _keyRepeatCount   = 0;
        _txtPath          = path.Replace("/", "_") + ".txt";

        FindAllCode(path);

        EditorUtility.DisplayProgressBar("本地化", "保存字典到Txt", 1);
        for (var i = 0; i < _txtKey.Count; i++)
        {
            var key   = _txtKey[i];
            var value = _txtValue[i];
            value           = LocalizedUtil.ReplaceNewLine(value);
            _dictionaryStr += (i + 1) + "\t" + key + "\t" + value + "\r\n";
        }
        EditorUtility.ClearProgressBar();
        File.WriteAllText(_txtPath, _dictionaryStr);
        // 输出结果
        Debug.Log("Find " + _txtKey.Count + " Keys.");
        if (_keyRepeatCount > 0 || _valueRepeatCount > 0)
        {
            Debug.Log("Value repeat : " + _valueRepeatCount + " , Key repeat ; " + _keyRepeatCount);
        }
        EditorApplication.SaveAssets();
        AssetDatabase.Refresh();
    }
Example #2
0
        public static TextHelper MarkText(GameObject gameObject, string key)
        {
            if (null != gameObject.GetComponent <TextHelper>())
            {
                Debug.LogError("貌似这个物体已经标记过了" + key);
                return(null);
            }

            Text text = gameObject.GetComponent <Text>();

            if (null == text)
            {
                Debug.LogError("没有在这个物体上找到Text " + key);
                return(null);
            }

            if (null == text.font)
            {
                Debug.LogError("这个物体的Font为空,最好检查一下" + key);
                return(null);
            }
            TextHelper textHelper = gameObject.AddComponent <TextHelper>();

            textHelper.FontPath = LocalizedUtil.GetResourcePath(text.font);
            if (textHelper.FontPath != null)              //避开使用了非Resource下的字体
            {
                text.font = null;
            }

            if (!string.IsNullOrEmpty(text.text) && text.text.ContainChinese() && !string.IsNullOrEmpty(key))
            {
                textHelper.Key = key;
                textHelper.OriginStringValue = LocalizedUtil.ReplaceNewLine(text.text);
                textHelper.OriginStringValue = textHelper.OriginStringValue.Replace("\t", "    ");
                text.text = null;
            }
            else
            {
                //				Debug.Log("没有文字或者文字不包含中文,跳过这个: " + key);
            }
            //			Debug.Log("成功标记 -  " + textHelper.FontPath + "  -  " + gameObject.name);
            return(textHelper);
        }