简体   繁体   English

(Android Unity 插件)我创建了一个简单的插件,预期为 123,得到 0

[英](Android Unity plugin) i created a simple plugin, expected 123, got 0

I'm trying to make a plugin for Unity, but not even the simplest class works.我正在尝试为 Unity 制作一个插件,但即使是最简单的类也不起作用。

In Android Studio I created a library module, and in it, the following class:在 Android Studio 中,我创建了一个库模块,并在其中创建了以下类:

package com.vuforia.android.pluginlib;

import static android.os.Looper.getMainLooper;

public class Multi {
    static public Multi mult=new Multi();
    static public int testes =123;
}

After that I added to the gradle of lib, the following configurations of a Task,to create the aar:之后我在lib的gradle中添加了一个Task的如下配置,来创建aar:

task copyPlugin (type : Copy){
    dependsOn assemble
    from ('build/outputs/aar')
    into ('../../Assets/Plugins/Android')
    include(project.name+'-release.aar')
}

In unity, I created some sprite, and added such script to it:在 unity 中,我创建了一些精灵,并在其中添加了这样的脚本:

using UnityEngine;

public class movetest : MonoBehaviour
{
    private AndroidJavaClass javaClass = null;
    void Update()
    {

        javaClass = new AndroidJavaClass("com.vuforia.android.pluginlib.Multi");
        int i = javaClass.GetStatic<int>("testes");
        Debug.Log("->>"+i);
    }

}

and when clicking on run, then what is received "- >>0".当点击运行时,收到的是“- >> 0”。

I assume you are running in the editor because you stated "when clicking on run"..我假设您正在编辑器中运行,因为您说“单击运行时”..

Java plugins will not work in the editor. Java 插件在编辑器中不起作用。 You would need to deploy to an Android device to test the functionality.您需要部署到 Android 设备来测试功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM