I have only a scene for my game - it’s easier to edit the whole game, and the transitions between screens are instantaneous. But now after I’ve switched to Unity 5, I can’t make 2 lightmaps for different levels in the same scene.
Did anyone find a simple workaround for this problem?
No matter how many lightmaps I bake, the same LightmapSnapshot keeps overriding all the light settings from the scene.
It should work with Baked GI only. If the scene contains Realtime GI also, it will not work.
I only want Baked GI. The problem is that Baked Selected button is gone in Unity 5. So I enable and disable different maps and only bake them. After I bake a map, I move the texture and the LightmapSnapshot in a different folder, and rebake a different map.
On each map I have a script that changes the current lightmap:
using UnityEngine;
[ExecuteInEditMode]
public class LightmapEnable : MonoBehaviour
{
public Texture2D lightmapFar;
public Texture2D lightmapNear;
private LightmapData[] _lightmapDatas;
public LightmapData[] lightmapDatas
{
get
{
if ((lightmapFar != null || lightmapNear != null) && _lightmapDatas == null)
{
_lightmapDatas = new[] { new LightmapData { lightmapFar = lightmapFar, lightmapNear = lightmapNear } };
}
return _lightmapDatas;
}
}
void OnEnable()
{
LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional;
if (lightmapDatas != null)
LightmapSettings.lightmaps = lightmapDatas;
}
void OnDisable()
{
if (LightmapSettings.lightmaps.Length > 0 && lightmapDatas != null && LightmapSettings.lightmaps[0].lightmapFar == lightmapDatas[0].lightmapFar)
LightmapSettings.lightmaps = null;
}
}
This worked in Unity 4.x but it does not work anymore in Unity 5.
I guess the UV info is lost once a new bake is done in the scene.
If you find a simple solution, let me know.