コード例 #1
0
            public void Draw()
            {
                _expand = EditorGUILayout.Foldout(_expand, _label, true);
                if (!_expand)
                {
                    return;
                }

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                for (var i = 0; i < _languages.Length; ++i)
                {
                    var selected = PlayerPrefs.GetInt(LocManager.LastLocPrefKey, -1) == i;
                    var language = _languages[i];
                    EditorGUILayout.BeginHorizontal();

                    var bold = EditorStyles.label.fontStyle;
                    if (selected)
                    {
                        EditorStyles.label.fontStyle = FontStyle.Bold;
                    }
                    EditorGUILayout.LabelField(language.stringValue);
                    EditorStyles.label.fontStyle = bold;

                    if (GUILayout.Toggle(selected, "Preview", EditorStyles.miniButton, GUILayout.ExpandWidth(false)) &&
                        !selected)
                    {
                        LocEditorTools.LoadPreview(i);
                    }

                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
コード例 #2
0
        private static bool RefreshFoundState(string value)
        {
            // If string is null, it's not set
            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }
            ;

            var path = LocEditorTools.GetAssetPath(LocManager.KeysName);
            var keys = AssetDatabase.LoadAssetAtPath <LocKeys>(path);

            return(keys != null && keys.Strings.Contains(value));
        }
コード例 #3
0
        public override void OnGUI(Rect position, SerializedProperty key, GUIContent label)
        {
            if (_requireRefresh)
            {
                _found          = RefreshFoundState(key.stringValue);
                _requireRefresh = false;
            }

            EditorGUI.BeginProperty(position, label, key);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Change color of selection is missing
            var previousColor = GUI.backgroundColor;

            if (!_found)
            {
                GUI.backgroundColor = Missing;
            }

            // Draw dropdown
            if (GUI.Button(position, key.stringValue, EditorStyles.popup))
            {
                var path = LocEditorTools.GetAssetPath(LocManager.KeysName);
                var keys = AssetDatabase.LoadAssetAtPath <LocKeys>(path);

                // Show popup
                var popup = new KeySearchPopup(key.stringValue, keys.Strings, selection =>
                {
                    key.stringValue = selection;
                    key.serializedObject.ApplyModifiedProperties();
                    _requireRefresh = true;
                });
                PopupWindow.Show(position, popup);
            }

            GUI.backgroundColor = previousColor;
            EditorGUI.EndProperty();
        }
コード例 #4
0
        private void OnEnable()
        {
            var path = LocEditorTools.GetAssetPath(LocManager.KeysName);
            var keys = AssetDatabase.LoadAssetAtPath <LocKeys>(path);

            if (keys == null)
            {
                return;
            }

            _keys = new GUIContent[keys.Strings.Length];
            for (var i = 0; i < _keys.Length; ++i)
            {
                var key = keys.Strings[i];
                _keys[i] = new GUIContent(key, key);
            }

            var strings = serializedObject.FindProperty("_strings");

            _strings = strings.GetAllElements();

            _foldoutLabel = new GUIContent(string.Format("Values ({0})", _strings.Length));
        }
コード例 #5
0
ファイル: LocImporter.cs プロジェクト: shane-harper/Polyglot
        private static void Import(string path)
        {
            // Delete languages folder?
            var languagesFolder = string.Format("{0}/{1}", LocEditorTools.Folder, LocEditorTools.LanguageSubFolder);

            if (Directory.Exists(languagesFolder) && EditorUtility.DisplayDialog("Delete Previous Localization?",
                                                                                 "Would you like to remove any previous localization assets?", "Yes", "No"))
            {
                Directory.Delete(languagesFolder, true);
            }

            const string progressBarTitle = "Polyglot";
            float        progress         = 0;

            string[]      ids;
            List <string> keys;

            List <string>[] values;
            EditorUtility.DisplayProgressBar(progressBarTitle, "Reading csv...", progress);
            using (var file = new StreamReader(path))
            {
                var line = file.ReadLine();
                if (line == null)
                {
                    throw new Exception("Failed to read data from file");
                }

                // Read headers
                var headers = ParseLine(line);

                // Get localization language ids
                var idCount = headers.Length - 1;
                ids = new string[idCount];
                for (var i = 0; i < idCount; ++i)
                {
                    ids[i] = headers[i + 1];
                }

                // Create lists to hold loc keys values
                keys   = new List <string>();
                values = new List <string> [idCount];
                for (var i = 0; i < idCount; ++i)
                {
                    values[i] = new List <string>();
                }

                // Read string localizations from file
                while ((line = file.ReadLine()) != null)
                {
                    // Ignore empty lines
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    // Split line and get key
                    var split = ParseLine(line);
                    keys.Add(split[0]);

                    // Get values
                    for (var i = 1; i < split.Length; ++i)
                    {
                        values[i - 1].Add(split[i]);
                    }
                }
            }

            // Set keys in LocData
            EditorUtility.DisplayProgressBar(progressBarTitle, "Creating keys file...", progress += 0.2f);
            var keyPath   = LocEditorTools.GetAssetPath(LocManager.KeysName);
            var keysAsset = LocEditorTools.CreateScriptableObject <LocKeys>(keyPath);

            CopyListToSerializedProperty(keys, keysAsset, "_stringKeys");

            // Update settings file
            var settings = Resources.Load <LocSettings>(LocManager.SettingsName);

            if (settings == null)
            {
                settings = CreateSettings();
            }
            CopyListToSerializedProperty(ids, settings, "_languages");

            // Create languages and populate
            const float maxLanguageProgress = 0.9f;

            for (var i = 0; i < values.Length; ++i)
            {
                EditorUtility.DisplayProgressBar(progressBarTitle, "Creating languages...",
                                                 progress + (float)i / values.Length * (maxLanguageProgress - progress));
                var languagePath = LocEditorTools.GetAssetPath(ids[i]);
                var language     = LocEditorTools.CreateScriptableObject <LocLanguage>(languagePath);
                CopyListToSerializedProperty(values[i], language, "_strings");
            }

            // Rebuild asset bundles
            #if !POLYGLOT_ADDRESSABLES
            progress = maxLanguageProgress;
            var buildTarget = EditorUserBuildSettings.activeBuildTarget;
            var message     = string.Format(
                "Localization data import complete! Would you like to rebuild Polyglot asset bundles?\n\n({0})",
                buildTarget);
            if (EditorUtility.DisplayDialog("Rebuild Asset Bundles", message, "Yes", "No"))
            {
                EditorUtility.DisplayProgressBar(progressBarTitle, "Rebuilding asset bundles...", progress);
                LocEditorTools.BuildStreamingAssets(buildTarget);
            }
            #endif

            // Clear progress bar
            EditorUtility.ClearProgressBar();
        }
コード例 #6
0
ファイル: LocImporter.cs プロジェクト: shane-harper/Polyglot
        private static LocSettings CreateSettings()
        {
            var path = string.Format("{0}/Resources/{1}.asset", LocEditorTools.Folder, LocManager.SettingsName);

            return(LocEditorTools.CreateScriptableObject <LocSettings>(path));
        }