private void Update() { if (targets.Count > 0) { Bounds totalBounds = targets[0].GetTotalBounds(Space.World); for (int i = 1; i < targets.Count; i++) { totalBounds = totalBounds.Combine(targets[i].GetTotalBounds(Space.World)); } Vector3 startPosition = totalBounds.min.ProjectPointToSurface(totalBounds.center, targetNormal); Vector3 endPosition = totalBounds.max.ProjectPointToSurface(totalBounds.center, targetNormal); Vector3 connectingLine = (endPosition - startPosition).Planar(targetNormal); Vector3 cameraDirection = Vector3.Cross(targetNormal, connectingLine.normalized); float cameraDistance = attachedCamera.PerspectiveDistanceFromWidth((totalBounds.max - totalBounds.min).magnitude); transform.forward = -cameraDirection; transform.position = totalBounds.center + cameraDirection * cameraDistance; } }
public void RecalculateCachedShadowBounds() { cachedShadowBounds = Bounds.InfiniteInverse; if (shadowLayers != null) { foreach (var shadowLayer in shadowLayers) { var shadowSprite = shadowLayer.shadowSpriteRef.ResolveRequire(); if (shadowSprite.texture != null) { var bounds = new Bounds(shadowSprite.WorldSpaceBounds); cachedShadowBounds = cachedShadowBounds.Combine(bounds); } } } if (!cachedShadowBounds.IsValid) { cachedShadowBounds = default(Bounds); } }