本文介绍了如何使用WWW将本地文件作为AssetBundle加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在尝试使用户可以加载.obj文件并将其读取为AssetBundle,但我无法弄清楚.

So I have been trying to make it possible for users to load a .obj file and read it as an AssetBundle, but I can't figure it out.

我已经弄清楚了如何获取文件的路径,但是我无法将其作为资产捆绑包加载,它只会返回null.

I have figured out how to get the path of the file, but I can't load it as an asset bundle, it just returns null.

这是我的代码:

        WWW bundleRequest = new WWW(@"file://" + pathName);

        while (!bundleRequest.isDone)
        {
            yield return null;
        }

        AssetBundle bundle = null;
        if (bundleRequest.bytesDownloaded > 0)
        {
            AssetBundleCreateRequest myRequest = AssetBundle.LoadFromMemoryAsync(bundleRequest.bytes);
            while (!myRequest.isDone)
            {
                Debug.Log("loading....");
                yield return null;
            }
            if (myRequest.assetBundle != null)
            {
                bundle = myRequest.assetBundle;
                GameObject model = null;
                if (bundle != null)
                {
                    AssetBundleRequest newRequest = bundle.LoadAssetAsync<GameObject>("Test");
                    while (!newRequest.isDone)
                    {
                        Debug.Log("loading ASSET....");
                        yield return null;
                    }
                    model = (GameObject)newRequest.asset;

                    bundle.Unload(false);
                }
            }
            else
            {
                Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL");
            }
        }
        else
        {
            Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL");
        }

pathName在这里是:"C:\\Users\\mySuperCoolName\\OneDrive\\Documents\\Fun\\Programming\\Ungoing projects\\ThiefCop\\Unity Mobile\\Assets\\Prefabs\\TestOBJ.obj".直到AssetBundleCreateRequest调用AssetBundle.LoadFromMemoryAsync()为止,一切都似乎可以正常工作,即使正确下载 文件也没有问题.

pathName here is: "C:\\Users\\mySuperCoolName\\OneDrive\\Documents\\Fun\\Programming\\Ungoing projects\\ThiefCop\\Unity Mobile\\Assets\\Prefabs\\TestOBJ.obj". Everything seems to work until AssetBundleCreateRequest when AssetBundle.LoadFromMemoryAsync() is called, where myRequest.assetBundle == null even if the file was downloaded correctly.

我也收到可能与我的问题有关的错误:
我已经搜索了它的含义,但找不到...

I also get an error which probably is linked with my problem :
I have searched for what it meant but I couldn't find...

真的很难解释我的意思,但是我真的希望你能找到答案.我已经搜索了几个小时,而且在我们之间,我对File loadind和Reading的了解不多...

请不要犹豫,问您是否听懂我的英语不好...

谢谢您:)

It is really hard to explain what I mean, but I really hope you can find an answer to this, I've been searching for hours and between us, I don't understand much of File loadind and Reading...

Don't hesitate to ask if you didn't understand my bad english...

Thank you in advance :)

推荐答案

https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundles.html

简而言之:

  • 将对象导入Unity
  • 给它一个AssetBundle名称(单击它,然后在检查器视图的底部)
  • 调用此功能

这篇关于如何使用WWW将本地文件作为AssetBundle加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:41