从Android手机中的Web服务器导入资产包

时间:2022-11-21 16:23:25

In Unity, I am creating an asset bundle and am loading that assets from server and am running that app in Android. Now the problem was asset bundle can't be loaded in Android device, but it was loaded in Editor. Can anyone give me a suggestion to load assets bundle in Android?

在Unity中,我正在创建资产包并从服务器加载该资产,并在Android中运行该应用程序。现在问题是资产包无法在Android设备中加载,但它已在编辑器中加载。任何人都可以给我一个在Android中加载资产包的建议吗?

3 个解决方案

#1


0  

You have to build assetbundles according to the platform you're using. Check this link for Assetbundles buildtarget

您必须根据您使用的平台构建assetbundles。查看Assetbundles buildtarget的此链接

Change the BuildTarget.TargetPlatformCheck the build targets here

在此处更改BuildTarget.TargetPlatformCheck构建目标

#2


0  

I created assetbundles using this code

我使用此代码创建了assetsbundles

public class creatinassets : MonoBehaviour {

[MenuItem ("Assets/Build AssetBundles")]
static void BulidAllAssetBundles()
{
    BuildPipeline.BuildAssetBundles("Assets/Asset bundles",BuildAssetBundleOptions.None, BuildTarget.Android );
}

I loaded the bundle using following code

我使用以下代码加载了包

public class loading : MonoBehaviour {
public GameObject cub;
public WWW www;

void Start()
{
    StartCoroutine ("Downloadobject");
}   
IEnumerator Downloadobject()
{
    www = WWW.LoadFromCacheOrDownload  ("http://192.168.1.126/gopinath/AssetBundles/light",3);// light= Assetbundlename
    yield return www;

    AssetBundle bundle = www.assetBundle;
    if (bundle == null) {
        Debug.Log ("error loading www");
    } else {

         cub = (GameObject)bundle.LoadAsset ("lamp"); //lamp = Assetname   
        Instantiate (cub);

    }
}

}

}

#3


0  

From the code you have posted, the problem seems to be with the download. Check for www errors. Also check the link from your phone's browser.

从您发布的代码中,问题似乎与下载有关。检查www错误。同时检查手机浏览器中的链接。

  if(www.error)
  {
   Debug.Log(www.error)
  }

#1


0  

You have to build assetbundles according to the platform you're using. Check this link for Assetbundles buildtarget

您必须根据您使用的平台构建assetbundles。查看Assetbundles buildtarget的此链接

Change the BuildTarget.TargetPlatformCheck the build targets here

在此处更改BuildTarget.TargetPlatformCheck构建目标

#2


0  

I created assetbundles using this code

我使用此代码创建了assetsbundles

public class creatinassets : MonoBehaviour {

[MenuItem ("Assets/Build AssetBundles")]
static void BulidAllAssetBundles()
{
    BuildPipeline.BuildAssetBundles("Assets/Asset bundles",BuildAssetBundleOptions.None, BuildTarget.Android );
}

I loaded the bundle using following code

我使用以下代码加载了包

public class loading : MonoBehaviour {
public GameObject cub;
public WWW www;

void Start()
{
    StartCoroutine ("Downloadobject");
}   
IEnumerator Downloadobject()
{
    www = WWW.LoadFromCacheOrDownload  ("http://192.168.1.126/gopinath/AssetBundles/light",3);// light= Assetbundlename
    yield return www;

    AssetBundle bundle = www.assetBundle;
    if (bundle == null) {
        Debug.Log ("error loading www");
    } else {

         cub = (GameObject)bundle.LoadAsset ("lamp"); //lamp = Assetname   
        Instantiate (cub);

    }
}

}

}

#3


0  

From the code you have posted, the problem seems to be with the download. Check for www errors. Also check the link from your phone's browser.

从您发布的代码中,问题似乎与下载有关。检查www错误。同时检查手机浏览器中的链接。

  if(www.error)
  {
   Debug.Log(www.error)
  }