Example #1
0
    //[MenuItem("Tools/Copy Test", false, 0)]
    static void CopyVideo1()
    {
        BuildTarget buildTarget = BuildTarget.Android;
        //首先从资源路径复制所有音效资源到更新路径
        string pltname = PackageUtils.GetPlatformName(buildTarget);

        //取得音效的原始路径
        string sourcePath = PackageUtils.GetAudioSourceDataPath(pltname);
        //资源输出路径
        string AssetsPath = PackageUtils.GetAssetBundleOutputPath(buildTarget, "Test");
        //需要复制到的资源路径
        string destPath = Path.Combine(AssetsPath, AssetBundleConfig.AssetBundlesAudioFolderName_GEN);

        //加入平台
        destPath = Path.Combine(destPath, pltname);
        // 有毒,竟然在有的windows系统这个函数删除不了目录,不知道是不是Unity的Bug
        // GameUtility.SafeDeleteDir(destination);
        destPath   = GameUtility.FormatToUnityPath(destPath);
        sourcePath = GameUtility.FormatToUnityPath(sourcePath);
        //如果文件夹下面有meta文件的时候无法删除文件夹,因为meta文件是隐藏文件,需要权限
        GameUtility.SafeDeleteDir(destPath);
        //检测目标路路径是否存在
        //GameUtility.CheckDirAndCreateWhenNeeded(destPath);
        Debug.Log("Audio dst Path:" + destPath);
        Debug.Log("Audio src Path:" + sourcePath);

        try
        {
            FileUtil.CopyFileOrDirectory(sourcePath, destPath);
            var allfiles = GameUtility.GetSpecifyFilesInFolder(sourcePath);
            if (allfiles != null && allfiles.Length > 0)
            {
                for (int i = 0; i < allfiles.Length; i++)
                {
                    if (allfiles[i].IndexOf(".meta") >= 0)
                    {
                        GameUtility.SafeDeleteFile(allfiles[i]);
                    }
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError("Something wrong: " + ex);
            return;
        }
    }