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



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

由于我们在资源包方面没有太多经验,因此我们首先创建了一个非常简单的捆绑包文件(只有一些 Unity 基元和材质),然后我们首先尝试从 Unity 编辑器将它们加载到应用程序中。这正在按预期工作,但是当我们将应用程序部署到Hololens中时,它会失败。

这是我们的加载方法:

#if WINDOWS_UWP
public async void CallForBundles()
#else
public void CallForBundles()
#endif
{
string bundleFile = "--- NO BUNDLE ---";
#if UNITY_EDITOR
bundleFile = @"D:tempUnityBuildsAssetBundlesexportablebundle";
#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:buildslaveunitybuildRuntime/VirtualFileSystem/ArchiveFileSystem/ArchiveStorageReader.cpp Line: 542)

'Holoplan.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:DataUsersDefaultAccountAppDataLocalDevelopmentFilesHoloplanVS.Release_x86.jalfonsoSystem.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)

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

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

请问任何人都可以帮我们一把吗?

编辑-

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

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

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

抱歉,资产捆绑目前在 HL 设备中不起作用。这是必须修复的已知问题。

最新更新