summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/Scene/LightMapSetter.cs
blob: e9aea3bb3874b66cfdef5a5d72a81071a49be478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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<string>()).ToArray();
        LightMapFar = LightMapFar.OrderBy(t2d => t2d.name, new NaturalSortComparer<string>()).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;
    }
}