-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutputTextures.cs
41 lines (31 loc) · 1.1 KB
/
OutputTextures.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class OutputTextures : EditorWindow {
Texture tex;
[MenuItem("SDTools/SD2PNG")]
static public void Main()
{
OutputTextures windows = GetWindow<OutputTextures>();
windows.Show();
}
private void OnGUI()
{
GUILayout.BeginHorizontal();
tex = (Texture)EditorGUILayout.ObjectField(tex, typeof(Texture), false);
GUILayout.EndHorizontal();
GUILayout.Space(20);
if (GUILayout.Button("Get"))
{
RenderTexture ResultTexture = new RenderTexture(tex.width, tex.height, 24);
Graphics.Blit(tex, ResultTexture);
Texture2D frame = new Texture2D(ResultTexture.width, ResultTexture.height);
frame.ReadPixels(new Rect(0, 0, ResultTexture.width, ResultTexture.height), 0, 0, false);
frame.Apply();
byte[] bytes = frame.EncodeToPNG();
System.IO.File.WriteAllBytes("Assets/Temp/Save.png", bytes);
AssetDatabase.Refresh();
}
}
}