打包导出包体文件夹时 将指定文件(夹)自动拷贝到包体内
发表于2018-12-29
using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; using System.IO; public class AfterBuildToDo : Editor { [PostProcessBuild(1)] public static void AfterBuild(BuildTarget target, string pathToBuiltProject) { Debug.Log("Build Success 输出平台: " + target + " 输出路径: " + pathToBuiltProject); //打开文件或文件夹 //System.Diagnostics.Process.Start(pathToBuiltProject); if (target == BuildTarget.Android) { //读取源文件路径 string sourceParh = Application.dataPath + "/Plugins/Android/MyDirectory/MyFile.text"; //获取拷贝路径 = 打包输出路径 + 包名(打包文件夹名) + 下级路径 string targetPath = pathToBuiltProject + "/" + PlayerSettings.productName + "/MyDirectory"; //是否已存在文件夹 if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } //拷贝文件(源路径及文件名, 拷贝路径及文件名, 若该文件名已存在,是否替换) File.Copy(sourceParh, targetPath + "/MyFile.text", true); } } }