0

我的办公室有一个用 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# 导入的方法 -

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
                    }
            }

现在,插件根本不起作用,甚至测试方法也不起作用,

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

对我来说有什么好主意可以在不需要更改库中的任何内容的情况下使其正常工作吗?

提前致谢 :)

4

0 回答 0