コード例 #1
0
 static bool GetAssetPathFromGUID(SerializableLocalizationObjectPair objectPair, out string assetPath)
 {
     assetPath = null;
     if (objectPair.changedValue.TextValue != null && objectPair.changedValue.TextValue != string.Empty)
     {
         assetPath = AssetDatabase.GUIDToAssetPath(objectPair.changedValue.TextValue);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        void OnKeyAdded(int addedIndex)
        {
            LocalizedObject dummyObject = new LocalizedObject();

            dummyObject.ObjectType = LocalizedObjectType.STRING;
            dummyObject.TextValue  = "New Value";

            string addedKey = LanguageDictionaryHelper.AddNewKeyPersistent(parsedRootValues, "New Key", dummyObject);

            LocalizedObject copyObject = new LocalizedObject();

            copyObject.ObjectType = LocalizedObjectType.STRING;
            copyObject.TextValue  = "New Value";

            changedRootKeys.Add(new SerializableStringPair(addedKey, addedKey));
            changedRootValues[addedIndex] = new SerializableLocalizationObjectPair(addedKey, copyObject);
        }
コード例 #3
0
        void SaveRootLanguageFile()
        {
            var changeNewRootKeys   = new Dictionary <string, string>();
            var changeNewRootValues = new Dictionary <string, string>();

            for (int i = 0; i < changedRootKeys.Count; i++)
            {
                SerializableStringPair             rootKey   = changedRootKeys[i];
                SerializableLocalizationObjectPair rootValue = changedRootValues[i];
                //Check for possible duplicates and rename them
                string newKeyValue = LanguageDictionaryHelper.AddNewKeyPersistent(changeNewRootKeys,
                                                                                  rootKey.originalValue,
                                                                                  rootValue.changedValue.GetFullKey(rootKey.changedValue));

                //Check for possible duplicates and rename them(same as above)
                LanguageDictionaryHelper.AddNewKeyPersistent(changeNewRootValues, newKeyValue, rootValue.changedValue.TextValue);
            }

            //Add the full values before saving
            var changeNewRootKeysToSave   = new Dictionary <string, string>();
            var changeNewRootValuesToSave = new Dictionary <string, string>();

            foreach (var rootKey in changeNewRootKeys)
            {
                LocalizedObject thisLocalizedObject = parsedRootValues[rootKey.Key];
                changeNewRootKeysToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), rootKey.Value);
                changeNewRootValuesToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), changeNewRootValues[rootKey.Key]);
            }



            SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());

            LanguageHandlerEditor.SaveRootLanguageFile(changeNewRootKeysToSave, changeNewRootValuesToSave, LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures));

            //Fire the root language changed event
            if (OnRootFileChanged != null)
            {
                OnRootFileChanged();
            }

            //Reload the window(in case of duplicate keys)
            SetRootValues(LanguageHandlerEditor.LoadParsedLanguageFile(null, true));
        }
コード例 #4
0
        SerializableLocalizationObjectPair DrawRootPair(Rect position, SerializableLocalizationObjectPair item)
        {
            LocalizedObjectType newChangedType = (LocalizedObjectType)EditorGUI.Popup(
                listColumns.GetColumnPosition(position, "Type"),
                (int)item.changedValue.ObjectType,
                keyTypes);

            int index = changedRootValues.IndexOf(item);
            SerializableStringPair rootValue = changedRootKeys[index];
            string newChangedValue           = EditorGUI.TextField(listColumns.GetColumnPosition(position, "Key"), rootValue.changedValue);
            string newTextValue = EditorGUI.TextArea(listColumns.GetColumnPosition(position, "Comment"), item.changedValue.TextValue);

            if (newChangedType != changedRootValues[index].changedValue.ObjectType ||
                newChangedValue != rootValue.changedValue ||
                newTextValue != changedRootValues[index].changedValue.TextValue)
            {
                undoManager.ForceDirty();
                changedRootValues[index].changedValue.ObjectType = newChangedType;
                rootValue.changedValue = newChangedValue;
                changedRootValues[index].changedValue.TextValue = newTextValue;
            }

            return(item);
        }
