繁体   English   中英

在HoloLens上加载资产仅在Unity中有效吗?

[英]Loading an asset on HoloLens only works in Unity?

我正在开发一个HoloLens-Application,该应用程序从其内部存储器加载资产。 目前,我只能访问仿真器而不是设备。

    try
    {
        //for unity: replaced with string path = @"C:\Users\root\Desktop\cube";
        string path = Path.Combine(Application.persistentDataPath, "cube.unity3d");
        if (File.Exists(path))
        {
            //Using the example code
            myLoadedAssetBundle = AssetBundle.LoadFromFile(path);
            if (myLoadedAssetBundle == null)
            {
                Debug.Log("Failed to load AssetBundle!");
                return;
            }
            var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("cube");
            Instantiate(prefab);
            myLoadedAssetBundle.Unload(false);
        }
        else
        {
            //do nothing
        }
    }
    catch (Exception ex)
    {
        //never reached during all tests
        Debug.Log(ex.Message);
    }

当我整体按下播放按钮时,将显示该多维数据集,但是当我在HoloLens仿真器中运行该程序时,它将无法正常工作。 该文件存在,但myLoadedAssetBundle始终为null。 在Unity中,我使用了桌面路径,而在hololens上运行时,我在代码中使用了路径。 可以访问所有文件。 甚至以下情况也可以:

//called after creating the string path
File.WriteAllText(path + ".txt", "This is a test");

我不知道可能是什么问题。 该文件始终在路径中(我在FileExplorer中上传了文件),并且找到了它。 我的桌面上的文件与模拟器中上传的文件完全相同。

它有可能在HoloLens上运行但不在模拟器上运行吗?

更新:

现在,我还在具有相同问题的真实HoloLens上进行了尝试。 我正在使用Unity 2017.1.0f3

我也为此挣扎了一段时间。

我发现它与资产捆绑包的导出方式有关。 例子倾向于表明这一点-

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

但是,要在HoloLens中工作,就需要像这样导出它们-

BuildPipeline.BuildAssetBundles(assetBundleDirectory, buildMap, BuildAssetBundleOptions.None, BuildTarget.WSAPlayer);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM