Hi, I'm building an Android plugin that can take a picture. The problem is, the picture is not instantly ready and the Unity application follows its course while the picture is being treated. So what I'm currently doing is putting my main Thread to sleep 2s (arbitrary value) hoping that my picture will be ready by then. It's dirty and unreliable but I can't figure out how to do it differently. Each time I try to call a Plugin function from a Thread my app just crashes. Here is the part where I'm calling the plugin :
if (jc != null) {
if (!pic_taken) {
script_cam_display.stopCam ();
// Ask the plugin to take a picture
CamPlugin.takePicture (jc);
// Dirty
Thread.Sleep(2000);
// Check if pic is available
pic_taken = CamPlugin.picAvailable (jc);
if (pic_taken) {
// Get the picture
data = CamPlugin.getData (jc);
if(data != null) {
Texture2D tex = new Texture2D (2, 2);
tex.LoadImage (data);
script_pic_display.displayPicture (tex);
}
}
}
}
pic_taken = false;
script_cam_display.stopCam ();
script_cam_display.restartCam ();
Any idea on how I could reliably wait for the picture to came in without freezing the UI during an arbitrary number of seconds ?
↧