Hololens——Assetbundle处理

来源:互联网 发布:moga算法 编辑:程序博客网 时间:2024/06/05 19:44

说明:

最近尝试使用了Hololens进行了Unity AssetBoundle联网下载及加载,测试证明:Hololens也支持对Assetbundle的使用,哈哈哈哈啊哈。。。

使用AssetBoundle打包的一个小坑

在进行资源打包时,按照assetbundle的官方说明,一个平台下处理出来的assetbundle文件只能使用于同一个平台,如:iOS只能使用于iOS系列平台;由于之前一直处理的只有PC、android、iOS平台,没接触过Hololens平台的资源打包,于是走了很多冤枉路:

错误的打包平台:

打包了很多错误的平台如:——主要想试试这些平台是否在新的平台上能否存在兼容的清空,然而并不是
  1. standalonewindows
  2. standalonewindows64
  3. WP8
  4. .....

正确的打包平台:

Hololens属于UWP平台,在打包时需要选择WSA平台,WSA——Windows Store App

资源加载

资源加载和之前地加载方式一致,没有什么特殊性,这里加载出的资源需要设置一下位置,一般情况放在摄像机前面2——3米,适合Hololens查看。
代码如下:
using UnityEngine;using System.Collections;public class TEST : MonoBehaviour{    void Start()    {        StartCoroutine(LoadAssetBundleAsset("你的服务器地址/foxiangwsaplayer_5_1.assetbundle"));    }    AssetBundle myAssetBundle;    IEnumerator LoadAssetBundleAsset(string abURL)    {        WWW www = WWW.LoadFromCacheOrDownload(abURL, 5);        yield return www;        if (www.error != null)        {            Debug.Log(www.error);        }        else        {            myAssetBundle = www.assetBundle;            var request = myAssetBundle.LoadAllAssets(typeof(GameObject))[0];//*********默认加载第一个*********测试所用            yield return request;            GameObject modle = request as GameObject;            myAssetBundle.Unload(false);            var obj = GameObject.Instantiate(modle);            obj.transform.localPosition = new Vector3(0, 0, 2);            obj.transform.localScale = new Vector3(1, 1, -1);        }    }}

pc上加载如下所示:


Hololens测试如下所示:



Hololens下载assetbundle提示:

starting www download: http://Da/XXQQ_asset/XXQQ/TestHololens/H_5_5/foxiangstandalonewindows_5.5.assetbundleCapability 'internetClient' is required, please enable it in Package.appxmanifest because you're using WWW functionality. (Filename: C:\buildslave\unity\build\PlatformDependent/MetroPlayer/MetroCapabilities.cpp Line: 126)loading from cache: http://Da/XXQQ_asset/XXQQ/TestHololens/H_5_5/foxiangstandalonewindows_5.5.assetbundle

Hololens assetbundle版本不对提示:

The file can not be loaded because it was created for another build target that is not compatible with this platform.Please make sure to build AssetBundles using the build target platform that it is used by.File's Build target is: 5 (Filename: C:/buildslave/unity/build/Runtime/Serialize/SerializedFile.cpp Line: 1049)The AssetBundle 'http://Da/XXQQ_asset/XXQQ/TestHololens/H_5_5/foxiangstandalonewindows_5.5.assetbundle' can't be loaded because it was not built with the right version or build target. (Filename: C:\buildslave\unity\build\Runtime/AssetBundles/AssetBundleLoadFromAsyncOperation.cpp Line: 420)

版本不对解决方法:

使用对应的Unity版本打包,打包平台选择——WSA

0 0
原创粉丝点击