Example #1
0
        public void LateUpdate()
        {
            _meshRenderer = _meshRenderer ?? GetComponent <MeshRenderer>();


            if (_meshRenderer != null && onlyUpdateWhenVisible && !_meshRenderer.isVisible)
            {
                return;
            }

            _visiblitySet = _visiblitySet ?? new VisiblitySet();

            // Can't rotate the lights at the moment
            transform.rotation = Quaternion.identity;

            Vector2 newPosition   = transform.position;
            Vector2 oldScreenSize = _screenSize;

            _screenSize = new Vector2(Screen.width, Screen.height);

            bool rebuild = updateOnEachUpdate;

            rebuild = rebuild || _screenSize != oldScreenSize || !Mathf.Approximately(size, _oldSize);
            rebuild = rebuild || !Mathf.Approximately(Camera.main.orthographicSize, _oldOrthographicSize);
            rebuild = rebuild || !Mathf.Approximately(Camera.main.fieldOfView, _oldFieldOfView);
            rebuild = rebuild || updateOnChangedLocation && !ShadowMathUtils.Approximately(_oldPosition, newPosition);
            rebuild = rebuild || updateWhenCollidersChange && GetHaveCollidersChanged();

            _oldSize = size;

            if (rebuild)
            {
                RebuildShadow();
                _oldOrthographicSize = Camera.main.orthographicSize;
                _oldFieldOfView      = Camera.main.fieldOfView;
            }
            else
            {
                if (updateUvs &&
                    !ShadowMathUtils.Approximately(Camera.main.transform.position, _oldCameraPosition))
                {
                    _visiblitySet.UpdateUvs();
                    _oldCameraPosition = Camera.main.transform.position;
                }
            }

            _oldPosition = newPosition;
        }
Example #2
0
        public void LateUpdate()
        {
            _visiblitySet = _visiblitySet ?? new VisiblitySet();

            // Can't rotate the lights at the moment
            transform.rotation = Quaternion.identity;

            Vector2 newPosition = transform.position;
            Vector2 oldScreenSize = _screenSize;
            _screenSize = new Vector2(Screen.width, Screen.height);

            bool rebuild = updateOnEachUpdate;
            rebuild = rebuild || _screenSize != oldScreenSize || !Mathf.Approximately(size, _oldSize);
            rebuild = rebuild || !Mathf.Approximately(Camera.main.orthographicSize, _oldOrthographicSize);
            rebuild = rebuild || updateOnChangedLocation && !ShadowMathUtils.Approximately(_oldPosition, newPosition);
            rebuild = rebuild || updateWhenCollidersChange && GetHaveCollidersChanged();

            _oldSize = size;

            if (rebuild)
            {
                RebuildShadow();
                _oldOrthographicSize = Camera.main.orthographicSize;
            }
            else
            {
                if (updateUvs
                    && !ShadowMathUtils.Approximately(Camera.main.transform.position, _oldCameraPosition))
                {
                    _visiblitySet.UpdateUvs();
                    _oldCameraPosition = Camera.main.transform.position;
                }
            }

            _oldPosition = newPosition;
        }