Unity导出android关于路径问题总结

来源:互联网 发布:统计怎么下载数据 编辑:程序博客网 时间:2024/06/06 04:20

(1)unity导出andriod时报错:Moving file failed,如下图,

解决:在导出的路径中已存在3456.apk了,且这个apk阻止修改!重命名导出的apk即可。

(2)在Android平台下,无法加载打包的文件(.assetbundle 、.unity3d、...),查看打包代码中是否写入了打包平台信息:

打包AssentBundle,最核心的方法:

BuildPipeline.BuildAssetBundle (obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies)

不过这是默认的电脑上打包的资源只可以电脑上用

安卓打包需要添加参数:

BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.Android);

Iphone打包也需要添加参数:
 BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.iPhone);

(3)Android平台下保存或者加载Assetbundle文件的路径

path="file:///"+Application.persistentDataPath+"/res_name";(Android/com.productname.company/files/,测试结果,该路径可读写数据)

path="jar:file://"+Application.datapath+"!/assets/***/res_name";(/mnt/sdcard/com.productname.company/pkg.apk!/assest/,测试结果,该路径仅读数据,并且只读文件必须放在文件夹StreamingAssets下,可在此目录下新建文件夹***)

用以下步骤进行在Android机子上使用AssetBundle:

参考地址:http://www.narkii.com/club/forum.php?mod=viewthread&tid=299447&extra=page%3D{prevpage}&page=1
重点有2点:
Use the option "BuildTarget.Android".
Describe the path with triple slash "file:///"
以下是步骤:

Delete directories "Per Texture Materials", "assetbundles", and so on.  把已经导出过的包删掉
Use the option "BuildTarget.Android" to all "BuildPipeline.BuildAssetBundle".   要把BuildTarget为Android平台!!!
Run these on Editor. Character Generator/Generate Materials Character Generator/Create Assetbundles Character Generator/Update Character Element Database  
Copy Assetbundles database to Android device which like "/mnt/sdcard/assetbundles/"  把这些包放到Android的指定目录下
Modify AssetbundleBaseURL. (the point was "file:///") 修改获取AssetbundleBaseURL基础路径的地址

代码:
public static string AssetbundleBaseURL
{
    get
    {
        if (Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
        {
            return Application.dataPath + "/assetbundles/";
        }
        else if (Application.platform == RuntimePlatform.Android)
        {
            return "file:///mnt/sdcard/assetbundles/";(这个路径本人测试了但是没成功)
        }
        else
        {
            return "file://" + Application.dataPath + "/../assetbundles/";
        }
    }
}

0 0
原创粉丝点击