static internal int checkDelegate(IntPtr l, int p, out UnityEngine.Experimental.GlobalIllumination.Lightmapping.RequestLightsDelegate ua)
        {
            int op = extractFunction(l, p);

            if (LuaDLL.lua_isnil(l, p))
            {
                ua = null;
                return(op);
            }
            else if (LuaDLL.lua_isuserdata(l, p) == 1)
            {
                ua = (UnityEngine.Experimental.GlobalIllumination.Lightmapping.RequestLightsDelegate)checkObj(l, p);
                return(op);
            }
            if (LuaDLL.lua_isnil(l, -1))
            {
                ua = null;
                return(op);
            }
            LuaDelegate ld;

            checkType(l, -1, out ld);
            LuaDLL.lua_pop(l, 1);
            if (ld.d != null)
            {
                ua = (UnityEngine.Experimental.GlobalIllumination.Lightmapping.RequestLightsDelegate)ld.d;
                return(op);
            }

            l  = LuaState.get(l).L;
            ua = (UnityEngine.Light[] a1, Unity.Collections.NativeArray <UnityEngine.Experimental.GlobalIllumination.LightDataGI> a2) =>
            {
                int error = pushTry(l);

                pushValue(l, a1);
                pushValue(l, a2);
                ld.pcall(2, error);
                LuaDLL.lua_settop(l, error - 1);
            };
            ld.d = ua;
            return(op);
        }
    // Inverse Square Falloff for the progressive lightmapper - Code from https://docs.unity3d.com/Manual/ProgressiveLightmapper-CustomFallOff.html
    public void OnEnable()
    {
        UnityEngine.Experimental.GlobalIllumination.Lightmapping.RequestLightsDelegate testDel = (Light[] requests, Unity.Collections.NativeArray <LightDataGI> lightsOutput) => {
            DirectionalLight dLight = new DirectionalLight();
            PointLight       point  = new PointLight();
            SpotLight        spot   = new SpotLight();
            RectangleLight   rect   = new RectangleLight();
            LightDataGI      ld     = new LightDataGI();

            for (int i = 0; i < requests.Length; i++)
            {
                Light l = requests[i];
                switch (l.type)
                {
                case UnityEngine.LightType.Directional:
                    LightmapperUtils.Extract(l, ref dLight);
                    ld.Init(ref dLight);
                    break;

                case UnityEngine.LightType.Point:
                    LightmapperUtils.Extract(l, ref point);
                    ld.Init(ref point);
                    break;

                case UnityEngine.LightType.Spot:
                    LightmapperUtils.Extract(l, ref spot);
                    ld.Init(ref spot);
                    break;

                case UnityEngine.LightType.Area:
                    LightmapperUtils.Extract(l, ref rect);
                    ld.Init(ref rect);
                    break;

                default:
                    ld.InitNoBake(l.GetInstanceID());
                    break;
                }

                ld.falloff      = bakedLightsFalloff;
                lightsOutput[i] = ld;
            }
        };

        UnityEngine.Experimental.GlobalIllumination.Lightmapping.SetDelegate(testDel);
    }