private void AddOutline(VisiblitySet visiblitySet) { float top = size / 2f; float btm = -size / 2f; float left = -size / 2f; float right = size / 2f; Vector3 topLeft = transform.TransformPoint(new Vector3(left, top, 0f)); Vector3 topRight = transform.TransformPoint(new Vector3(right, top, 0f)); Vector3 btmLeft = transform.TransformPoint(new Vector3(left, btm, 0f)); Vector3 btmRight = transform.TransformPoint(new Vector3(right, btm, 0f)); visiblitySet.Segments.Add(new Segment(topRight, topLeft) { IsOutline = true }); visiblitySet.Segments.Add(new Segment(btmRight, topRight) { IsOutline = true }); visiblitySet.Segments.Add(new Segment(btmLeft, btmRight) { IsOutline = true }); visiblitySet.Segments.Add(new Segment(topLeft, btmLeft) { IsOutline = true }); }
public void RebuildShadow() { _visiblitySet = _visiblitySet ?? new VisiblitySet(); _visiblitySet.Clear(this); _meshFilter = _meshFilter ?? GetComponent <MeshFilter>(); AddSegments(_visiblitySet); _visiblitySet.PrepareSegments(); _visiblitySet.UpdateAngles(); _visiblitySet.Sweep(); _bounds = new Bounds(transform.position, new Vector3(size, size, size)); CreateShadowPolygonPoints(); Mesh mesh = _visiblitySet.CreateOrUpdateMesh(); if (_meshFilter != null) { _meshFilter.sharedMesh = mesh; } if (_drawGizmos) { Gizmos.color = Color.blue; Gizmos.DrawWireMesh(mesh, transform.position, transform.rotation); } }
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; }
private void AddSegments(VisiblitySet visiblitySet) { if (usePhysicsForShadowCasters) { _collider2DTracker.UpdateColliders(_visiblitySet.TopLeft, _visiblitySet.BottomRight, layerMask); } if (segmentGenerator == null) { Debug.LogError("No segment generator found!"); return; } foreach (Collider2D collider in _collider2DTracker.colliders) { segmentGenerator.AddColliderSegments(this, visiblitySet.Segments, collider); } AddOutline(visiblitySet); }
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; }
public void RebuildShadow() { _visiblitySet = _visiblitySet ?? new VisiblitySet(); _visiblitySet.Clear(this); _meshFilter = _meshFilter ?? GetComponent<MeshFilter>(); AddSegments(_visiblitySet); _visiblitySet.PrepareSegments(); _visiblitySet.UpdateAngles(); _visiblitySet.Sweep(); _bounds = new Bounds(transform.position, new Vector3(size, size, size)); CreateShadowPolygonPoints(); Mesh mesh = _visiblitySet.CreateOrUpdateMesh(); _meshFilter.sharedMesh = mesh; if (_drawGizmos) { Gizmos.color = Color.blue; Gizmos.DrawWireMesh(mesh, transform.position, transform.rotation); } }