简体   繁体   English

Android Unity 插件

[英]Android Unity plugin

I want to use unity android plugin in my AR application.我想在我的 AR 应用程序中使用 unity android 插件。 The app has an AR camera, an image target and a 3d object.该应用程序有一个 AR 摄像头、一个图像目标和一个 3d 对象。

ON ECLIPSE :日食:

I create a default android application on eclipse.我在 eclipse 上创建了一个默认的 android 应用程序。 I click build automatically and check project name -> proeprties -> isLibrary .我单击自动构建并检查project name -> proeprties -> isLibrary I create a class named Bridge on eclipse project.我在 eclipse 项目上创建了一个名为Bridge的类。

Bridge.java Bridge.java

package com.tutorial.pluginforunity;
public class Bridge {

    public static int ReturnInt() {
        return 5;
    }
}

ON UNITY : I create a BridgeForUnity.cs file. ON UNITY :我创建了一个BridgeForUnity.cs文件。 Conent of it :内容:

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;

public class BridgeForAndroid : MonoBehaviour {

    #if UNITY_ANDROID 
    //&& !UNITY_EDITOR
    public static int ReturnInt () {
        AndroidJavaClass ajc = new AndroidJavaClass("com.tutorial.pluginforunity.Bridge");
        return ajc.CallStatic<int>("ReturnInt") ;
    }
    #endif

    void Start () {

    }

    void Update () {

    }
}

I edit DefaultTrackableEventHandler.cs that attached to image target.我编辑附加到图像目标的DefaultTrackableEventHandler.cs

private void Update() {
    #if UNITY_ANDROID 
    GUI.Label(new Rect(10, 10, 100, 20), "Return = " + BridgeForAndroid.ReturnInt());
    #endif
    if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); }
}

I copy jar file under bin folder in eclipse project.我将 jar 文件复制到 eclipse 项目中的 bin 文件夹下。 I paste it under Assets/Plugins/Android.When I run this application, I see only black screen.我把它粘贴到 Assets/Plugins/Android 下。当我运行这个应用程序时,我只看到黑屏。

要查看插件的返回值,请将代码从Update移至OnGUI

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

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