72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class WebGl : SingletonMonoBehaviour<WebGl>
|
|
{
|
|
public bool isOn = false;
|
|
|
|
public byte[] image { get { return _images; } }
|
|
byte[] _images;
|
|
|
|
public void GetDragAndDrop(string base64Json)
|
|
{
|
|
if (!isOn)
|
|
return;
|
|
try
|
|
{
|
|
base64Json = base64Json.Replace("[\"", "").Replace("\"]", "");
|
|
string[] data = base64Json.Split(',');
|
|
data[0] = data[0].Replace("data:", "");
|
|
data[0] = data[0].Replace("/", ";");
|
|
string[] info = data[0].Split(";");
|
|
if (info[0] != "image")
|
|
{
|
|
GameManager.Instance.infoPageUI.SetError(InfoMessage.NotImage);
|
|
return;
|
|
}
|
|
|
|
if (!(info[1] == "png" || info[1] == "jpg" || info[1] == "jpeg"))
|
|
{
|
|
GameManager.Instance.infoPageUI.SetError(InfoMessage.NotImageType);
|
|
return;
|
|
}
|
|
|
|
if (info[2] != "base64")
|
|
{
|
|
GameManager.Instance.infoPageUI.SetError(InfoMessage.SystemError00001);
|
|
return;
|
|
}
|
|
|
|
_images = DecodeBase64(data[1]);
|
|
double fileSizeInMB = _images.Length / (1024.0 * 1024.0);
|
|
|
|
if (fileSizeInMB > 10.0d)
|
|
{
|
|
GameManager.Instance.infoPageUI.SetError(InfoMessage.NotImageSize);
|
|
Debug.Log($"파일 크기: {fileSizeInMB:F2} MB");
|
|
return;
|
|
}
|
|
FursuitAddCtrl.Instance.SetImage(image);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
GameManager.Instance.infoPageUI.SetError(InfoMessage.SystemError00002);
|
|
}
|
|
}
|
|
|
|
public byte[] DecodeBase64(string base64String)
|
|
{
|
|
try
|
|
{
|
|
// Base64 문자열을 byte[]로 디코딩
|
|
byte[] byteArray = Convert.FromBase64String(base64String);
|
|
return byteArray;
|
|
}
|
|
catch (FormatException ex)
|
|
{
|
|
// 잘못된 Base64 문자열 처리
|
|
Console.WriteLine("Base64 디코딩 실패: " + ex.Message);
|
|
return null;
|
|
}
|
|
}
|
|
} |