コード例 #5
0
        SerializableLocalizationObjectPair DrawLanguageValue(Rect position, SerializableLocalizationObjectPair item)
        {
            float fullWindowWidth = position.width + 28;

            position.width = fullWindowWidth;

            if (GUI.Button(listColumns.GetColumnPosition(position, "Копия"), "Из корня"))     //Copy Root
            {
                if (undoManager != null)
                {
                    undoManager.ForceDirty();
                }

                item.changedValue = new LocalizedObject(rootValues[item.keyValue]);

                GUIUtility.keyboardControl = 0;
            }
            if (item.changedValue.ObjectType == LocalizedObjectType.STRING && canLanguageBeTranslated &&
                translateFromLanguageValue != 0 &&
                translateFromDictionary != null && translateFromDictionary[item.keyValue].TextValue != null &&
                translateFromDictionary[item.keyValue].TextValue != string.Empty)
            {
                if (GUI.Button(listColumns.GetColumnPosition(position, "Перевод"), "Перевод"))          //Translate
                {
                    automaticTranslator.TranslateText(OnTextTranslated, item.keyValue, translateFromDictionary[item.keyValue].TextValue,
                                                      translateFromLanguage, currentCultureInfo.languageCode);
                }
            }
            else
            {
                GUI.Label(listColumns.GetColumnPosition(position, "Перевод"), "Перевод");           //Translate
            }

            EditorGUI.SelectableLabel(listColumns.GetColumnPosition(position, "Ключ"), item.keyValue);                              //Key
            EditorGUI.SelectableLabel(listColumns.GetColumnPosition(position, "Комментарий"), rootValues[item.keyValue].TextValue); //Comment

            if (item.changedValue.ObjectType != LocalizedObjectType.STRING && otherAvailableLanguageCodes.Count > 0)
            {
                bool overrideLang = EditorGUI.Toggle(listColumns.GetColumnPosition(position, "Переопределить"), item.changedValue.OverrideLocalizedObject);           //Override
                if (overrideLang != item.changedValue.OverrideLocalizedObject)
                {
                    if (undoManager != null)
                    {
                        undoManager.ForceDirty();
                    }

                    item.changedValue.OverrideLocalizedObject = overrideLang;

                    if (overrideLang)
                    {
                        item.changedValue.OverrideObjectLanguageCode = otherAvailableLanguageCodes[0];
                    }
                }
            }
            else
            {
                GUI.Label(listColumns.GetColumnPosition(position, "Переопределить"), "-");            //Override
            }

            Rect newPosition = listColumns.GetColumnPosition(position, "Значение");        //Value

            bool setDirty = false;

            if (!item.changedValue.OverrideLocalizedObject)
            {
                if (item.changedValue.ObjectType == LocalizedObjectType.STRING)
                {
                    string newTextValue = EditorGUI.TextArea(newPosition, item.changedValue.TextValue);
                    if (newTextValue != item.changedValue.TextValue)
                    {
                        setDirty = true;
                        item.changedValue.TextValue = newTextValue;
                    }
                }
                else if (item.changedValue.ObjectType == LocalizedObjectType.AUDIO)
                {
                    AudioClip newAudioValue = (AudioClip)EditorGUI.ObjectField(newPosition,
                                                                               item.changedValue.ThisAudioClip,
                                                                               typeof(AudioClip), false);
                    if (newAudioValue != item.changedValue.ThisAudioClip)
                    {
                        setDirty = true;
                        item.changedValue.ThisAudioClip = newAudioValue;
                    }
                }
                else if (item.changedValue.ObjectType == LocalizedObjectType.GAME_OBJECT)
                {
                    GameObject newGameObjectValue = (GameObject)EditorGUI.ObjectField(newPosition,
                                                                                      item.changedValue.ThisGameObject,
                                                                                      typeof(GameObject), false);

                    if (newGameObjectValue != item.changedValue.ThisGameObject)
                    {
                        setDirty = true;
                        item.changedValue.ThisGameObject = newGameObjectValue;
                    }
                }
                else if (item.changedValue.ObjectType == LocalizedObjectType.TEXTURE)
                {
                    Texture newTextureValue = (Texture)EditorGUI.ObjectField(newPosition,
                                                                             item.changedValue.ThisTexture,
                                                                             typeof(Texture), false);
                    if (newTextureValue != item.changedValue.ThisTexture)
                    {
                        setDirty = true;
                        item.changedValue.ThisTexture = newTextureValue;
                    }
                }
                else if (item.changedValue.ObjectType == LocalizedObjectType.TEXT_ASSET)
                {
                    TextAsset newTextAssetValue = (TextAsset)EditorGUI.ObjectField(newPosition,
                                                                                   item.changedValue.ThisTextAsset,
                                                                                   typeof(TextAsset), false);
                    if (newTextAssetValue != item.changedValue.ThisTextAsset)
                    {
                        setDirty = true;
                        item.changedValue.ThisTextAsset = newTextAssetValue;
                    }
                }
                else if (item.changedValue.ObjectType == LocalizedObjectType.FONT)
                {
                    Font newFontValue = (Font)EditorGUI.ObjectField(newPosition,
                                                                    item.changedValue.Font,
                                                                    typeof(Font), false);
                    if (newFontValue != item.changedValue.Font)
                    {
                        setDirty = true;
                        item.changedValue.Font = newFontValue;
                    }
                }
            }
            else
            {
                if (otherAvailableLanguageCodes.Count > 0)
                {
                    int selectedIndex = -1;
                    for (int i = 0; i < otherAvailableLanguageCodes.Count; ++i)
                    {
                        if (otherAvailableLanguageCodes[i] == item.changedValue.OverrideObjectLanguageCode)
                        {
                            selectedIndex = i;
                            break;
                        }
                    }

                    if (selectedIndex == -1)
                    {
                        selectedIndex = 0;
                        item.changedValue.OverrideObjectLanguageCode = otherAvailableLanguageCodes[selectedIndex];
                        setDirty = true;
                    }
                    int newIndex = EditorGUI.Popup(newPosition, selectedIndex, otherAvailableLanguageCodesArray);

                    if (newIndex != selectedIndex)
                    {
                        item.changedValue.OverrideObjectLanguageCode = otherAvailableLanguageCodes[newIndex];
                        setDirty = true;
                    }
                }
                else
                {
                    //There are no languages to steal from, disable the override.
                    item.changedValue.OverrideLocalizedObject = false;
                    setDirty = true;
                }
            }

            if (undoManager != null && setDirty)
            {
                undoManager.ForceDirty();
            }
            return(item);
        }
