简体   繁体   English

如何将“ .jar”库文件导入Unity?

[英]How to import '.jar' library file into Unity?

How can I import to .jar file into Unity3D? 如何将.jar文件导入Unity3D? I am using Windows platform, not Android, iOS, Mac etc. I put my .jar file into to the Assets/Plugins/x86. 我使用的是Windows平台,而不是Android,iOS,Mac等。我将.jar文件放入Assets / Plugins / x86。 I don't understand how to call my function in .jar library. 我不明白如何在.jar库中调用函数。

I haven't found anything here for windows: http://docs.unity3d.com/Manual/Plugins.html 我在Windows上找不到任何内容: http : //docs.unity3d.com/Manual/Plugins.html

Thanks. 谢谢。

In Unity on Windows platform you do not have a built in support for this as far as I know, but it is easy to convert Java bytecode to .NET using ikvm . 据我所知,在Windows平台上的Unity中,您没有对此的内置支持,但是使用ikvm将Java字节码转换为.NET很容易。 It comes with a converter named ikvmc, so you can simply use: 它带有一个名为ikvmc的转换器,因此您可以简单地使用:

ikvmc your.jar -target:library ==> add -target:library to generate dll

It will convert your jar to your.dll which is your Java code rewritten in .NET dll. 它将jar转换为your.dll,这是在.NET dll中重写的Java代码。 Then you simply use it by putting it in your assets folder and use it as if it was native .NET library. 然后,只需将其放在资产文件夹中就可以使用它,就好像它是本机.NET库一样使用。 For example, if your java code was: 例如,如果您的Java代码是:

public class HelloWorld {
    public static void hello() {
        System.out.println("Hello, World");
    }
}

You use it simply by HelloWorld.hello() 您只需通过HelloWorld.hello()使用它

If you want to directly add jar files in unity 如果要统一直接添加jar文件

Example class file below, compile into jar 下面的示例类文件,编译成jar

package xxx;
    import android.util.Log;
    public class Helper {
    public static void testAndroid()
        {
        Log.i(“Unity”, “test android”);
        }
    }

Place the jar file in plugins->Android in unity and check android platform in plugin editor. 将jar文件统一放在plugins-> Android中,然后在插件编辑器中检查android平台。 Note it will only run on android device or simulator if you are using android references 请注意,如果您使用的是android引用,它将仅在android设备或模拟器上运行

Create a new MonoBehaviour script TestAndroidPlugin.cs, and attach it to the camera: 创建一个新的MonoBehaviour脚本TestAndroidPlugin.cs,并将其附加到相机:

public class TestAndroidPlugin : MonoBehaviour {    
    void Start () {
        Debug.Log("Android function is to be called");


        var ajc = new AndroidJavaClass("xxx.Helper"); //(1)
        ajc.CallStatic("testAndroid");                                       //(2)
        Debug.Log("Androidtion is called");  
    }
}

As I have know unity does not support jar library for windows development because the supported programming language are 据我所知,Unity不支持Windows开发的jar库,因为支持的编程语言是

UnityScript(javascript for unity), boo and C#. UnityScript(统一的JavaScript),boo和C#。

You can check the documentation here unity supported programming language Even they drop support for booking in unity 5.0 but you can use it. 您可以在此处查看文档统一支持的编程语言,即使他们放弃了统一5.0的预订支持,但您可以使用它。 Instead of a jar library why not look for ac# library that solve the same problem you want to solve. 为什么不找一个可以解决您要解决的相同问题的ac#库而不是jar库

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

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