-
-
Save kirillrybin/8383471afce061ff35b0 to your computer and use it in GitHub Desktop.
Unity3D/C# class that takes screenshot from SFCamera. Works with Scaleform Unity Plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Scaleform; | |
using UnityEngine; | |
[RequireComponent(typeof (SFCamera))] | |
public class SFCameraSnapshot : MonoBehaviour | |
{ | |
private bool _takeShot; | |
private Rect _rect; | |
public void Shoot(Rect getSnapshotRect) | |
{ | |
_rect = getSnapshotRect; | |
_takeShot = true; | |
} | |
private void OnPostRender() | |
{ | |
if (_takeShot) | |
{ | |
var resWidth = (int)_rect.width; | |
var resHeight = (int)_rect.height; | |
var screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); | |
screenShot.ReadPixels(_rect, 0, 0); | |
byte[] bytes = screenShot.EncodeToPNG(); | |
string filename = ScreenShotName(resWidth, resHeight); | |
System.IO.File.WriteAllBytes(filename, bytes); | |
Debug.Log(string.Format("Took screenshot to: {0}", filename)); | |
_takeShot = false; | |
} | |
} | |
public static string ScreenShotName(int width, int height) | |
{ | |
return string.Format("{0}/screenshots/screen_{1}x{2}_{3}.png", | |
Application.dataPath, | |
width, height, | |
System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment