Пример #1
0
 private void ButtonCreate(Rect rect)
 {
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     if (GUILayout.Button("Create Locales"))
     {
         LocalizationSO localization     = LocalizationUtility.RetrieveLocalization();
         string         pathLocalization = AssetDatabase.GetAssetPath(localization);
         if (localization != null && string.IsNullOrEmpty(pathLocalization) == false)
         {
             foreach (LocaleLanguageEditor language in _mInformations.GetLanguagesSelected())
             {
                 if (localization.LocaleExists(language._mLanguage) == false)
                 {
                     string pathLocale = Path.Combine(Path.GetDirectoryName(pathLocalization), "Locale - " + language._mName + ".asset");
                     Debug.Log(pathLocale);
                     LocalizationLocaleSO locale = ScriptableObject.CreateInstance <LocalizationLocaleSO>();
                     locale.Init(language._mLanguage, language._mName, language._mCode);
                     localization.AddLocale(locale);
                     AssetDatabase.CreateAsset(locale, pathLocale);
                     EditorUtility.SetDirty(localization);
                     AssetDatabase.SaveAssets();
                     AssetDatabase.Refresh();
                 }
             }
         }
     }
     GUILayout.EndHorizontal();
 }
        public override void InitializeWindow()
        {
            base.InitializeWindow();

            _mLocalization = LocalizationUtility.RetrieveLocalization();
            if (_mLocalization.Tables.Count > 0)
            {
                _mInformations = new AssetTablesInformations(_mLocalization.Tables[0]);
            }
            else
            {
                _mInformations = new AssetTablesInformations(null);
            }

            _mScrollviewPosition = Vector2.zero;

            foreach (LocalizationLocaleSO locale in _mLocalization.Locales)
            {
                _mInformations.SetLanguage(locale.Language, false);
            }

            InitializeWindowAsCreateTable();
        }
        private void TableSelection(Rect rect)
        {
            GUILayout.BeginVertical();

            LocalizationSO localization      = LocalizationUtility.RetrieveLocalization();
            List <string>  tablesIdentifiers = localization.GetTablesIdentifiers();

            if (tablesIdentifiers.Count > 0)
            {
                int indexSelected = tablesIdentifiers.IndexOf(_mInformations.TextTableName);
                if (indexSelected < 0)
                {
                    indexSelected = 0;
                }

                GUILayout.BeginHorizontal();

                GUILayout.Label("Table", GUILayout.MaxWidth(100));
                indexSelected = EditorGUILayout.Popup("", indexSelected, tablesIdentifiers.ToArray());
                var tableSelected = localization.Tables[indexSelected];
                if (tableSelected != _mInformations.TableSelected)
                {
                    _mInformations.SetTableSelected(localization.Tables[indexSelected]);
                }

                if (GUILayout.Button("Delete", GUILayout.MaxWidth(100)))
                {
                    string pathLocalization       = AssetDatabase.GetAssetPath(_mLocalization);
                    string folderPathLocalization = Path.GetDirectoryName(pathLocalization);
                    string folderToDelete         = Path.Combine(folderPathLocalization, _mInformations.TableSelected.TableName);
                    _mLocalization.RemoveAssetTable(_mInformations.TableSelected);
                    MyrmidonEditorUtility.DeleteFolder(folderToDelete);
                    Repaint();
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Table name", GUILayout.MaxWidth(100));
                _mInformations.EditingTableName = GUILayout.TextField(_mInformations.EditingTableName);
                if (GUILayout.Button("Rename", GUILayout.MaxWidth(100)))
                {
                    string registeredName = _mInformations.RegisteredTableName;
                    string editedName     = _mInformations.EditingTableName;
                    if (string.IsNullOrEmpty(editedName) == false && editedName != registeredName && _mLocalization.AssetsTableExists(editedName) == false)
                    {
                        string pathLocalization       = AssetDatabase.GetAssetPath(_mLocalization);
                        string folderPathLocalization = Path.GetDirectoryName(pathLocalization);
                        string folderPathTable        = Path.Combine(folderPathLocalization, _mInformations.TableSelected.TableName);

                        MyrmidonEditorUtility.RenameFolderAt(folderPathTable, registeredName, editedName);

                        _mInformations.RegisteredTableName     = _mInformations.EditingTableName;
                        _mInformations.TableSelected.TableName = editedName;
                        MyrmidonEditorUtility.RenameAsset(_mInformations.TableSelected, registeredName, editedName);

                        foreach (LocalizationLocaleAssetsSO localeAssets in _mInformations.TableSelected.LocalesAssets)
                        {
                            MyrmidonEditorUtility.RenameAsset(localeAssets, registeredName, editedName);
                        }

                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }