forked from falseeeeeeeeee/ShaderLibrary
-
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.
- Loading branch information
1 parent
b6ff600
commit d15aba7
Showing
95 changed files
with
3,886 additions
and
4,866 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,90 @@ | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
public class ScreenShotWindow : EditorWindow | ||
{ | ||
private Camera m_Camera; | ||
private string filePath; | ||
private bool m_IsEnableAlpha = false; | ||
private CameraClearFlags m_CameraClearFlags; | ||
|
||
[MenuItem("Tools/屏幕截图")] | ||
private static void Init() | ||
{ | ||
ScreenShotWindow window = GetWindowWithRect<ScreenShotWindow>(new Rect(0, 0, 300, 150)); | ||
window.titleContent = new GUIContent("屏幕截图"); | ||
window.Show(); | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
EditorGUILayout.Space(); | ||
m_Camera = EditorGUILayout.ObjectField("选择摄像机", m_Camera, typeof(Camera), true) as Camera; | ||
|
||
if (GUILayout.Button("选择保存位置")) | ||
{ | ||
filePath = EditorUtility.OpenFolderPanel("", "", ""); | ||
} | ||
|
||
m_IsEnableAlpha = EditorGUILayout.Toggle("是否使用纯色背景", m_IsEnableAlpha); //是否开启透明通道 | ||
EditorGUILayout.Space(); | ||
if (GUILayout.Button("单摄像机截图")) | ||
{ | ||
TakeShot(); | ||
} | ||
if (GUILayout.Button("窗口截图(含UI)")) | ||
{ | ||
string fileName = filePath + "/" + $"{System.DateTime.Now:yyyy-MM-dd_HH-mm-ss}" + ".png"; | ||
ScreenCapture.CaptureScreenshot(fileName); | ||
} | ||
EditorGUILayout.Space(); | ||
if (GUILayout.Button("打开导出文件夹")) | ||
{ | ||
if (string.IsNullOrEmpty(filePath)) | ||
{ | ||
Debug.LogError("<color=red>" + "没有选择截图保存位置" + "</color>"); | ||
return; | ||
} | ||
Application.OpenURL("file://" + filePath); | ||
} | ||
} | ||
|
||
private void TakeShot() | ||
{ | ||
if (m_Camera == null) | ||
{ | ||
Debug.LogError("<color=red>" + "没有选择摄像机" + "</color>"); | ||
return; | ||
} | ||
|
||
if (string.IsNullOrEmpty(filePath)) | ||
{ | ||
Debug.LogError("<color=red>" + "没有选择截图保存位置" + "</color>"); | ||
return; | ||
} | ||
|
||
m_CameraClearFlags = m_Camera.clearFlags; | ||
if (m_IsEnableAlpha) | ||
{ | ||
m_Camera.clearFlags = CameraClearFlags.Depth; | ||
} | ||
|
||
int resolutionX = (int)Handles.GetMainGameViewSize().x; | ||
int resolutionY = (int)Handles.GetMainGameViewSize().y; | ||
RenderTexture rt = new RenderTexture(resolutionX, resolutionY, 24); | ||
m_Camera.targetTexture = rt; | ||
Texture2D screenShot = new Texture2D(resolutionX, resolutionY, TextureFormat.ARGB32, false); | ||
m_Camera.Render(); | ||
RenderTexture.active = rt; | ||
screenShot.ReadPixels(new Rect(0, 0, resolutionX, resolutionY), 0, 0); | ||
m_Camera.targetTexture = null; | ||
RenderTexture.active = null; | ||
m_Camera.clearFlags = m_CameraClearFlags; | ||
//Destroy(rt); | ||
byte[] bytes = screenShot.EncodeToPNG(); | ||
string fileName = filePath + "/" + $"{System.DateTime.Now:yyyy-MM-dd_HH-mm-ss}" + ".png"; | ||
File.WriteAllBytes(fileName, bytes); | ||
Debug.Log("截图成功"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.