/screenshoter

A simple script for creating screenshots in Unity3D

Primary LanguageC#Apache License 2.0Apache-2.0

Screenshoter

This package provides a simple utility for taking screenshots of a scene in Unity3D

INSTALLATION

There are 3 ways to install this plugin:

  • import Screenshoter.unitypackage via Assets-Import Package
  • clone/download this repository and move the Screenshoter.cs file to your Unity project's Assets folder
  • (via Package Manager) Select Add package from git URL from the add menu. A text box and an Add button appear. Enter a valid Git URL in the text box:
    • https://github.com/llarean/screenshoter.git
  • (via Package Manager) add the following line to Packages/manifest.json:
    • "com.llarean.screenshoter": "https://github.com/llarean/screenshoter.git",

HOW TO and EXAMPLE CODE

  1. Create an instance of the class and pass to the constructor the camera from which the screenshot will be taken
using UnityEngine;
using Utilities;

public interface Example : MonoBehaviour
{
    [SerializeField] private Camera _screenshotCamera;
    [SerializeField] private Vector2Int _screenshotSize;
    
    private Screenshoter _screensoter;
    
    private void Start()
    {
        _screensoter = new Screenshoter(_screenshotCamera);
    }
}
  1. To get a screenshot in the form of a sprite
private void GetSprite()
{
    Sprite sprite = _screensoter.GetScreenshotSprite(_screenshotSize);
}
  1. To get a screenshot in the form of a texture
private void GetTexture()
{
    Texture2D texture2D = _screensoter.GetScreenshotTexture2D(_screenshotSize);
}
  1. To get a screenshot in the form of an array of bytes
private void GetTexture()
{
    byte[] spriteBytes = _screensoter.GetScreenshotArray(_screenshotSize);
}