using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class ScreenShot : EditorWindow
{
[MenuItem("检查/Scene视图截图 %#z")]
public static void Tool1()
{
string path = @"C:\Users\Admin\Desktop\新建文件夹\" + "test" + ".png";
Fun(UnityEditor.SceneView.GetAllSceneCameras()[0], path);
}
static void Fun(Camera m_Camera, string filename)
{
RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 16);
m_Camera.targetTexture = rt;
m_Camera.Render();
RenderTexture.active = rt;
Texture2D t = new Texture2D(Screen.width, Screen.height);
t.ReadPixels(new Rect(0, 0, t.width, t.height), 0, 0);
t.Apply();
System.IO.File.WriteAllBytes(filename, t.EncodeToPNG());
}
}
|