/// <summary> /// Checks .resx files and converts them into text assets that can be used at runtime /// </summary> public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { //Only use this if there's a localization system created if (!LocalizationWorkspace.Exists()) { return; } foreach (string asset in importedAssets) { if (asset.EndsWith(LocalizationWorkspace.resXFileEnding)) { string newFileName = LocalizationWorkspace.ResourcesFolderFilePath() + "/" + Path.GetFileNameWithoutExtension(asset) + LocalizationWorkspace.txtFileEnding; if (!DirectoryUtility.CheckAndCreate(LocalizationWorkspace.ResourcesFolderFilePath())) { return; } //Delete the file if it already exists if (FileUtility.Exists(newFileName)) { FileUtility.Delete(newFileName); } string fileData = ""; using (StreamReader reader = new StreamReader(asset)) { fileData = reader.ReadToEnd(); } FileUtility.WriteToFile(newFileName, fileData); SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath()); LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures); AssetDatabase.Refresh(ImportAssetOptions.Default); } } }
/// <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); PrefabUtility.CreatePrefab(relativePath, objectToCopy.ThisGameObject); } return AssetDatabase.AssetPathToGUID(currentAssetPath); }
/// <summary> /// Generates all the files for store presence /// </summary> /// <returns>If the operation was successful</returns> public static bool GeneratePresence() { if (HasStorePresence) { return(true); } string currentDirectory = Application.dataPath + "/" + PluginFolderName; if (!DirectoryUtility.CheckAndCreate(currentDirectory)) { return(false); } currentDirectory += "/" + AndroidFolderName; if (!DirectoryUtility.CheckAndCreate(currentDirectory)) { return(false); } currentDirectory += "/" + ResourceFolderName; if (!DirectoryUtility.CheckAndCreate(currentDirectory)) { return(false); } //Create the default directory if (!DirectoryUtility.CheckAndCreate(currentDirectory + "/" + ValuesFolderName)) { return(false); } if (!AppendOrCreateStringsFile(currentDirectory + "/" + ValuesFolderName + "/" + StringsFileName)) { return(false); } var availableCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.AvailableCulturesFilePath()); foreach (SmartCultureInfo cultureInfo in availableCultures.cultureInfos) { if (!IsLanguageSupported(cultureInfo.languageCode)) { continue; } string currentLanguageFolderPath = GetValueFolderPath(currentDirectory, cultureInfo); if (!DirectoryUtility.CheckAndCreate(currentLanguageFolderPath)) { return(false); } if (!AppendOrCreateStringsFile(currentLanguageFolderPath + "/" + StringsFileName)) { return(false); } } AssetDatabase.Refresh(); return(true); }