【发布时间】:2019-10-13 22:50:27
【问题描述】:
我们正在构建一个 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:\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)
“无法打开存档文件:C:/Data/Users/edata/3D Objects/exportablebundle”
似乎与应用程序尝试加载具有错误文件名或路径的捆绑包时发生的错误相同,即使在编辑器上运行也是如此,因此看起来由于某种原因“AssetBundle.LoadFromFile”无法找到 de 文件.我们在该行检查了 bundleFile,它包含正确的文件路径('C:\Data\Users\edata\3D Objects\exportablebundle' 其中 'exportablebundle' 是包文件名),所以我们猜测 '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,因此我们选择了它。
【问题讨论】:
-
尝试在路径中使用反斜杠。
-
assetbundle 是否与 UWP 兼容?我不确定,但您可能需要正确的文件结尾?捆绑包是如何创建的?
-
@derHugo 在“编辑”标题下的原始帖子中找到澄清
-
HoloLens 是
WSAPlayer(WSA 代表 Windows Store App).. 尝试使用它,看看是否有帮助
标签: unity3d hololens assetbundle