-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
0800694
commit a9e8d0f
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
} | ||
|
||
} |