Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gilzoide/unity-camera-viewport-rect

Automatically setup Camera viewports from RectTransforms in Unity
https://github.com/gilzoide/unity-camera-viewport-rect

3d camera recttransform responsive ui unity unity3d viewport

Last synced: 3 months ago
JSON representation

Automatically setup Camera viewports from RectTransforms in Unity

Awesome Lists containing this project

README

        

# Camera Viewport Rect
[![openupm](https://img.shields.io/npm/v/com.gilzoide.camera-viewport-rect?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.gilzoide.camera-viewport-rect/)

Automatically setup `Camera` viewports from `RectTransform`s.

This way one can easily show 3D models directly into responsive UI without the need of setting up `RenderTexture`s.

![Demonstration of the CameraViewportRect script](Extras~/demo.gif)

## Features
- Supports canvases in both `Screen Space - Camera` and `Screen Space - Overlay` modes.
Using `Screen Space - Camera` mode is recommended to make sure the camera renders above the UI.
- Supports enabling/disabling the target Camera when the script itself gets enabled/disabled

## How to install
Either:

- Install using [openupm](https://openupm.com/):
```
openupm add com.gilzoide.camera-viewport-rect
```

- Install via [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui-giturl.html) using the following URL:
```
https://github.com/gilzoide/unity-camera-viewport-rect.git#1.0.1
```

- Copy the script [CameraViewportRect.cs](Runtime/CameraViewportRect.cs) directly into your project

## How to use
1. Add a [CameraViewportRect](Runtime/CameraViewportRect.cs) component to any
object with a `RectTransform`
2. Set the `Camera` property to the camera that should render inside it
3. Enjoy 🍾

## Samples
This UPM package has the following sample scene:
- [RotatingCube](Samples~/RotatingCube/RotatingCubeSample.unity): Simple sample with a rotating cube that appears on a responsive UI