public override void OnInspectorGUI()
        {
            GUIStyle boldFoldout = new GUIStyle(EditorStyles.foldout)
            {
                fontStyle = FontStyle.Bold
            };

            serializedObject.Update();
            // Grab target
            LanguageManager myTarget = (LanguageManager)target;

            // Space above first line
            GUILayout.Space(SPACING_SIZE);
            AddHeader("Auto-Loading");
            myTarget.SetSerializedField("loadOnAwake", EditorGUILayout.Toggle("Load On Awake", myTarget.LoadOnAwake));
            // Header
            AddHeader("Preferred Language");
            // Toggle for usage of Preferred Language
            myTarget.SetSerializedField("usePreferredLanguage", EditorGUILayout.ToggleLeft("Use a preferred Language", myTarget.UsePreferredLanguage));
            // Toogle for usage of saved language
            myTarget.SetSerializedField("useSavedLanguage", EditorGUILayout.ToggleLeft("Use saved language settings", myTarget.UseSavedLanguage));
            // Dropdown shown only if toggle = true
            if (myTarget.UsePreferredLanguage)
            {
                EditorGUI.indentLevel++;
                myTarget.SetSerializedField("preferredLanguage", (Language)Enum.GetValues(typeof(Language)).GetValue(EditorGUILayout.Popup("Language:", Array.IndexOf(Enum.GetNames(typeof(Language)), myTarget.PreferredLanguage.ToString()), Enum.GetNames(typeof(Language)), EditorStyles.popup)));
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * INDENT_SIZE);
                if (GUILayout.Button("Set as Current", EditorStyles.miniButtonRight))
                {
                    if (LanguageManager.Exists) // Game is Running
                    {
                        LanguageManager.SetLanguage(myTarget.PreferredLanguage);
                    }
                    else // Game is NOT running
                    {
                        myTarget.SetSerializedField("currentLanguage", myTarget.PreferredLanguage);
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }
            GUILayout.Space(SPACING_SIZE);
            // Header
            AddHeader("Translation-File  (CSV)");
            EditorGUI.indentLevel++;
            bool changed = GUI.changed;

            csvSettingsFoldout = EditorGUILayout.Foldout(csvSettingsFoldout, "CSV Settings");
            // Skip GUI.changed for Foldout
            GUI.changed = changed;
            if (csvSettingsFoldout)
            {
                EditorGUI.indentLevel++;
                Dictionary <string, string> newLines = new Dictionary <string, string>
                {
                    { "Environment_NewLine", Environment.NewLine },
                    { "\\n", "\n" },
                    { "\\r\\n", "\r\n" },
                    { ";", ";" }
                };
                if (newLines.Values.Contains(myTarget.NewLineStr))
                {
                    myTarget.SetSerializedField("newLineStr", newLines.Values.ToList()[EditorGUILayout.Popup("NewLine", newLines.Values.ToList().IndexOf(myTarget.NewLineStr), newLines.Keys.ToArray())]);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("NewLine");
                    EditorGUILayout.LabelField(myTarget.NewLineStr);
                    EditorGUILayout.EndHorizontal();
                }
                char[] delimiter =
                {
                    ',',
                    '.',
                    ';',
                    ':',
                    '|',
                    '^',
                    '#',
                };
                List <string> delStrings = new List <string>();
                foreach (char c in delimiter)
                {
                    delStrings.Add(c.ToString());
                }
                if (delStrings.Contains(myTarget.Delimiter.ToString()))
                {
                    myTarget.SetSerializedField("delimiter", delimiter.ToList()[EditorGUILayout.Popup("Delimiter", delimiter.ToList().IndexOf(myTarget.Delimiter), delStrings.ToArray())]);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Delimiter");
                    EditorGUILayout.LabelField(myTarget.Delimiter.ToString());
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
            }
            EditorGUI.indentLevel--;

            // Toggle for usage of Remote (Downloaded & Cached) Language-File
            myTarget.SetSerializedField("useRemoteLanguageFile", EditorGUILayout.ToggleLeft("Use a remote Language-File", myTarget.UseRemoteLanguageFile));
            // TextField (for URL) shown only if toggle = true;
            if (myTarget.UseRemoteLanguageFile)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("URL for Language-File:");
                EditorGUILayout.LabelField("Staging:");
                myTarget.SetSerializedField("stagingLanguageURL", EditorGUILayout.TextField(myTarget.StagingLanguageUrl));
                EditorGUILayout.LabelField("Live:");
                myTarget.SetSerializedField("liveLanguageURL", EditorGUILayout.TextField(myTarget.LiveLanguageUrl));
                myTarget.SetSerializedField("appendApplicationVersion", EditorGUILayout.Toggle("Append Version Number", myTarget.AppendApplicationVersion));
                EditorGUILayout.EndVertical();
                myTarget.SetSerializedField("userName", EditorGUILayout.TextField("Custom Username: "******"password", EditorGUILayout.PasswordField("Custom Password: "******"domain", EditorGUILayout.TextField("Custom Domain: ", myTarget.Domain));
                }
                else
                {
                    myTarget.SetSerializedField("password", null);
                    myTarget.SetSerializedField("domain", null);
                }
                myTarget.SetSerializedField("wifiDownloadOnly", EditorGUILayout.Toggle("Download on WIFI only", myTarget.WIFIDownloadOnly));
                myTarget.SetSerializedField("languageMap", (TextAsset)EditorGUILayout.ObjectField("FirstBoot-File:", myTarget.LanguageMap, typeof(TextAsset), false));
                EditorGUI.indentLevel--;
            }
            else // ObjectField (for TextAsset) shown if toggle = false
            {
                GUILayout.Space(SPACING_SIZE);
                myTarget.SetSerializedField("languageMap", (TextAsset)EditorGUILayout.ObjectField("Language-File:", myTarget.LanguageMap, typeof(TextAsset), false));
            }
            GUILayout.Space(SPACING_SIZE);
            // Header
            AddHeader("Language");
            EditorGUILayout.BeginHorizontal();
            // Current Language in Manager
            EditorGUILayout.LabelField("Current Language:");
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = -4; // Don't ask why
            EditorGUILayout.LabelField(myTarget.GetSerializedField <Language>("currentLanguage").ToString());
            EditorGUI.indentLevel = indent;
            EditorGUILayout.EndHorizontal();
            // FallbackLanguage
            myTarget.SetSerializedField("fallbackLanguage", (Language)Enum.GetValues(typeof(Language)).GetValue(EditorGUILayout.Popup("Fallback Language:", Array.IndexOf(Enum.GetNames(typeof(Language)), myTarget.FallbackLanguage.ToString()), Enum.GetNames(typeof(Language)), EditorStyles.popup)));
            GUILayout.Space(SPACING_SIZE);
            changed = GUI.changed;
            EditorGUI.indentLevel++;
            debugFoldout = EditorGUILayout.Foldout(debugFoldout, "Debug", boldFoldout);
            EditorGUI.indentLevel--;
            // Skip foldout for GUI.changed
            GUI.changed = changed;
            if (debugFoldout)
            {
                bool LogMethods = myTarget.GetSerializedField <bool>("logMethods");
                LogMethods = EditorGUILayout.Toggle("Log Methods", LogMethods);
                myTarget.SetSerializedField("logMethods", LogMethods);
                if (LogMethods)
                {
                    myTarget.SetSerializedField("logLevel", (LoggingLevel)Enum.GetValues(typeof(LoggingLevel)).GetValue(EditorGUILayout.Popup("Logging-Level:", Array.IndexOf(Enum.GetNames(typeof(LoggingLevel)), myTarget.GetSerializedField <LoggingLevel>("logLevel").ToString()), Enum.GetNames(typeof(LoggingLevel)), EditorStyles.popup)));
                }
            }
            // GAME IS RUNNING
            if (LanguageManager.Exists)
            {
                GUILayout.Space(SPACING_SIZE);
                if (ResourceLoader.UserHasSavedLanguage)
                {
                    EditorGUILayout.BeginHorizontal();
                    // User-Saved Language
                    EditorGUILayout.LabelField("User-Saved Language:");
                    EditorGUILayout.LabelField(ResourceLoader.UserSavedLanguage.ToString());
                    EditorGUILayout.EndHorizontal();
                    // Clear-Button
                    if (GUILayout.Button("Clear Saved Language", EditorStyles.miniButtonRight))
                    {
                        ResourceLoader.ClearSavedLanguage();
                    }
                    GUILayout.Space(SPACING_SIZE);
                }
                // Header
                AddHeader("TranslatedTexts");
                // Button for updating Registered Texts
                if (GUILayout.Button("Update Registered TranslatedTexts", EditorStyles.toolbarButton))
                {
                    LanguageManager.RefreshRegisteredTranslatedTexts();
                }
                // Button for updating ALL Texts
                if (GUILayout.Button("Update All TranslatedTexts", EditorStyles.toolbarButton))
                {
                    AbstractTranslatedText.RefreshAll();
                }
            }
            if (GUI.changed && !Application.isPlaying)
            {
                EditorUtility.SetDirty((LanguageManager)target);
                EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
            }
        }
Пример #2
0
 /// <summary>
 /// Refreshes ALL RegisterText-Objects, including non-registered ones
 /// <para>
 /// Is the same as calling RegisterText.RefreshAll()
 /// </para>
 /// </summary>
 public static void RefreshALLTranslatedTexts()
 {
     LoggingLevel.Info.Log("TranslatedText: Refreshing ALL TranslatedTexts", instance.GetLoggingLevel(), instance);
     AbstractTranslatedText.RefreshAll();
 }
Пример #3
0
        public override void OnInspectorGUI()
        {
            if (boldFoldout == null)
            {
                if (EditorStyles.foldout == null)
                {
                    return; // Fix for NullRef on first frame when entering play-mode
                }
                boldFoldout = new GUIStyle(EditorStyles.foldout)
                {
                    fontStyle = FontStyle.Bold
                };
            }

            // Grab target
            AbstractTranslatedText myTarget = (AbstractTranslatedText)target;

            // Space above first line
            GUILayout.Space(SPACING_SIZE);
            // Fields
            string newVal = EditorGUILayout.TextField("Translation Key", myTarget.FieldName);

            if (!string.Equals(newVal, myTarget.FieldName))
            {
                myTarget.SetSerializedField("fieldName", newVal);
                GUI.changed = true;
            }
            bool autoRegister = EditorGUILayout.Toggle("Auto-Register", myTarget.AutoRegister);

            if (autoRegister != myTarget.AutoRegister)
            {
                myTarget.SetSerializedField("autoRegister", autoRegister);
                GUI.changed = true;
            }
            bool useCustomLang = EditorGUILayout.ToggleLeft("Use Custom Language", myTarget.UseCustomLanguage);

            if (!useCustomLang.Equals(myTarget.UseCustomLanguage))
            {
                if (!LanguageManager.Exists) // Game is running. Use setter with Refresh()
                {
                    myTarget.UseCustomLanguage = useCustomLang;
                }
                else
                {
                    myTarget.SetSerializedField("useCustomLanguage", useCustomLang);  // Game is NOT running. Use setter without Refresh()
                }
                GUI.changed = true;
            }
            // Only show CustomLanguage is UseCustomLanguage is true
            if (myTarget.UseCustomLanguage)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                Language customLang = (Language)Enum.GetValues(typeof(Language)).GetValue(EditorGUILayout.Popup("Custom Language:", Array.IndexOf(Enum.GetNames(typeof(Language)), myTarget.CustomLanguage.ToString()), Enum.GetNames(typeof(Language)), EditorStyles.popup));
                if (!customLang.Equals(myTarget.CustomLanguage))
                {
                    if (LanguageManager.Exists)// Game is running. Use setter with Refresh()
                    {
                        myTarget.CustomLanguage = customLang;
                    }
                    else
                    {
                        myTarget.SetSerializedField("customLanguage", customLang); // Game is NOT running. Use setter without Refresh()
                    }
                    GUI.changed = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }

            AbstractTranslatedText.SpecialTextSettings textSetting = (AbstractTranslatedText.SpecialTextSettings)EditorGUILayout.EnumPopup("Special Text Setting", myTarget.TextSetting);
            if (textSetting != myTarget.TextSetting)
            {
                myTarget.SetSerializedField("specialTextSettings", textSetting);
                GUI.changed = true;
            }

            bool lineBreak = EditorGUILayout.Toggle("Ignore Line Breaks", myTarget.IgnoreLineBreak);

            if (lineBreak != myTarget.IgnoreLineBreak)
            {
                myTarget.SetSerializedField("ignoreLineBreaks", lineBreak);
                GUI.changed = true;
            }

            GUILayout.Space(SPACING_SIZE);

            bool changed = GUI.changed;

            EditorGUI.indentLevel++;

            DrawTextDisplayInspector();
            debugFoldout = EditorGUILayout.Foldout(debugFoldout, "Debug", boldFoldout);
            EditorGUI.indentLevel--;
            // Skip foldout for GUI.changed
            GUI.changed = changed;
            if (debugFoldout)
            {
                bool log    = myTarget.GetSerializedField <bool>("logMethods");
                bool newLog = EditorGUILayout.Toggle("Log Methods", log);
                if (log != newLog)
                {
                    myTarget.SetSerializedField("logMethods", newLog);
                    GUI.changed = true;
                }
                if (newLog)
                {
                    LoggingLevel logging    = myTarget.GetSerializedField <LoggingLevel>("logLevel");
                    LoggingLevel newLogging = (LoggingLevel)Enum.GetValues(typeof(LoggingLevel)).GetValue(EditorGUILayout.Popup("Logging-Level:", Array.IndexOf(Enum.GetNames(typeof(LoggingLevel)), logging.ToString()), Enum.GetNames(typeof(LoggingLevel)), EditorStyles.popup));
                    if (!logging.Equals(newLogging))
                    {
                        myTarget.SetSerializedField("logLevel", newLogging);
                        GUI.changed = true;
                    }
                }
            }
            // GAME IS RUNNING
            if (LanguageManager.Exists)
            {
                GUILayout.Space(SPACING_SIZE);
                FontStyle currStyle = EditorStyles.label.fontStyle;
                int       currSize  = EditorStyles.label.fontSize;
                EditorStyles.label.fontStyle = FontStyle.Bold;
                EditorStyles.label.fontSize  = 12;
                EditorGUILayout.LabelField("Runtime", GUILayout.Height(20));
                EditorStyles.label.fontStyle = currStyle;
                EditorStyles.label.fontSize  = currSize;
                if (!myTarget.IsRegistered.Equals(EditorGUILayout.Toggle("Registered", myTarget.IsRegistered)))
                {
                    if (myTarget.IsRegistered)
                    {
                        LanguageManager.UnregisterTranslatedText(myTarget);
                    }
                    else
                    {
                        LanguageManager.RegisterTranslatedText(myTarget);
                    }
                }
                if (GUILayout.Button("Refresh", EditorStyles.toolbarButton))
                {
                    myTarget.Refresh();
                }
                if (GUILayout.Button("Refresh All", EditorStyles.toolbarButton))
                {
                    AbstractTranslatedText.RefreshAll();
                }
            }
            if (GUI.changed && !Application.isPlaying)
            {
                EditorUtility.SetDirty((AbstractTranslatedText)target);
                EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
            }
        }