46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEngine;
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class WebGl : MonoBehaviour
|
|
{
|
|
public byte[] image { get { return _images; } }
|
|
byte[] _images;
|
|
public void GetDragAndDrop(string base64Json)
|
|
{
|
|
try
|
|
{
|
|
Debug.Log("JSON 데이터 수신 완료");
|
|
|
|
// JSON 문자열을 리스트로 변환
|
|
List<string> base64List = JsonConvert.DeserializeObject<List<string>>(base64Json);
|
|
|
|
if (base64List == null || base64List.Count == 0)
|
|
{
|
|
Debug.LogError("Base64 리스트가 비어 있습니다.");
|
|
return;
|
|
}
|
|
|
|
// 첫 번째 이미지를 _images에 저장 (여러 개 저장하려면 List<byte[]> 사용)
|
|
_images = Convert.FromBase64String(base64List[0]);
|
|
|
|
Debug.Log("이미지 변환 완료, 크기: " + _images.Length + " 바이트");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError("JSON 처리 중 오류 발생: " + e.Message);
|
|
}
|
|
}
|
|
[DllImport("__Internal")]
|
|
private static extern void GetImageDataJS(byte[] array, int length);
|
|
|
|
public void ReceiveImageData(byte[] data)
|
|
{
|
|
Debug.Log("시작");
|
|
_images = data;
|
|
Debug.Log($"이미지 데이터 수신 완료: {_images.Length} 바이트");
|
|
}
|
|
}
|