- Home /
Unity5: Export Asset Bundle with Lightmaps
I used to be able to export lightmaps using the following code, but with the new Enlighten there seem to be no more lightmap assets to package.
Any idea how to do it now?
// Bring up save panel
string path = EditorUtility.SaveFilePanel("Save Resource", lastDir, "unnamed", "unity3d");
if (path.Length != 0)
{
lastDir = System.IO.Path.GetDirectoryName(path);
// Build the resource file from the active selection.
List<Object> selection = new List<Object>(Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets));
string curScene = EditorApplication.currentScene;
string[] parts = curScene.Split('/', '\\');
curScene = parts[parts.Length - 1].Split('.')[0];
foreach (Texture2D tex in Object.FindObjectsOfTypeIncludingAssets(typeof(Texture2D)))
if (tex.name.StartsWith("Lightmap"))
{
string[] p = AssetDatabase.GetAssetPath(tex).Split('/', '\\');
if ((p.Length > 1) && ((p[p.Length - 2] == curScene) || (p[p.Length - 2] == "anyscene"))) // if it is a lightmap for the current (or any) scene
selection.Add(tex);
}
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection.ToArray(), path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, platform);
Selection.objects = selection.ToArray();
}
Answer by frevd · Mar 21, 2015 at 08:29 PM
Apparently I can get the textures directly from LightmapSettings.lightmaps and then, since they are no assets, use AssetDatabase.Create to save them as files..
Except that those textures are in an internal format and not marked as readable, so I cannot save and load or re-encode them in another format.
Does anybody have any idea how to export Lightmaps? Unity5 breaks my project for no reason.
same problem here. Looking for a solution. Did you find a work around?
Your answer
Follow this Question
Related Questions
How the heck can I include Lightmapping data in unity 5 asset bundles??? 3 Answers
Using the Lightmap UV texcoords in a Unity 5 Surface Shader? 1 Answer
Upgrading from 4 to 5 0 Answers
SetTexture Not Working In Unity 5 1 Answer
Problem to go to another world scene in level select lock/unlock 0 Answers