49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UVC.Edit
|
|
{
|
|
public class PropertyWindow : MonoBehaviour
|
|
{
|
|
public Image uiImageTarget; // UI 객체에 적용할 Image
|
|
public SpriteRenderer spriteTarget; // 2D 객체에 적용할 SpriteRenderer
|
|
|
|
public void OpenImageFileBrowser()
|
|
{
|
|
//var extensions = new[] {
|
|
// new ExtensionFilter("Image Files", "png", "jpg", "jpeg")
|
|
//};
|
|
|
|
//// 비동기 방식으로 파일 브라우저 열기
|
|
//StandaloneFileBrowser.OpenFilePanelAsync("Select an Image", "", extensions, false, (string[] paths) =>
|
|
//{
|
|
// if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
|
|
// {
|
|
// LoadAndApplyTexture(paths[0]);
|
|
// }
|
|
//});
|
|
}
|
|
|
|
private void LoadAndApplyTexture(string path)
|
|
{
|
|
byte[] fileData = File.ReadAllBytes(path);
|
|
Texture2D texture = new Texture2D(2, 2);
|
|
// 이미지 데이터로 텍스처 로드
|
|
if (texture.LoadImage(fileData))
|
|
{
|
|
if (uiImageTarget != null)
|
|
{
|
|
Sprite newSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
uiImageTarget.sprite = newSprite;
|
|
}
|
|
if (spriteTarget != null)
|
|
{
|
|
Sprite newSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
spriteTarget.sprite = newSprite;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|