コード例 #6
0
        /// <summary> Copies the file into the resources folder. Naming the new asset to KEY </summary>
        public static string CopyFileIntoResources(SerializableLocalizationObjectPair objectPair, SmartCultureInfo thisCultureInfo)
        {
            if (!DirectoryUtility.CheckAndCreate(LocalizationWorkspace.LanguageRuntimeFolderPath(thisCultureInfo.languageCode)))
            {
                return("");
            }


            string          newFileName      = objectPair.keyValue;
            string          filePath         = string.Empty;
            string          currentAssetPath = string.Empty;
            LocalizedObject objectToCopy     = objectPair.changedValue;

            if (objectToCopy.ObjectType == LocalizedObjectType.AUDIO && objectToCopy.ThisAudioClip != null)
            {
                filePath         = LocalizationWorkspace.LanguageAudioFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.ThisAudioClip);
            }
            else if (objectToCopy.ObjectType == LocalizedObjectType.TEXTURE && objectToCopy.ThisTexture != null)
            {
                filePath         = LocalizationWorkspace.LanguageTexturesFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.ThisTexture);
            }
            else if (objectToCopy.ObjectType == LocalizedObjectType.GAME_OBJECT && objectToCopy.ThisGameObject != null)
            {
                filePath         = LocalizationWorkspace.LanguagePrefabsFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.ThisGameObject);
            }
            else if (objectToCopy.ObjectType == LocalizedObjectType.TEXT_ASSET && objectToCopy.ThisTextAsset != null)
            {
                filePath         = LocalizationWorkspace.LanguageTextAssetsFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.ThisTextAsset);
            }
            else if (objectToCopy.ObjectType == LocalizedObjectType.FONT && objectToCopy.Font != null)
            {
                filePath         = LocalizationWorkspace.LanguageFontsFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.Font);
            }
            else
            {
                return(string.Empty);
            }

            if (!DirectoryUtility.CheckAndCreate(filePath))
            {
                return("");
            }

            //Get the fileExtension of the asset
            string fileExtension = FileUtility.GetFileExtension(Application.dataPath + currentAssetPath);

            if (objectToCopy.ObjectType != LocalizedObjectType.GAME_OBJECT)
            {
                //Copy or replace the file to the new path
                FileUtil.ReplaceFile(currentAssetPath, filePath + "/" + newFileName + fileExtension);

                string metaFile = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length) +
                                  currentAssetPath.Substring(0, currentAssetPath.Length - fileExtension.Length) + fileExtension + ".meta";
                if (File.Exists(metaFile))
                {
                    FileUtil.ReplaceFile(metaFile, filePath + "/" + newFileName + fileExtension + ".meta");
                }
            }
            else
            {
                string relativePath = filePath + "/" + newFileName + fileExtension;
                relativePath = "Assets" + relativePath.Substring(Application.dataPath.Length);
                //1PrefabUtility.CreatePrefab(relativePath, objectToCopy.ThisGameObject);
                PrefabUtility.SaveAsPrefabAsset(objectToCopy.ThisGameObject, relativePath);             // TODO Перепроверить
            }

            return(AssetDatabase.AssetPathToGUID(currentAssetPath));
        }