接入unity代码
This commit is contained in:
parent
029a930c48
commit
5926cab906
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -12,7 +12,9 @@
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="cocos2djs" />
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".MainActivity"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -84,6 +84,13 @@ android.applicationVariants.all { variant ->
|
||||
include "js/**"
|
||||
into outputDir
|
||||
}
|
||||
def sourceDirUnity = "/Users/zhl/Documents/workspace/unity/first/android/first/src/main/assets/"
|
||||
|
||||
copy {
|
||||
from "${sourceDirUnity}"
|
||||
include "bin/**"
|
||||
into outputDir
|
||||
}
|
||||
|
||||
// copy {
|
||||
// from "${sourceDir}/main.js"
|
||||
@ -101,4 +108,5 @@ dependencies {
|
||||
implementation project(':libcocos2dx')
|
||||
|
||||
implementation "androidx.appcompat:appcompat:1.0.2"
|
||||
implementation files('../libs/unity-classes.jar')
|
||||
}
|
BIN
app/libs/arm64-v8a/libil2cpp.so
Executable file
BIN
app/libs/arm64-v8a/libil2cpp.so
Executable file
Binary file not shown.
BIN
app/libs/arm64-v8a/libmain.so
Executable file
BIN
app/libs/arm64-v8a/libmain.so
Executable file
Binary file not shown.
BIN
app/libs/arm64-v8a/libunity.so
Executable file
BIN
app/libs/arm64-v8a/libunity.so
Executable file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libMonoPosixHelper.so
Executable file
BIN
app/libs/armeabi-v7a/libMonoPosixHelper.so
Executable file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libil2cpp.so
Executable file
BIN
app/libs/armeabi-v7a/libil2cpp.so
Executable file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libmain.so
Executable file
BIN
app/libs/armeabi-v7a/libmain.so
Executable file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libmonobdwgc-2.0.so
Executable file
BIN
app/libs/armeabi-v7a/libmonobdwgc-2.0.so
Executable file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libunity.so
Executable file
BIN
app/libs/armeabi-v7a/libunity.so
Executable file
Binary file not shown.
BIN
app/libs/x86/libMonoPosixHelper.so
Executable file
BIN
app/libs/x86/libMonoPosixHelper.so
Executable file
Binary file not shown.
BIN
app/libs/x86/libil2cpp.so
Executable file
BIN
app/libs/x86/libil2cpp.so
Executable file
Binary file not shown.
BIN
app/libs/x86/libmain.so
Executable file
BIN
app/libs/x86/libmain.so
Executable file
Binary file not shown.
BIN
app/libs/x86/libmonobdwgc-2.0.so
Executable file
BIN
app/libs/x86/libmonobdwgc-2.0.so
Executable file
Binary file not shown.
BIN
app/libs/x86/libunity.so
Executable file
BIN
app/libs/x86/libunity.so
Executable file
Binary file not shown.
@ -1,20 +1,41 @@
|
||||
package com.fitchgc.headlesscocos;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Window;
|
||||
|
||||
import com.unity3d.player.UnityPlayer;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper;
|
||||
import org.cocos2dx.lib.CocosJSHelper;
|
||||
|
||||
|
||||
public class MainActivity extends Activity implements Cocos2dxHelper.Cocos2dxHelperListener {
|
||||
protected UnityPlayer mUnityPlayer;
|
||||
|
||||
protected String updateUnityCommandLineArguments(String cmdLine)
|
||||
{
|
||||
return cmdLine;
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity"));
|
||||
getIntent().putExtra("unity", cmdLine);
|
||||
|
||||
mUnityPlayer = new UnityPlayer(this);
|
||||
setContentView(mUnityPlayer);
|
||||
mUnityPlayer.requestFocus();
|
||||
|
||||
// setContentView(R.layout.activity_main);
|
||||
onLoadNativeLibraries();
|
||||
Cocos2dxHelper.init(this);
|
||||
CocosJSHelper.initJSEnv(getApplicationContext());
|
||||
@ -40,4 +61,94 @@ public class MainActivity extends Activity implements Cocos2dxHelper.Cocos2dxHel
|
||||
public void runOnGLThread(Runnable pRunnable) {
|
||||
|
||||
}
|
||||
|
||||
// begin for unity
|
||||
@Override protected void onNewIntent(Intent intent)
|
||||
{
|
||||
// To support deep linking, we need to make sure that the client can get access to
|
||||
// the last sent intent. The clients access this through a JNI api that allows them
|
||||
// to get the intent set on launch. To update that after launch we have to manually
|
||||
// replace the intent with the one caught here.
|
||||
setIntent(intent);
|
||||
}
|
||||
|
||||
// Quit Unity
|
||||
@Override protected void onDestroy ()
|
||||
{
|
||||
mUnityPlayer.destroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
// Pause Unity
|
||||
@Override protected void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
mUnityPlayer.pause();
|
||||
}
|
||||
|
||||
// Resume Unity
|
||||
@Override protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
mUnityPlayer.resume();
|
||||
}
|
||||
|
||||
@Override protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
mUnityPlayer.start();
|
||||
}
|
||||
|
||||
@Override protected void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
mUnityPlayer.stop();
|
||||
}
|
||||
|
||||
// Low Memory Unity
|
||||
@Override public void onLowMemory()
|
||||
{
|
||||
super.onLowMemory();
|
||||
mUnityPlayer.lowMemory();
|
||||
}
|
||||
|
||||
// Trim Memory Unity
|
||||
@Override public void onTrimMemory(int level)
|
||||
{
|
||||
super.onTrimMemory(level);
|
||||
if (level == TRIM_MEMORY_RUNNING_CRITICAL)
|
||||
{
|
||||
mUnityPlayer.lowMemory();
|
||||
}
|
||||
}
|
||||
|
||||
// This ensures the layout will be correct.
|
||||
@Override public void onConfigurationChanged(Configuration newConfig)
|
||||
{
|
||||
super.onConfigurationChanged(newConfig);
|
||||
mUnityPlayer.configurationChanged(newConfig);
|
||||
}
|
||||
|
||||
// Notify Unity of the focus change.
|
||||
@Override public void onWindowFocusChanged(boolean hasFocus)
|
||||
{
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
mUnityPlayer.windowFocusChanged(hasFocus);
|
||||
}
|
||||
|
||||
// For some reason the multiple keyevent type is not supported by the ndk.
|
||||
// Force event injection by overriding dispatchKeyEvent().
|
||||
@Override public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
|
||||
return mUnityPlayer.injectEvent(event);
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
// Pass any events not handled by (unfocused) views straight to UnityPlayer
|
||||
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
|
||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
|
||||
@Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
|
||||
/*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
|
||||
|
||||
}
|
BIN
libs/unity-classes.jar
Normal file
BIN
libs/unity-classes.jar
Normal file
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">HeadlessCocos</string>
|
||||
<string name="game_view_content_description">Game view</string>
|
||||
</resources>
|
12
res/values/styles.xml
Normal file
12
res/values/styles.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="UnityThemeSelector" parent="BaseUnityTheme">
|
||||
<item name="android:windowBackground">@android:color/black</item>
|
||||
</style>
|
||||
<style name="BaseUnityTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
|
||||
</style>
|
||||
<style name="UnityThemeSelector.Translucent" parent="@style/UnityThemeSelector">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user