[英]Android Unity plugin
我想在我的 AR 應用程序中使用 unity android 插件。 該應用程序有一個 AR 攝像頭、一個圖像目標和一個 3d 對象。
日食:
我在 eclipse 上創建了一個默認的 android 應用程序。 我單擊自動構建並檢查project name -> proeprties -> isLibrary
。 我在 eclipse 項目上創建了一個名為Bridge的類。
Bridge.java
package com.tutorial.pluginforunity;
public class Bridge {
public static int ReturnInt() {
return 5;
}
}
ON UNITY :我創建了一個BridgeForUnity.cs
文件。 內容:
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 () {
}
}
我編輯附加到圖像目標的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(); }
}
我將 jar 文件復制到 eclipse 項目中的 bin 文件夾下。 我把它粘貼到 Assets/Plugins/Android 下。當我運行這個應用程序時,我只看到黑屏。
要查看插件的返回值,請將代碼從Update
移至OnGUI
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.