Created
July 12, 2017 14:39
-
-
Save EntranceJew/4a7aa5011bed14684cb6d7e691397c45 to your computer and use it in GitHub Desktop.
BeeCode/Utils
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 UnityEngine; | |
using System.Collections; | |
using BeeCode.Extensions; | |
namespace BeeCode.Utils { | |
public static class ScreenCap { | |
public static IEnumerator Deferred( UnityEngine.Events.UnityAction<Texture2D> onCapture ) { | |
yield return new WaitForEndOfFrame(); | |
Texture2D screenShot = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false ); | |
screenShot.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 ); | |
screenShot.Apply(); | |
onCapture( screenShot ); | |
//byte[] bytes = screenShot.EncodeToPNG(); | |
//string fileName = Application.persistentDataPath + "/Screenshot" + index + ".png"; | |
//System.IO.File.WriteAllBytes( fileName, bytes ); | |
} | |
public static Texture2D Capture() { | |
var fileName = "screenshot_" + System.DateTime.UtcNow.Unix(); | |
if( !Application.isMobilePlatform ) { | |
fileName = Application.persistentDataPath + "/" + fileName; | |
} | |
fileName += ".png"; | |
Application.CaptureScreenshot( fileName ); | |
var texture = new Texture2D( Screen.width, Screen.height ); | |
texture.LoadImage( System.IO.File.ReadAllBytes( fileName ) ); | |
System.IO.File.Delete( fileName ); | |
return texture; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment