Exemplo n.º 1
0
    public static void createTranslationAsset(ref TranslatedText translation, string path, string directory, string defaultString)
    {
        //create the directory where the prefab will exists if not created
        if (!Directory.Exists(directory))
        {
            Directory.CreateDirectory(directory);
        }

        //create an empty gameobject but make it inactive
        GameObject go = new GameObject();

        go.AddComponent <TranslatedText>();
        go.active = false;

        //create an empty prefab in the specified path and copy the quest component to the prefab
        Object     p      = PrefabUtility.CreateEmptyPrefab(path);
        GameObject prefab = EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);

        //destroy the gameobject
        GameObject.DestroyImmediate(go);

        //link translation dialog to translation
        translation = prefab.GetComponent <TranslatedText>();
        translation.setText(TranslatedText.LANGUAGES.ENGLISH, defaultString);
        EditorUtility.SetDirty(prefab);
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        TranslatedText text = (TranslatedText)target;

        GUILayout.Label("Languages", EditorStyles.boldLabel);

        for (int i = 0; i < TranslatedText.LANGUAGES_str.Length; i++)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(TranslatedText.LANGUAGES_str[i]);
            text.setText((TranslatedText.LANGUAGES)i, EditorGUILayout.TextArea(text.getText((TranslatedText.LANGUAGES)i), GUILayout.Height(64)));
            if (GUI.changed)
            {
                EditorUtility.SetDirty(text);
            }
            GUILayout.EndHorizontal();
        }
    }
Exemplo n.º 3
0
    static void ImportTranslations()
    {
        string path   = EditorUtility.OpenFilePanel("Load Translation file(csv)", "", "csv");
        int    amount = 0;

        using (StreamReader sr = new StreamReader(path))
        {
            string[] headers = ParseCSVLine(sr.ReadLine());
            while (sr.Peek() != -1)
            {
                string[] values = ParseCSVLine(sr.ReadLine());

                string resName = values[0];

                resName = resName.Substring("Assets/Resources/".Length);
                resName = resName.Substring(0, resName.Length - ".prefab".Length);

                TranslatedText text = Resources.Load(resName, typeof(TranslatedText)) as TranslatedText;

                if (!text)
                {
                    Debug.Log("could not find:" + values[0] + ":" + resName);
                    continue;
                }

                string textToReplace = values[2];

                textToReplace = textToReplace.Replace("\\n", "\n");

                if (text.getText(TranslatedText.LANGUAGES.ENGLISH) != textToReplace)
                {
                    Debug.Log("replacing " + resName);
                    Debug.Log("from:" + text.getText(TranslatedText.LANGUAGES.ENGLISH));
                    Debug.Log("for:" + textToReplace);
                    text.setText(TranslatedText.LANGUAGES.ENGLISH, textToReplace);
                    EditorUtility.SetDirty(text);
                    amount++;
                }
            }
        }

        Debug.Log("imported " + amount + " new strings");
    }