Log in or register to post comments

hi, i want to konw about overlay..

April 30, 2011 - 10:59pm #1

i built my project in Unity3D and intergrated with Eclipse.

however, i don't know how to add my button at this environment.

please, i want to detaily know the process

thanks!

-JD

Re: hi, i want to konw about overlay..

June 23, 2011 - 7:11pm #21

Egads, please save the log as a text file, those pictures are tough to follow! You can click on a line in the log, hold the shift key, then click on a line at the end of the log to select a section. Or just press CTRL-A to select the whole log. Press CTRL-C to copy, paste in a text file. In general we need a fresh run from start to finish (not resumed from the background). You should see QCAR initialization lines at the start.

Anyways, I'm not sure we're getting anywhere debugging this way. Can you possibly zip up your Unity project and Java projects and send to

? You'll want to use a file sharing service, you can use this one if you'd like: http://me2u.qualcomm.com (create an account with your email address).

- Kim

Re: hi, i want to konw about overlay..

June 23, 2011 - 2:50am #20

Hi Kim,

Yes, I modify the AndroidManifest.xml, like this :

<manifest package="com.Romain.RA_Unity" android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"/>
<uses-feature android:name="android.hardware.camera"/>
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
−
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:debuggable="false">
−
<activity android:name="com.qualcomm.QCARUnityPlayer.PlayerActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation" android:screenOrientation="landscape">
−
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
−
<activity android:name=".MyPlayer" android:label="@string/app_name">
−
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

I make a debug log after call of AndroidJavaClass jc, like this :

AndroidJavaClass jc = new AndroidJavaClass("com.Romain.RA_Unity.MyPlayer");
Debug.Log("JC="+jc);

And I obtain this in the Unity log :

JC=UnityEngine.AndroidJavaClass
UnityEngine.Debug:Log(Object)

In Eclipse, I've send you my error log only, sorry, you can see the complete log here : http://imageshack.us/g/98/log12z.jpg/

Thank you again for your help,

Re: hi, i want to konw about overlay..

June 22, 2011 - 2:51pm #19

You should be able to run the application in Eclipse with full tracking and functionality. There should be more to the log than the screenshot you captured, such as log lines as to whether or not tracker initialization succeeded. It's hard to help debug the issue without seeing more of the logs or your project setup, the class below looks fine.

Have you modified the AndroidManifest.xml file to use your class as the application entry point? When you call this:

AndroidJavaClass jc = new AndroidJavaClass("com.Romain.RA_Unity.MyPlayer");

is jc null, or does it find the class?

- Kim

Re: hi, i want to konw about overlay..

June 22, 2011 - 1:14am #18

Yes, I create a variable called currentActivity, like this (MyPlayer.java):

[CODE" />package com.Romain.RA_Unity;

import android.os.Bundle;
import android.util.Log;

import com.qualcomm.QCARUnityPlayer.PlayerActivity;

public class MyPlayer extends com.qualcomm.QCARUnityPlayer.PlayerActivity {

public static MyPlayer currentActivity;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentActivity = this;
}

public void test() {
Log.e("test", "LOG OK");
}
}[/CODE" />

(I just want call the "debug function" test).
And yes, I can run the application from Eclipse but my Unity 3D object doesn't appear and there is no reaction when I detect a marker, is it a correct behavior?
I joined you my Eclipse debug:http://img21.imageshack.us/img21/1835/eclipsedebug.jpg

Thank you for your help,

Re: hi, i want to konw about overlay..

June 21, 2011 - 7:09pm #17

Did you create a variable in your java class called currentActivity and set it? This isn't something Android does for you... Something like this:

public static MyPlayerActivity currentActivity;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    currentActivity = this;
}

If you've done that, can you run the application from Eclipse and have everything work correctly? I would debug in Eclipse, and only once it's working there try to create a jar and move it to the Unity project.

- Kim

Re: hi, i want to konw about overlay..

June 21, 2011 - 9:12am #16

Hi Kim,

I folowed your advices but I couldn't make it to work.
When I launch my application on my Android device from Eclipse, Unity works but 3D object doesn't appear and there is no reaction when I detect a marker.
I import my java code on Unity (by a .jar file) and when I launch it I have always the error "JNI : Unable to find field if for 'currentActivity' (static)".
I export my java code with Eclipse (File -> Export -> JAR file) and I copy the .jar (MyPlayer.jar) in the Plugins/Android folder of Unity, moreover, I copy the AndroidManifest.xml of my java code on the Plugins/Android folder too.

