I'm using asset bundles to load assets in my 3d application. I've kept the unity package on server and loading it on runtime. But when the asset prefab is loaded the lighting seems to go haywire, even when all the lighting parameters remain the same. There is also a problem with texture transparency when the prefab is instantiated. Following are the files I've used for Exporting and downloading asset bundles.
using UnityEngine;
using System.Collections;
using UnityEditor;
public class ExportAssetBundles : Editor {
[MenuItem("Assets/Build AssetBundle")]
static void ExportResource()
{
string path = "Assets/AssetBundle/myAssetBundle.unity3d";
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path,
BuildAssetBundleOptions.CollectDependencies
| BuildAssetBundleOptions.CompleteAssets,BuildTarget.Android);
}
}
For Downloading
using System;
using UnityEngine;
using System.Collections;
public class CachingLoadExample : MonoBehaviour {
public string BundleURL;
public string AssetName;
public int version;
void Start() {
StartCoroutine (DownloadAndCache());
}
IEnumerator DownloadAndCache (){
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate (bundle.mainAsset);
else
yield return new WaitForSeconds (0.5f);
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
}
In all there are two problems I'm facing right now. The scene objects are getting burned due to excessive light, when the original prefab works just fine. Second the transparency of material doesn't work when I'm changing it through scripts after everything has finished loading. If anyone has worked with assetbundle please contribute. Thank you.
↧