Layout
Control the layout of your Rive animation in Unity
For more information on Rive Layout see the runtime documentation.
Fit and Alignment
The fit and alignment can be controlled on the Rive.Renderer .Align()
method:
public Fit fit = Fit.contain; public Alignment alignment = Alignment.Center; public RenderTexture renderTexture; private Rive.Renderer m_riveRenderer; ... m_renderQueue = new Rive.RenderQueue(renderTexture); m_riveRenderer = m_renderQueue.Renderer(); ... if (m_artboard != null && renderTexture != null) { m_riveRenderer.Align(fit, alignment, m_artboard); m_riveRenderer.Draw(m_artboard); }
Responsive Layout
The Layout Fit Mode lets you display resizable artboards with built-in responsive behavior, configured directly in the graphic. Set a Fit of type Layout at runtime and the artboard will resize automatically. Optionally, provide a Layout Scale Factor to further adjust the scale of the content.
Implementing Layout in Custom Scripts
When implementing Fit.Layout
in your custom scripts, consider the following aspects:
Screen Resolution and Scaling
Monitor screen resolution changes
Handle device pixel ratios
Implement proper scaling for different display densities
Input Handling
Transform input coordinates to match the scaled layout
Account for different device pixel ratios when processing touch/mouse input
Consider hit-testing adjustments for scaled elements
This script shows one way you could implement Fit.Layout
support while considering the points mentioned above.