コード例 #1
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.GameObject && objectToCopy.ThisGameObject != null)
            {
                filePath         = LocalizationWorkspace.LanguagePrefabsFolderPath(thisCultureInfo.languageCode);
                currentAssetPath = AssetDatabase.GetAssetPath(objectToCopy.ThisGameObject);
            }
            else if (objectToCopy.ObjectType == LocalizedObjectType.TextAsset && 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.GameObject)
            {
                //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));
        }