using UnityEditor;
using UnityEngine;
public class SampleEditorWindow : EditorWindow
{
private Texture2D _texture;
private void OnGUI()
{
if (GUILayout.Button("画像をロードする"))
{
var sourcePath = EditorUtility.OpenFilePanel("Select Image", "", "png,jpg,jpeg");
if (!string.IsNullOrEmpty(sourcePath))
{
_texture = new Texture2D(0, 0);
_texture.LoadImage(System.IO.File.ReadAllBytes(sourcePath));
}
}
if (_texture != null)
{
var rect = GUILayoutUtility.GetRect(_texture.width, _texture.height, GUILayout.MaxWidth(_texture.width), GUILayout.MaxHeight(_texture.height));
EditorGUI.DrawTextureTransparent(rect, _texture);
}
}
}