ClientServer/Client/Assets/Scripts/Util/ScreenShotterUtil.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2025-09-06 17:17:39 +04:00
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
//Thomas09
[ExecuteInEditMode]
[CustomEditor(typeof(ScreenShotter))]
public class ScreenShotterUtil : Editor
{
string path = "Assets/Screenshots";
string screenShotName = "";
public override void OnInspectorGUI()
{
GUILayout.Label("Make sure you have created a folder called 'Screenshots' in Assets.");
GUILayout.Space(20);
GUILayout.Label("Take Photo Of Game View");
if (GUILayout.Button("Capture!"))
{
CaptureScreenShot();
}
GUILayout.Label("Press this to delete all photos currently stored.");
if(GUILayout.Button("DELETE ALL PHOTOS"))
{
DeletePhotos();
}
}
private void DeletePhotos()
{
string[] screenshots = Directory.GetFiles(Application.dataPath + "/Screenshots/");
foreach (var SS in screenshots)
{
File.Delete(SS);
Debug.Log("Deleted all currently stored screenshots!");
}
RefreshAssetDataBase();
}
private void CaptureScreenShot()
{
Debug.Log("SCREENSHOT CAPTURED!");
screenShotName = "Screenshot_" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".png";
ScreenCapture.CaptureScreenshot(Path.Combine(path, screenShotName), 4);
RefreshAssetDataBase();
}
private async void RefreshAssetDataBase()
{
await Task.Delay(1000);
AssetDatabase.Refresh();
}
}
#endif