The name of my java package is the same of my Bundle Identifier of my Unity project (com.Romain.RA_Unity) and my personnal java code have the name of "MyPlayer.java". So, I call :

AndroidJavaClass jc = new AndroidJavaClass("com.Romain.RA_Unity.MyPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

But it doesn't work.

Did I forgot something ?

Thank you for your help,

Re: hi, i want to konw about overlay..

June 20, 2011 - 7:02pm #15

The set of instructions you have been following are specifically designed to allow you to run the application from Eclipse once everything is set up. If you want to run the project from Unity, you will need to create a jar file with your code and put it in the Plugins/Android folder. If you have changed the AndroidManifest.xml file you should copy that to the Plugins/Android folder as well.

- Kim

Re: hi, i want to konw about overlay..

June 20, 2011 - 2:05pm #14

Hi Kim,

Thank you for your help.
However I don't understand how to import my java code on Unity :
I managed to set up my project on Eclipse with the ADT and it's working fine when I run it from my Android device.

But now I don't know how to import this code on Unity. Should I replace the Temp/StagingArea of my Unity project by my Eclipse's one or should I export my Eclipse project as a .jar file and import it as a Plugins/Android on my Unity project ?

Thank you,

Re: hi, i want to konw about overlay..

June 20, 2011 - 6:43am #13

This thread may be helpful: http://ar.qualcomm.at/node/2000478

- Kim

Re: hi, i want to konw about overlay..

June 20, 2011 - 1:58am #12

Hi,

I'm sorry but I don't understand how to import Java source code in Unity.
I understand that I must to copy the content of Temp/StagingArea and create a new Android project in Eclipse with this content (http://forum.unity3d.com/threads/71607-Integrating-Unity-and-Eclipse) but I don't understand how to create and import my own Java code.
I think my AndroidManifest.xml is correct but I've always the error : "JNI : Unable to find field for id for 'currentActivity' (static)" (for example).

Anybody can help me ?

Thanks,

Re: hi, i want to konw about overlay..

May 9, 2011 - 7:05pm #11

thank u,kim

i succeed intent

i didn't change AndroidManifest.xml

again, thank U

and God bless U

Re: hi, i want to konw about overlay..

May 9, 2011 - 7:32am #10

I'm not sure, can you show us the Java class as well? Are you extending the main activity at all? If so, be sure to change the AndroidManifest.xml file to use your package and class name.

- Kim

Re: hi, i want to konw about overlay..

May 9, 2011 - 6:24am #9

i tried to make intent button as your advice.

but still it doesn't work
this is my device logcat


JNI: Unable to find method id for 'switchActivity'

I/Unity   ( 5030): UnityEngine.Debug:Internal_Log(Int32, String, Object)

I/Unity   ( 5030): UnityEngine.Debug:Log(Object)

I/Unity   ( 5030): UnityEngine._AndroidJNIHelper:GetMethodID(IntPtr, String, Object[], Boolean)

I/Unity   ( 5030): UnityEngine.AndroidJNIHelper:GetMethodID(IntPtr, String, Object[], Boolean)

I/Unity   ( 5030): UnityEngine.AndroidJavaObject:GetCachedMethodID(String, Object[], Boolean)

I/Unity   ( 5030): UnityEngine.AndroidJavaObject:_Call(String, Object[])

I/Unity   ( 5030): UnityEngine.AndroidJavaObject:Call(String, Object[])

I/Unity   ( 5030): JavaButtonHandler:OnGUI()

I/Unity   ( 5030):  

I/Unity   ( 5030): (Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

I/Unity   ( 5030): 

i made project, class, xml file . my package is com.dyu.gradation. main class is Grab

sure i have added C# script in my Unity project


using UnityEngine;
using System.Collections;

public class JavaButtonHandler : MonoBehaviour {

    void OnGUI()
    {
        if (GUI.Button(new Rect(10,10,150,100), "switch activity")) {
            print("*** JavaButtonHandler switch activity ***");
            AndroidJavaClass jc = new AndroidJavaClass("com.dyu.gradation.Grab");
            AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
            jo.Call("switchActivity");
        }
    }
}

why does not it work ? T^T

Re: hi, i want to konw about overlay..

May 8, 2011 - 5:07am #8

You're building and running an Eclipse project now, right? You place your Java class files and xml layouts in this project like any other Android project. Add new class files in Eclipse to the src folder, and new layout files to the res/layout folder.

The C# scripts are part of the Unity project. Each time you rebuild your Unity project you have to copy the assets folder over to the Eclipse project, if you are using the method outlined here: http://forum.unity3d.com/threads/71607-Integrating-Unity-and-Eclipse

- Kim

Re: hi, i want to konw about overlay..

May 6, 2011 - 6:29pm #7

ok. i see that

but i don't know where it should be placed for my class and my xml(layout) file

Re: hi, i want to konw about overlay..

May 6, 2011 - 5:46am #6

The switchActivity method was in my sample Java class. You will have to write some Java code as well for this to work. I chose to extend the main Activity, but you could also write a separate class with static methods. You then use AndroidJavaClass to access the Java class, and the GetStatic or CallStatic method to get/call a static variable/method in that class. See the Unity documentation for more details:

http://unity3d.com/support/documentation/ScriptReference/AndroidJavaClass.html

- Kim

Re: hi, i want to konw about overlay..

May 5, 2011 - 10:07pm #5

hi,
i did that Unity C# script

i clicked the button in Unity3D project

and then appear this message in the Unity console

JNI: Unable to find method id for 'switchActivity'
UnityEngine.AndroidJavaObject:Call(String, Object[])
JavaButtonHandler:OnGUI() (at Assets/Qualcomm Augmented Reality/Scripts/JavaButtonHandler.cs:12)

sorry, i dont know C# very well

please, give me the technique.

Re: hi, i want to konw about overlay..

May 3, 2011 - 11:46am #4

Here are two possible solutions, with sample code:

1) Create your buttons in Unity and call Java methods directly on button press (using AndroidJavaClass/AndroidJavaObject).

2) Create and handle your buttons in Java. The only issue here is that you don't know the exact point at which the OpenGL view is added on the Java side (the initialization sequence is asynchronous), so you still need to make a call from Unity to Java when everything is set up.

Here's a sample Java activity that can handle either case:

public class MyPlayerActivity extends com.qualcomm.QCARUnityPlayer.PlayerActivity
{
    public static MyPlayerActivity currentActivity;
    
    private Handler uiHandler;
    private View overlayView;
    private Button myButton;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        DebugLog.LOGI("*** MyPlayerActivity onCreate ***");
        currentActivity = this;
        
        uiHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                DebugLog.LOGI("*** uiHandler add overlay ***");
                overlayView = View.inflate(getApplicationContext(), R.layout.interface_overlay, null);
                addContentView(overlayView, new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.FILL_PARENT));
                
                myButton = (Button) overlayView.findViewById(R.id.mybutton);
                myButton.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        DebugLog.LOGI("*** uiHandler button clicked ***");
                        switchActivity();
                    }
                });
            }
        };
    }
    
    public void addCustomUI()
    {
        DebugLog.LOGI("*** MyPlayerActivity addCustomUI ***");
        // Use a handler because we are not currently in the UI thread
        uiHandler.sendEmptyMessage(0);
    }
    
    public void switchActivity()
    {
        DebugLog.LOGI("*** MyPlayerActivity switchActivity ***");
        Intent intent = new Intent(MyPlayerActivity.this, MySecondActivity.class);
        startActivity(intent);
    }
}

