4

我正在尝试在 docs.unity3d 的帮助下扩展 UnityPlayerActivity。我有一个带有 MainActivity 类的简单 jar 文件,并且还将文件 classes.jar 包含到 libs 文件夹中。我的类文件有以下代码。

package com.example.testactivity;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.unity3d.player.UnityPlayerActivity;

public class MainActivity extends UnityPlayerActivity
{

@Override
public void onCreate(Bundle savedInstanceState) {
  Log.i("Hiren","==============ON CREATE CALLED==============");
  super.onCreate(savedInstanceState);
}


public static void callMe()
{
   Log.i("Hiren","==============Function CALLED==============");
}
}

我可以通过我的 c# 脚本调用静态函数 callMe (),但我的 onCreate() 在活动开始时没有被调用。我的 C# 脚本是

private static FBShare _instance;

public static FBShare Instance
{
get
{
  if(_instance == null)
     _instance = new FBShare();
  return _instance;
}
}

private AndroidJavaClass cls_Fb = new AndroidJavaClass("com.example.testactivity.MainActivity");

public void CallMe()
{

  using(AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  {

    using(AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    {
      cls_Fb.CallStatic("callMe");
    }
  }

当我调用“CallMe”方法时,我会得到被调用的日志。但我没有从 onCreate() 得到任何日志。

AndroidMenifest.xml 文件包含

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.testactivity.MainActivity"
    android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application

        android:label="@string/app_name"
        android:debuggable="true">
        <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <meta-data android:name="android.app.lib_name" android:value="unity" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        </activity>
        <activity android:name="com.unity3d.player.VideoPlayer"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>
        <activity android:name=".MainActivity"  
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation" >
              <meta-data android:name="android.app.lib_name" android:value="unity" />
                <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
        </activity>
        <uses-library android:name="com.google.android.maps" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_INTERNET" />

    </application>
</manifest>
4

1 回答 1

2

正如尼古拉斯所说,检查清单确保这部分是正确的

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
于 2013-05-13T19:15:29.390 回答