Skip to content

Commit

Permalink
First commit!
Browse files Browse the repository at this point in the history
Can store screenshots to a custom path in streamingassets or your persistant data path. :) Next will be the plan to add any path, resolution and transparency settings I can.
  • Loading branch information
TheFunnyBrain authored May 27, 2021
1 parent 0800694 commit a9e8d0f
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Screenshotter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;


public enum DesiredSaveLocation
{
Persistent, StreamingAssets
}

public class Screenshotter : MonoBehaviour
{
int ID;

string fullPath;

public string ImagePrefix = "Image ";

public string folder = "Screenshotter";

public int screenshotScale = 1;

public DesiredSaveLocation imageSaveLocation;

// Start is called before the first frame update
void Start()
{

}

private void Update()
{
if (Input.GetKeyDown(KeyCode.Period))
{


switch (imageSaveLocation)
{
case DesiredSaveLocation.Persistent:
fullPath = Path.Combine(Application.persistentDataPath, folder);
CheckThenCreateDir(fullPath);
break;
case DesiredSaveLocation.StreamingAssets:
CheckThenCreateDir(fullPath);
fullPath = Path.Combine(Application.streamingAssetsPath, folder);
break;
}

ID++;
string imageName = ImagePrefix + ID + ".png";

ScreenCapture.CaptureScreenshot(Path.Combine(fullPath, imageName), screenshotScale);
Debug.LogFormat("Screenshot {0} saved to {1}", imageName, fullPath);
}
}

private void CheckThenCreateDir(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}

}

0 comments on commit a9e8d0f

Please sign in to comment.