从设备文件夹在 Hololens 上使用 Unity 3d 资产包 [英] Using Unity 3d asset bundles on Hololens from device folders

查看:31
本文介绍了从设备文件夹在 Hololens 上使用 Unity 3d 资产包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个 Hololens 应用程序,该应用程序将使用设备文件夹中的资产包,但在尝试加载包文件时出现无法打开存档文件"错误.

由于我们对资源包没有太多经验,因此我们通过创建一个非常简单的包文件(只有几个 Unity 基元和材质)开始此操作,我们首先尝试将它们从 Unity 编辑器加载到应用程序中.这按预期工作,但当我们将应用部署到 Hololens 时却失败了.

这是我们的加载方法:

#if WINDOWS_UWP公共异步无效 CallForBundles()#别的公共无效 CallForBundles()#万一{字符串 bundleFile = "--- 没有捆绑 ---";#if UNITY_EDITORbundleFile = @"D:\temp\UnityBuilds\AssetBundles\exportablebundle";#万一#if WINDOWS_UWPWindows.Storage.StorageFolder objectsFolder = Windows.Storage.KnownFolders.Objects3D;Windows.Storage.StorageFile bundleFilePointer = await objectsFolder.GetFileAsync("exportablebundle");bundleFile = bundleFilePointer.Path;#万一var myLoadedAB = AssetBundle.LoadFromFile(bundleFile);//来自myLoadedAB的即时捆绑组件//}

如您所见,这是非常简单的事情.我们根据平台通过不同的方法找到包路径(我们已经将这个系统用于文本文件、png 和其他文件)并且 UNITY_EDITOR 端正在工作.WINDOWS_UWP 只是在调用 AssetBundle.LoadFromFile(bundleFile); 时抛出此错误:

无法打开存档文件:C:/Data/Users/edata/3D Objects/exportablebundle(文件名:C:\buildslave\unity\build\Runtime/VirtualFileSystem/ArchiveFileSystem/ArchiveStorageReader.cpp 行:542)Holoplan.exe"(CoreCLR:CoreCLR_UWP_Domain):加载C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\HoloplanVS.Release_x86.jalfonso\System.Diagnostics.StackTrace.dll".跳过加载符号.模块已优化,调试器选项仅我的代码"已启用.NullReferenceException:未将对象引用设置为对象的实例.在 GameManager.d__1.MoveNext()--- 从上一个抛出异常的位置开始的堆栈跟踪结束 ---在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(对象状态)在 UnityEngine.UnitySynchronizationContext.WorkRequest.Invoke()在 UnityEngine.UnitySynchronizationContext.Exec()在 UnityEngine.UnitySynchronizationContext.ExecuteTasks()在 UnityEngine.UnitySynchronizationContext.$Invoke1(Int64 实例,Int64* args)在 UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)(文件名:<未知>行:0)

<块引用>

无法打开存档文件:C:/Data/Users/edata/3D Objects/exportablebundle"

似乎与即使在编辑器上运行时应用程序尝试加载具有错误文件名或路径的捆绑包时发生的错误相同,因此看起来由于某种原因AssetBundle.LoadFromFile"无法找到文件.我们在该行检查了 bundleFile,它包含正确的文件路径('C:\Data\Users\edata\3D Objects\exportablebundle',其中 'exportablebundle' 是包文件名),所以我们猜测 'AssetBundle.LoadFromFile' 有从 Hololens 本地文件夹读取时出现问题,但我们不知道如何解决此问题.

¿任何人都可以帮助我们吗?

编辑-

我们正在使用 Unity 手册资产包工作流程"中的示例代码构建我们的资产包.是这样的:

static void BuildAllAssetBundles(){string assetBundleDirectory = "Assets/AssetBundles";如果 (!Directory.Exists(assetBundleDirectory)){Directory.CreateDirectory(assetBundleDirectory);}BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);}

作为构建目标的StandaloneWindows"似乎是可用列表中最接近 hololens 的,所以我们选择了它.

解决方案

抱歉,资产捆绑目前不适用于 HL 设备.这是必须修复的已知问题.

We are building a Hololens app which is going to use asset bundles from the device folders, but we are getting a 'Unable to open archive file' error when trying to load the bundle files.

As we don't have much experience with asset bundles we started this by creating a very simple bundle file (just a few Unity primitives and materials) and we made a first try loading them into the app from the Unity editor. That is working as expected but it fails when we deploy the app into our Hololens.

This is our loading method:

#if WINDOWS_UWP
    public async void CallForBundles()
#else
    public void CallForBundles()
#endif
    {
        string bundleFile = "--- NO BUNDLE ---";
#if UNITY_EDITOR
        bundleFile = @"D:\temp\UnityBuilds\AssetBundles\exportablebundle";
#endif
#if WINDOWS_UWP
        Windows.Storage.StorageFolder objectsFolder = Windows.Storage.KnownFolders.Objects3D;
        Windows.Storage.StorageFile bundleFilePointer = await objectsFolder.GetFileAsync("exportablebundle");
        bundleFile = bundleFilePointer.Path;
#endif

        var myLoadedAB = AssetBundle.LoadFromFile(bundleFile);
        //instante bundle components from myLoadedAB//
    }

As you see is something very simple. We find the bundle path by different methods depending on the platform (we already used this system for text files, pngs and others) and the UNITY_EDITOR side is working. The WINDOWS_UWP is throwing this error just on the call to AssetBundle.LoadFromFile(bundleFile);:

Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle

(Filename: C:\buildslave\unity\build\Runtime/VirtualFileSystem/ArchiveFileSystem/ArchiveStorageReader.cpp Line: 542)


'Holoplan.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\HoloplanVS.Release_x86.jalfonso\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
NullReferenceException: Object reference not set to an instance of an object.
at GameManager.<CallForBundles>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at UnityEngine.UnitySynchronizationContext.WorkRequest.Invoke()
at UnityEngine.UnitySynchronizationContext.Exec()
at UnityEngine.UnitySynchronizationContext.ExecuteTasks()
at UnityEngine.UnitySynchronizationContext.$Invoke1(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 

(Filename: <Unknown> Line: 0)

"Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle"

seems to be the same error that happens when the app try to load a bunde with wrong file name or path even when running on the editor so it looks like that for some reason 'AssetBundle.LoadFromFile' can't locate de file. We checked the bundleFile at that line and it contains the right filepath ('C:\Data\Users\edata\3D Objects\exportablebundle' where 'exportablebundle' is the bundle file name), so we guess that 'AssetBundle.LoadFromFile' has issues when reading from the Hololens local folder but we don't have much idea about how to address this.

¿Anyone can lend us a hand, please?

EDIT-

We are building our asset bundle with the sample code from the Unity manual in 'Asset bundle workflow'. Is like this:

static void BuildAllAssetBundles(){
  string assetBundleDirectory = "Assets/AssetBundles";
  if (!Directory.Exists(assetBundleDirectory)){
    Directory.CreateDirectory(assetBundleDirectory);
  }

  BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None,  BuildTarget.StandaloneWindows);
}

'StandaloneWindows' as build target seems the closest to hololens from the available list so we went for it.

解决方案

Sorry, asset bundling isn't working in HL devices right now. It's known issue that has to be fixed.

这篇关于从设备文件夹在 Hololens 上使用 Unity 3d 资产包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