Unity插件不适用于与侦听器工具的接口

时间:2018-04-02 09:58:43

标签: java android unity3d android-unity-plugin

我的办公室有一个用Java编写的Android网络库,可以实现快速简便的多人联网,

现在,我被分配到使用Unity3D上的库,我在Unity插件,AndroidJavaClass,AndroidJavaProxy,AndroidJavaRunnable等上完成了我的作业,

所以,我可以让大多数Android / Java方法都像这样工作,

来自Java类 -

Class MyClass{
public static Helper helperInstance;

    Helper() {
        helperInstance = this;
    }

    public static Helper GetInstance() {

        if (helperInstance == null) {
            helperInstance = new Helper();
        }

        return helperInstance;
    }

    public Context mContext;

    public String Test(Context mContext) {
        this.mContext = mContext;
        Toast.makeText(mContext, "From Java With Love", Toast.LENGTH_SHORT).show();
        return "This Works";
    }
}

可以像这样访问C#中的方法或从C#导入的方法 -

AndroidJavaClass unityDefault = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject gameActivity = unityDefault.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject context = gameActivity.Call<AndroidJavaObject>("getApplicationContext");

        AndroidJavaClass hClass = new AndroidJavaClass("com.nixonok.pluginunity.Helper");
        AndroidJavaObject helperInstance = RightMeshClass.CallStatic<AndroidJavaObject>("GetInstance");

        helloText.text = helperInstance.Call<string>("Test", context);

当我为网络状态更改侦听器实现侦听器

时,会出现问题
            public interface StateListener {
                int SUCCESS = 1;
                int FAILURE = 2;
                int DISABLED = 3;
                int RESUME = 4;

                void StateChanged(int var1, int var2);
            }

            public Class MyClass implements StateListener{
        // Called By a Service on network event 
        @Override
            public void meshStateChanged(MeshID meshID, int i) {

            }
            Helper() {
                        helperInstance = this;
                    }

                    public static Helper GetInstance() {

                        if (helperInstance == null) {
                            helperInstance = new Helper();
                        }

                        return helperInstance;
                    }

                    public Context mContext;

                    public String Test(Context mContext) {
                        this.mContext = mContext;
                        Toast.makeText(mContext, "From Java With Love", Toast.LENGTH_SHORT).show();
                        return "Even This doesn't Work now";
                    }

                    void init(){
                        nService nn = new nService(mContext, this);
                        // Sending context of the listener impliment to service
                    }
            }

现在,该插件根本不起作用,甚至不是Test方法,

我使用AndroidJavaProxy在C#中进行了一个接口回调但没有工具,在Java类上,服务无法启动:/

让我在不需要更改库中任何内容的情况下工作有什么好主意吗?

提前致谢:)

0 个答案:

没有答案