From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/Scene/LightMapSetter.cs | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Client/Assets/Scripts/Scene/LightMapSetter.cs (limited to 'Client/Assets/Scripts/Scene/LightMapSetter.cs') diff --git a/Client/Assets/Scripts/Scene/LightMapSetter.cs b/Client/Assets/Scripts/Scene/LightMapSetter.cs new file mode 100644 index 00000000..e9aea3bb --- /dev/null +++ b/Client/Assets/Scripts/Scene/LightMapSetter.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +using System.Linq; +using System; + +public class LightMapSetter : MonoBehaviour +{ + public Texture2D[] LightMapNear; + public Texture2D[] LightMapFar; + + private LightmapData[] lightMaps; + + void Awake() + { + //if (LightMapNear.Length != LightMapFar.Length) + //{ + // Debug.Log("In order for LightMapSwitcher to work, the Near and Far LightMap lists must be of equal length"); + // return; + //} + + // Sort the Day and Night arrays in numerical order, so you can just blindly drag and drop them into the inspector + LightMapNear = LightMapNear.OrderBy(t2d => t2d.name, new NaturalSortComparer()).ToArray(); + LightMapFar = LightMapFar.OrderBy(t2d => t2d.name, new NaturalSortComparer()).ToArray(); + + // Put them in a LightMapData structure + int MaxLightMapLength = Math.Max(LightMapFar.Length, LightMapNear.Length); + if (MaxLightMapLength == 0) + { + lightMaps = null; + return; + } + + lightMaps = new LightmapData[MaxLightMapLength]; + for (int i = 0; i < MaxLightMapLength; i++) + { + lightMaps[i] = new LightmapData(); + lightMaps[i].lightmapDir = (i < LightMapNear.Length ? LightMapNear[i] : null); + lightMaps[i].lightmapColor = (i < LightMapFar.Length ? LightMapFar[i] : null); + } + } + + public void SetLightMap() + { + if (lightMaps != null) + LightmapSettings.lightmaps = lightMaps; + } +} \ No newline at end of file -- cgit v1.1-26-g67d0