BakedLightmapKeeper.cs 864 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. namespace MTE
  3. {
  4. /// <summary>
  5. /// Make sure the lightmap data are correct at runtime.
  6. /// Unity somehow starts clear programmatically assigned lightMapIndex and lightmapScaleOffset when enter play mode.
  7. /// This class fixed the issue https://github.com/zwcloud/MeshTerrainEditor-issues/issues/209
  8. /// </summary>
  9. [ExecuteInEditMode]
  10. public class BakedLightmapKeeper : MonoBehaviour
  11. {
  12. public int lightMapIndex = -1;
  13. public Vector4 lightmapScaleOffset = new Vector4(1, 1, 0, 0);
  14. private void Awake()
  15. {
  16. var theRenderer = GetComponent<Renderer>();
  17. if (!theRenderer)
  18. {
  19. return;
  20. }
  21. theRenderer.lightmapIndex = lightMapIndex;
  22. theRenderer.lightmapScaleOffset = lightmapScaleOffset;
  23. }
  24. }
  25. }