从设备文件夹在 Hololens 上使用 Unity 3d 资产包

Using Unity 3d asset bundles on Hololens from device folders

我们正在构建一个 Hololens 应用程序,它将使用设备文件夹中的资产包,但在尝试加载包文件时出现 'Unable to open archive file' 错误。

由于我们对资产包没有太多经验,我们首先创建了一个非常简单的包文件(只有一些 Unity 原语和材质),然后我们第一次尝试从 Unity 编辑器将它们加载到应用程序中.这按预期工作,但当我们将应用程序部署到我们的 Hololens 时它失败了。

这是我们的加载方法:

#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//
    }

如您所见,事情很简单。我们根据平台通过不同的方法找到包路径(我们已经将这个系统用于文本文件、png 和其他文件)并且 UNITY_EDITOR 端正在工作。 WINDOWS_UWP 仅在调用 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"

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

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

编辑-

我们正在使用 'Asset bundle workflow' 中 Unity 手册中的示例代码构建我们的资产包。是这样的:

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

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

'StandaloneWindows' 因为构建目标似乎是可用列表中最接近全息镜头的,所以我们选择了它。

抱歉,资产捆绑目前无法在 HL 设备中使用。这是一个必须解决的已知问题。