Here's a Unity C# script for the first option:

public class JavaButtonHandler : MonoBehaviour
{
    void OnGUI()
    {
        if (GUI.Button(new Rect(10,10,150,100), "switch activity")) {
            print("*** JavaButtonHandler switch activity ***");
            AndroidJavaClass jc = new AndroidJavaClass("com.qualcomm.MyPlayerActivity");
            AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
            jo.Call("switchActivity");
        }
    }
}

And here's a C# script for the second option:

public class JavaUIBuilder : MonoBehaviour
{
    void Start()
    {
        print("*** JavaUIBuilder Start ***");
        AndroidJavaClass jc = new AndroidJavaClass("com.qualcomm.MyPlayerActivity");
        AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
        jo.Call("addCustomUI");
    }
}

- Kim

Re: hi, i want to konw about overlay..

May 1, 2011 - 7:21am #3

always thanks to u , Kim

Actually, if i press my button that it has a intent() method , i want to change to my other Activity

so i should use java code. already i intergrated my Unity project with Eclipse

how can i do that?

Re: hi, i want to konw about overlay..

May 1, 2011 - 6:55am #2

It's probably easiest to build your UI using Unity, see the Unity documentation for details: http://unity3d.com/support/documentation/ScriptReference/GUI.html

You can also build your UI using Android, but it might be a bit tricky integrating it with the Unity project (this is an advanced exercise). Do the button presses need to trigger actions in the Unity scripts or in Java code?

- Kim

Log in or register to post comments