38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
#if UNITY_EDITOR
|
|
|
|
using UnityEngine;
|
|
|
|
public class PrintScreenTool : MonoBehaviour
|
|
{
|
|
// Define the key to trigger the screenshot
|
|
public KeyCode screenshotKey = KeyCode.P;
|
|
|
|
// Function to capture the screenshot
|
|
private void CaptureScreenshot()
|
|
{
|
|
// Generate a unique filename for the screenshot
|
|
string filename = "Screenshot_" + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png";
|
|
|
|
// Capture the screenshot and save it to the persistent data path
|
|
string filePath = Application.persistentDataPath + "/" + filename;
|
|
ScreenCapture.CaptureScreenshot(filename);
|
|
|
|
// Display a tip with the screenshot location
|
|
string tipMessage = "Screenshot saved at the project folder";
|
|
DebugUtil.Log(tipMessage);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
// Check if the specified key is pressed
|
|
if (Input.GetKeyDown(screenshotKey))
|
|
{
|
|
// Capture the screenshot
|
|
CaptureScreenshot();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|