I won't be able to try the new version since I'm heading out to vacation for a week and NOT taking my laptop :)
But I did get it to work with the following scripts:
First I made a new class that save the index and coordinates of the lightmap.
public class LightmapParam : MonoBehaviour {
public int lightmapIndex;
public Vector4 lightmapScaleOffset;
}
I build the asset using this script, making sure to add a LIghtmapParam to each object that has a renderer. And manually adding the lightmaps to the assetBundle
private void BuildAssetBundle(){
GameObject assetParent = new GameObject();
assetParent.name = assetName;
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType() ;
foreach(GameObject obj in allObjects){
if(assetParent != obj){
obj.transform.SetParent(assetParent.transform, true);
Renderer r = obj.GetComponent();
if(r != null){
LightmapParam lmp = obj.GetComponent();
if(lmp == null)
lmp = obj.AddComponent();
lmp.lightmapIndex = r.lightmapIndex;
lmp.lightmapScaleOffset = r.lightmapScaleOffset;
}
}
}
string path = "Assets/AssetPrefabs/" + assetName + ".prefab";
PrefabUtility.CreatePrefab(path, assetParent, ReplacePrefabOptions.ReplaceNameBased);
Debug.Log("prefab " + path);
//AssetBundleBuild[] abb = new AssetBundleBuild[1];
//abb[0].assetBundleName = assetName;
//abb[0].assetNames = new string[]{ path};
//BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", abb);
string curScene = EditorApplication.currentScene;
string[] parts = curScene.Split('/', '\\');
string sceneName = parts[parts.Length - 1].Split('.')[0];
string lightmapPath = Path.GetDirectoryName(curScene) + "/" + sceneName + "/";
List assetList = new List();
for(int i = 0; i < LightmapSettings.lightmaps.Length; i++){
LightmapData lmd = LightmapSettings.lightmaps[i];
string lmp = lightmapPath + "Lightmap-" + i + "_comp_light.exr";
assetList.Add(lmp );
Debug.Log(lmp + " " + File.Exists(lmp));
}
Debug.Log(assetList[0] + " " + assetList.Count);
//string path = "Assets/AssetPrefabs/" + assetName + ".prefab";
assetList.Add(path);
AssetBundleBuild[] abb = new AssetBundleBuild[1]; // *************************************** lightmaps 2
abb[0].assetNames = assetList.ToArray();// new string[]{ path}; // create asset bundle from this prefab
// build mac
Debug.Log("make osx bundle");
abb[0].assetBundleName = assetName + "_osx.unity3d";
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", abb, BuildAssetBundleOptions.None, BuildTarget.StandaloneOSXUniversal);
}
Then when I'm loading the assetBundle I'm looking for the lightmapParam and assigning the values. and assigning the actual maps to the lightmapSettings.
AssetBundle bundle = www.assetBundle;
Object[] objects = bundle.LoadAllAssets
↧