Exemplo n.º 1
0
        private void Start()
        {
            List <LightWithId>[] lightsWithId = _lightManager.GetPrivateField <List <LightWithId>[]>("_lights");
            int maxLightId = _lightManager.GetPrivateField <int>("kMaxLightId");

            _lights = new List <Light> [maxLightId + 1];

            for (int id = 0; id < lightsWithId.Length; id++)
            {
                if (lightsWithId[id] == null)
                {
                    continue;
                }

                foreach (LightWithId lightWithId in lightsWithId[id])
                {
                    Vector3 direction = kOrigin - lightWithId.transform.position;

                    var light = new GameObject("DynamicLight").AddComponent <Light>();

                    light.type        = LightType.Directional;
                    light.color       = Color.black;
                    light.shadows     = LightShadows.None;           // shadows murder fps since there's so many lights being added
                    light.renderMode  = LightRenderMode.ForceVertex; // reduce performance toll
                    light.intensity   = 1f / (direction.sqrMagnitude * 5);
                    light.spotAngle   = 45;
                    light.cullingMask = AvatarLayers.kAllLayersMask;

                    light.transform.SetParent(lightWithId.transform);
                    light.transform.localPosition = Vector3.zero;
                    light.transform.rotation      = Quaternion.LookRotation(direction);

                    if (_lights[id] == null)
                    {
                        _lights[id] = new List <Light>(10);
                    }

                    _lights[id].Add(light);
                }
            }

            _logger.Trace($"Created {_lights.Sum(l => l?.Count)} lights");
            _logger.Trace($"Maximum intensity: {_lights.Where(l => l != null).SelectMany(l => l).Sum(l => l.intensity)}");

            AddPointLight(_colorManager.ColorForSaberType(SaberType.SaberA), _playerController.leftSaber.transform);
            AddPointLight(_colorManager.ColorForSaberType(SaberType.SaberB), _playerController.rightSaber.transform);
        }
Exemplo n.º 2
0
        private void CreateLights()
        {
            List <ILightWithId>[] lightsWithId = _lightManager.GetPrivateField <List <ILightWithId>[]>("_lights");
            int maxLightId = _lightManager.GetPrivateField <int>("kMaxLightId");

            _lights = new List <DynamicTubeBloomPrePassLight> [maxLightId + 1];

            for (int id = 0; id < lightsWithId.Length; id++)
            {
                if (lightsWithId[id] == null)
                {
                    continue;
                }

                foreach (ILightWithId lightWithId in lightsWithId[id])
                {
                    if (lightWithId is TubeBloomPrePassLightWithId tubeLightWithId)
                    {
                        TubeBloomPrePassLight tubeLight = tubeLightWithId.GetPrivateField <TubeBloomPrePassLight>("_tubeBloomPrePassLight");

                        DynamicTubeBloomPrePassLight light = _container.InstantiateComponent <DynamicTubeBloomPrePassLight>(new GameObject($"DynamicTubeBloomPrePassLight({tubeLight.name})"), new[] { tubeLight });

                        if (_lights[id] == null)
                        {
                            _lights[id] = new List <DynamicTubeBloomPrePassLight>(10);
                        }

                        _lights[id].Add(light);

                        light.transform.parent   = transform;
                        light.transform.position = Vector3.zero;
                        light.transform.rotation = Quaternion.identity;
                    }
                }
            }

            _logger.Trace($"Created {_lights.Sum(l => l?.Count)} DynamicTubeBloomPrePassLights");
        }