안드로이드 스튜디오에서 받아온 .obj와 .mtl 파일을 유니티로 전달하려면 파일의 내용을 문자열 형태로 변환한다.
그리고 이 문자열 데이터를 UnitySendMessage()를 이용해 유니티로 전달할 수 있다고 한다.
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
...
String filePath = "/path/to/your/file.obj";
File file = new File(filePath);
String fileContent = "";
try {
fileContent = new String(Files.readAllBytes(Paths.get(file.getPath())));
} catch (IOException e) {
e.printStackTrace();
}
주어진 경로의 파일 내용을 문자열로 엮어 ‘filecontent’ 변수에 저장한다.
UnityPlayer.UnitySendMessage("GameObjectName", "MethodName", fileContent);
‘filecontent’ 변수의 값을 유니티의 ‘MethodName()’ 메서드에 전달한다.
여기서 “GameObjectName”은 메시지를 받을 유니티 게임 오브젝트의 이름이며, “MethodName”은 해당 게임 오브젝트에서 호출할 메서드의 이름이다.
public class ExampleScript : MonoBehaviour
{
public void MethodName(string fileContent)
{
// Use 'fileContent' here.
}
}
이런 방식으로 안드로이드 스튜디오에서 읽은 파일을 유니티로 보낼 수 있다.