예제 #1
0
    static UIText GetText(bool fix, int index, string parentName, MyText text)
    {
        LanguageTranslate translate = new LanguageTranslate();
        UIText            uiText    = new UIText()
        {
            Fixed               = fix,
            Index               = index,
            Name                = text.gameObject.name,
            ParentName          = parentName,
            SimplifiedChineses  = new List <string>(),
            TraditionalChineses = new List <string>(),
        };

        if (text.SimplifiedChinese == null || text.SimplifiedChinese.Count == 0)
        {
            string str = text.text.Replace("{", "{").Replace("}", "}");
            uiText.SimplifiedChineses.Add(translate.ConvertChinSimp(str));
            uiText.TraditionalChineses.Add(translate.ConvertChinTrad(str));
        }
        else
        {
            foreach (var chinese in text.SimplifiedChinese)
            {
                string str = chinese.Replace("{", "{").Replace("}", "}");
                uiText.SimplifiedChineses.Add(translate.ConvertChinSimp(str));
                uiText.TraditionalChineses.Add(translate.ConvertChinTrad(str));
            }
        }
        return(uiText);
    }
예제 #2
0
    static void RefreshText(MyText text, ref UIText uiText)
    {
        LanguageTranslate translate = new LanguageTranslate();

        uiText.SimplifiedChineses  = new List <string>();
        uiText.TraditionalChineses = new List <string>();
        if (text.SimplifiedChinese == null || text.SimplifiedChinese.Count == 0)
        {
            string str = text.text.Replace("{", "{").Replace("}", "}");
            uiText.SimplifiedChineses.Add(translate.ConvertChinSimp(str));
            uiText.TraditionalChineses.Add(translate.ConvertChinTrad(str));
        }
        else
        {
            foreach (var chinese in text.SimplifiedChinese)
            {
                string str = chinese.Replace("{", "{").Replace("}", "}");
                uiText.SimplifiedChineses.Add(translate.ConvertChinSimp(str));
                uiText.TraditionalChineses.Add(translate.ConvertChinTrad(str));
            }
        }
    }
예제 #3
0
 static string TextTrans(string str)
 {
     if (HasChinese(str))
     {
         if (_scn)
         {
             return(_languageTranslate.ConvertChinSimp(str));
         }
         else
         {
             return(_languageTranslate.ConvertChinTrad(str));
         }
     }
     return(str);
 }
예제 #4
0
    public static void RefreshText()
    {
        string[]          sdirs       = { "Assets/Art/UIPrefab", "Assets/Editor Default Resources" };
        var               asstIds     = AssetDatabase.FindAssets("t:Prefab", sdirs);
        List <GameObject> gameObjects = new List <GameObject>();

        foreach (var asstId in asstIds)
        {
            string path = AssetDatabase.GUIDToAssetPath(asstId);
            var    pfb  = AssetDatabase.LoadAssetAtPath <GameObject>(path);
            gameObjects.Add(pfb);
        }
        int           i     = 0;
        List <UIText> texts = new List <UIText>();

        foreach (var pfb in gameObjects)
        {
            foreach (var text in pfb.GetComponentsInChildren <MyText>(true))
            {
                bool       exist = false;
                GameObject go    = null;
                foreach (var mono in pfb.GetComponentsInChildren <MonoBehaviour>(true))
                {
                    foreach (var field in mono.GetType().GetFields())
                    {
                        var xx = mono.GetFieldByReflect(field.Name);
                        if (xx.IsNotNull() && xx.GetType() == typeof(MyText))
                        {
                            if (xx.As <MyText>() == text)
                            {
                                go    = mono.gameObject;
                                exist = true;
                                break;
                            }
                        }
                    }
                }
                if (!exist && text.GetComponent("TextAdapt") == null)
                {
                    texts.Add(GetText(true, i, pfb.name, text));
                }
                else
                {
                    texts.Add(GetText(false, i, go?.gameObject.name, text));
                }
                text.Index = i;
                i++;
            }
            try
            {
                PrefabUtility.SavePrefabAsset(pfb);
            }
            catch (Exception e)
            {
                Debug.LogWarning(e.Message);
            }
        }

        //excel文本

        ExcelTool excelTool = new ExcelTool(true);
        PropertyExcelTextManager propertyExcelTextManager = ScriptableObject.CreateInstance <PropertyExcelTextManager>();

        propertyExcelTextManager.PropertyExcelText = excelTool.CreatePropertyExcelTextArrayWithExcel(propertyExcelTextManager);
        List <UIText>     excelTexts = new List <UIText>();
        LanguageTranslate translate  = new LanguageTranslate();

        for (int j = 0; j < propertyExcelTextManager.PropertyExcelText.Length; j++)
        {
            excelTexts.Add(new UIText()
            {
                Fixed              = true,
                Index              = j,
                Name               = DataEncryptManager.StringDecoder(propertyExcelTextManager.PropertyExcelText[j].ConstKey),
                ParentName         = "Excel",
                SimplifiedChineses = new List <string>()
                {
                    translate.ConvertChinSimp(propertyExcelTextManager.PropertyExcelText[j].ConstValue)
                },
                TraditionalChineses = new List <string>()
                {
                    translate.ConvertChinTrad(propertyExcelTextManager.PropertyExcelText[j].ConstValue)
                },
            });
        }
        UITextManager textManager = new UITextManager
        {
            FixedText = texts,
            ExcelText = excelTexts
        };

        AssetDatabase.CreateAsset(textManager, $"{ExcelConfig.assetPath}UITextManager.asset");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }