/// <summary> /// Creates the matcher for a background actor with the provided metadata and renderer. /// Will return null in case matcher is not required based on the actor configuration. /// </summary> public static BackgroundMatcher CreateFor(BackgroundMetadata metadata, TransitionalRenderer renderer) { if (renderer is TransitionalSpriteRenderer spriteRenderer && metadata.MatchMode != CameraMatchMode.Disable) { var cameraManager = Engine.GetService <ICameraManager>(); var matcher = new BackgroundMatcher(cameraManager, spriteRenderer, metadata); matcher.Start(); return(matcher); } return(null); }
private void PrepareRenderTexture(Vector2 drawDimensions, TransitionalRenderer renderer) { var requiredSize = new Vector2Int(Mathf.RoundToInt(drawDimensions.x), Mathf.RoundToInt(drawDimensions.y)); if (CurrentTextureValid()) { return; } if (renderTexture) { RenderTexture.ReleaseTemporary(renderTexture); } renderTexture = RenderTexture.GetTemporary(requiredSize.x, requiredSize.y); renderer.MainTexture = renderTexture; bool CurrentTextureValid() => renderTexture && renderTexture.width == requiredSize.x && renderTexture.height == requiredSize.y; }
public void DrawTo(TransitionalRenderer renderer, int pixelsPerUnit) { if (!meshRenderer.enabled) { return; } var drawDimensions = (Vector3)renderCanvas.Size * pixelsPerUnit; var drawPosition = transform.position + (Vector3)renderCanvas.Offset; var orthoMin = -drawDimensions / 2f + drawPosition * pixelsPerUnit; var orthoMax = drawDimensions / 2f + drawPosition * pixelsPerUnit; var orthoMatrix = Matrix4x4.Ortho(orthoMin.x, orthoMax.x, orthoMin.y, orthoMax.y, float.MinValue, float.MaxValue); var rotationMatrix = Matrix4x4.Rotate(Quaternion.Inverse(renderer.transform.localRotation)); PrepareRenderTexture(drawDimensions, renderer); PrepareCommandBuffer(orthoMatrix); Draw(rotationMatrix, pixelsPerUnit); Graphics.ExecuteCommandBuffer(commandBuffer); }