Advertisement
LittleAngel

LightMapToggle

Apr 11th, 2012
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [System.Serializable]
  5. public class TimeSettings {
  6. public string lightMap;
  7. public Material skyBoxMat;
  8. public bool fogToggle;
  9. public Color ambientLight;
  10. }
  11.  
  12. public class StartUpSettings : MonoBehaviour {
  13. public TimeSettings day;
  14. public TimeSettings night;
  15. private TimeSettings currentTimeSettings;
  16. private bool isDay;
  17.  
  18. void Start () {
  19. Screen.lockCursor = true;
  20. isDay = true;
  21. SetLightMaps ();
  22. }
  23.  
  24. void Update () {
  25. if (Input.GetKeyDown ("q")) {
  26. SetLightMaps ();
  27. }
  28. }
  29.  
  30. void SwapLightMaps () {
  31. }
  32.  
  33. void SetLightMaps () {
  34. // Set the CurrentTimeSettings
  35. currentTimeSettings = (isDay) ? day : night;
  36.  
  37. // Set the RenderSettings to match the CurrentTimeSettings
  38. RenderSettings.skybox = currentTimeSettings.skyBoxMat;
  39. RenderSettings.fog = currentTimeSettings.fogToggle;
  40. RenderSettings.ambientLight = currentTimeSettings.ambientLight;
  41.  
  42. // Load the light maps from the Resources folder
  43. // Pass in the path to the location of the lightmaps, starting below the "Resources" folder.
  44. LightmapData[] lightMapArray = LightmapSettings.lightmaps;
  45. for (int i = 0; i < lightMapArray.Length; i++) {
  46. LightmapData mapData = new LightmapData();
  47. mapData.lightmapFar = Resources.Load(currentTimeSettings.lightMap + "/LightmapColor-" + i.ToString(), typeof (Texture2D)) as Texture2D;
  48. mapData.lightmapNear = Resources.Load(currentTimeSettings.lightMap + "/LightmapScale-" + i.ToString(), typeof (Texture2D)) as Texture2D;
  49. lightMapArray[i] = mapData;
  50. }
  51. LightmapSettings.lightmaps = lightMapArray;
  52. isDay = !isDay;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement