android的统一插件(在logcat中未能收到调度信号错误)

时间:2015-03-18 06:30:13

标签: java android unity3d

我正在尝试为Android制作一个统一插件。当单击按钮时,插件将显示本机android对话框。但是当我点击按钮时,catlog中会出现错误,并且会在设备上发生。但

Jar文件由Eclipse IDE构成。 Android Jar文件在类中包含此函数:

public void OpenDialog()

{

    AlertDialog.Builder builder = new AlertDialog.Builder(UnityPlayer.currentActivity);

    builder.setTitle("Alert Dialog");

    builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {

               public void onClick(DialogInterface dialog, int id) {

               }

           });

    builder.setNegativeButton("Cancel", new 

    DialogInterface.OnClickListener() {

               public void onClick(DialogInterface dialog, int id) {

               }

           });

    AlertDialog dialog = builder.create();

    dialog.show();

}

我想尝试从Unity C#Script调用此函数:

void OnGUI()
{
    if (GUI.Button(new Rect(0, 200, 100, 100), "Call Add Method"))
    {
        AndroidJavaObject jo = new AndroidJavaObject("com.werplay.unityplugin.AndroidPlugin");
        jo.Call("OpenDialog");
    }

}   

这个错误出现在日食的catlog中:

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个,你必须在你的线程中运行它,

public void OpenDialog() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    UnityPlayer.currentActivity);
            builder.setTitle("Alert Dialog");
            builder.setPositiveButton("ok",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }

                    });
            builder.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }

                    });
            AlertDialog dialog = builder.create();
            dialog.show();

        }
    });
}