38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
|
|
public class GenerateItemSpriteSelected
|
|
{
|
|
[MenuItem("Generation/GenerateItemSpriteSelected")]
|
|
public static void Generate()
|
|
{
|
|
Camera camera = Camera.main;
|
|
if (camera == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int width = 1080;
|
|
int height = 1080;
|
|
|
|
RenderTexture rt = new RenderTexture(width, height, 24);
|
|
camera.targetTexture = rt;
|
|
Texture2D screenShot = new Texture2D(width, height, TextureFormat.RGBA32, false);
|
|
camera.Render();
|
|
RenderTexture.active = rt;
|
|
screenShot.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
screenShot.Apply();
|
|
camera.targetTexture = null;
|
|
RenderTexture.active = null;
|
|
Object.DestroyImmediate(rt);
|
|
string folderPath = "Assets/";
|
|
string path = Path.Combine(folderPath, "ItemSprite_" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png");
|
|
File.WriteAllBytes(path, screenShot.EncodeToPNG());
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log("Зображення збережено: " + path);
|
|
}
|
|
}
|