示例#1
0
    static void ProcessEnums <T>() where T : struct
    {
        if (!typeof(T).IsEnum)
        {
            Debug.LogError("Must Pass Enum Type");
            return;
        }

        int languageIndex = GetEnglishLanguageIndex();

        if (languageIndex == -1)
        {
            return;
        }

        string newTerms = "New Terms:\n";

        T[] enums = (T[])System.Enum.GetValues(typeof(T));
        for (int i = 0; i < enums.Length; i++)
        {
            string   termName = string.Format("{0}/{1}", typeof(T).ToString(), enums[i].ToString());
            TermData termData = LocalizationManager.GetTermData(termName);
            if (termData == null)
            {
                termData = LocalizationManager.Sources[0].AddTerm(termName);
                termData.SetTranslation(languageIndex, enums[i].ToString().SplitIntoWordsByCase());

                newTerms += termName + "\n";
            }
        }

        Debug.Log(newTerms);
    }
示例#2
0
    public static void ProcessAllScripts()
    {
        int languageIndex = GetEnglishLanguageIndex();

        if (languageIndex == -1)
        {
            return;
        }

        string newTerms = "New Terms:\n";

        List <MonoScript> scripts = LoadAllScripts("Assets/Scripts");

        for (int i = 0; i < scripts.Count; i++)
        {
            string pattern = @"LocUtils.Translate\((.*?)\)";

            MatchCollection matchCollection = Regex.Matches(scripts[i].text, pattern);
            foreach (Match m in matchCollection)
            {
                if (!m.Value.Contains('"') || scripts[i].GetClass() == MethodBase.GetCurrentMethod().DeclaringType)
                {
                    continue;
                }

                string termName = m.Value;
                termName = termName.Replace("LocUtils.Translate(\"", "").Replace("\")", "");

//              Debug.Log(scripts[i].name + ": " + termName);

                TermData termData = LocalizationManager.GetTermData(termName);
                if (termData == null)
                {
                    termData = LocalizationManager.Sources[0].AddTerm(termName);
                    termData.SetTranslation(languageIndex, termName);

                    newTerms += termName + "\n";
                }
            }
        }

        Debug.Log(newTerms);
        AssetDatabase.SaveAssets();
    }
示例#3
0
    public static void ProcessAllPrefabs()
    {
        int languageIndex = GetEnglishLanguageIndex();

        if (languageIndex == -1)
        {
            return;
        }

        List <GameObject> allPrefabs = PrefabLoader.LoadAllPrefabs("Assets/Prefabs");

        foreach (GameObject prefab in allPrefabs)
        {
            MonoBehaviour[] monoBehaviours = prefab.GetComponentsInChildren <MonoBehaviour>();
            foreach (MonoBehaviour mb in monoBehaviours)
            {
                if (mb == null)
                {
                    Debug.Log(prefab.name + " referencing dead component", prefab);
                    continue;
                }

                string chunks = string.Empty;

                SerializedObject   mbSO     = new SerializedObject(mb);
                SerializedProperty propIter = mbSO.GetIterator();
                propIter.Next(true);

                bool anyChanged = false;

                while (propIter.Next(true))
                {
                    if (propIter.type == typeof(DialogueChunk).ToString() && propIter.isArray)
                    {
                        for (int j = 0; j < propIter.arraySize; j++)
                        {
                            SerializedProperty chunkProp        = propIter.GetArrayElementAtIndex(j);
                            SerializedProperty dialogueTermProp = chunkProp.FindPropertyRelative("dialogueTerm");

                            string displayPropPath = chunkProp.propertyPath
                                                     .Replace("_", "")
                                                     .Replace(".Array.data", "")
                                                     .Replace("[", "-")
                                                     .Replace("]", "");

                            displayPropPath = char.ToUpper(displayPropPath[0]) + displayPropPath.Substring(1);

                            string   termName = string.Format("Dialogue/{0}_{1}", prefab.name, displayPropPath);
                            TermData termData = LocalizationManager.GetTermData(termName);
                            if (termData == null)
                            {
                                termData = LocalizationManager.Sources[0].AddTerm(termName);
                                chunks  += termName + "\n";
                            }

                            string prevTranslation = termData.GetTranslation(languageIndex);
                            string newTranslation  = chunkProp.FindPropertyRelative("dialogue").stringValue;

                            if (prevTranslation == string.Empty ||
                                newTranslation != prevTranslation ||
                                dialogueTermProp.stringValue != termName)
                            {
                                termData.SetTranslation(languageIndex, newTranslation);
                                dialogueTermProp.stringValue = termName;
                                anyChanged = true;
                            }
                        }
                    }
                }

                if (anyChanged)
                {
                    mbSO.ApplyModifiedProperties();
                    EditorUtility.SetDirty(LocalizationManager.Sources[0]);
                }

                if (chunks != string.Empty)
                {
                    Debug.Log(prefab.name + ":\n" + chunks);
                }
            }
        }

        AssetDatabase.SaveAssets();
    }