I am making a game with different levels. Each level is an additive scene having 2 sets of lightmaps, Day version and Night version. LightmapSettings will be updated after the scene is loaded.
[System.Serializable]
public class LightmapTextures
{
public Texture2D[] lights;
public Texture2D[] dirs;
public Texture2D[] shadows;
}
public class LightmapSwitch : MonoBehaviour
{
public LightmapTextures[] lightmaps;
public void SetLightMap(int index)
{
LightmapTextures lightmapTextures = lightmaps[1 - index]; // Setting mistake
LightmapData[] lightmapData = new LightmapData[lightmapTextures.lights.Length];
for(int i = 0; i < lightmapTextures.lights.Length; i++)
{
lightmapData[i] = new LightmapData();
lightmapData[i].lightmapColor = lightmapTextures.lights[i];
lightmapData[i].lightmapDir = lightmapTextures.dirs[i];
if (i < lightmapTextures.shadows.Length)
{
lightmapData[i].shadowMask = lightmapTextures.shadows[i];
}
}
LightmapSettings.lightmaps = lightmapData;
}
}
It works fine in the editor. When I build on Android, the lightmaps looks well in the beginning. But after some levels, the lightmaps will be broken until I restart the app.
Is there any setting mistake from my codes or my maps? Or is it caused by caching or out of memories?