change unity version to 2021

This commit is contained in:
zhl 2023-02-06 14:45:58 +08:00
parent 3f5e33c1ba
commit ebaf16c138
5 changed files with 49 additions and 42 deletions

View File

@ -5,7 +5,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion PROP_BUILD_TOOLS_VERSION
ndkVersion "21.4.7075529"
ndkVersion "21.3.6528147"
defaultConfig {
applicationId "com.cege.games.release"
@ -108,13 +108,13 @@ android.applicationVariants.all { variant ->
from "${sourceDir}/cert/cacert.pem"
into outputDir
}
def sourceDirUnity = rootProject.ext.cfgs.unityAndroidProject + "/src/main/assets/"
copy {
from "${sourceDirUnity}"
include "**"
into outputDir
}
// def sourceDirUnity = rootProject.ext.cfgs.unityAndroidProject + "/src/main/assets/"
//
// copy {
// from "${sourceDirUnity}"
// include "**"
// into outputDir
// }
}
}
@ -123,6 +123,8 @@ dependencies {
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation project(':unityLibrary')
implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
implementation fileTree(dir: rootProject.ext.cfgs.cocos2dxBasePath + "/cocos/platform/android/java/libs", include: ['*.jar'])
implementation project(':libcocos2dx')

View File

@ -38,7 +38,7 @@ import com.jc.jcfw.util.FileUtils;
import com.king.zxing.CameraScan;
import com.king.zxing.util.CodeUtils;
import com.king.zxing.util.LogUtils;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
import net.openid.appauth.AppAuthConfiguration;
import net.openid.appauth.AuthState;
@ -78,13 +78,12 @@ import pub.devrel.easypermissions.EasyPermissions;
import static com.cege.games.release.dialog.QRCodeActivity.RC_SAVE_QR;
public class MainActivity extends Activity
public class MainActivity extends UnityPlayerActivity
implements Cocos2dxHelper.Cocos2dxHelperListener, EasyPermissions.PermissionCallbacks {
private static final String TAG = MainActivity.class.getSimpleName();
public static MainActivity app;
protected UnityPlayer mUnityPlayer;
// protected UnityPlayer mUnityPlayer;
private Toast toast;
public static final String KEY_TITLE = "key_title";
@ -144,9 +143,9 @@ public class MainActivity extends Activity
String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity"));
getIntent().putExtra("unity", cmdLine);
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
// mUnityPlayer = new UnityPlayer(this);
// setContentView(mUnityPlayer);
// mUnityPlayer.requestFocus();
onLoadNativeLibraries();
app = this;
@ -235,7 +234,7 @@ public class MainActivity extends Activity
@Override
protected void onStart() {
super.onStart();
mUnityPlayer.start();
// mUnityPlayer.start();
if (mExecutor.isShutdown()) {
mExecutor = Executors.newSingleThreadExecutor();
@ -246,7 +245,7 @@ public class MainActivity extends Activity
@Override
protected void onResume() {
super.onResume();
mUnityPlayer.resume();
// mUnityPlayer.resume();
}
// begin for unity
@ -263,19 +262,19 @@ public class MainActivity extends Activity
@Override
protected void onPause() {
super.onPause();
mUnityPlayer.pause();
// mUnityPlayer.pause();
}
@Override
protected void onStop() {
super.onStop();
mUnityPlayer.stop();
// mUnityPlayer.stop();
}
// Quit Unity
@Override
protected void onDestroy() {
mUnityPlayer.destroy();
// mUnityPlayer.destroy();
super.onDestroy();
}
@ -283,14 +282,14 @@ public class MainActivity extends Activity
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
// mUnityPlayer.configurationChanged(newConfig);
}
// Low Memory Unity
@Override
public void onLowMemory() {
super.onLowMemory();
mUnityPlayer.lowMemory();
// mUnityPlayer.lowMemory();
}
// Trim Memory Unity
@ -298,44 +297,44 @@ public class MainActivity extends Activity
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
mUnityPlayer.lowMemory();
// mUnityPlayer.lowMemory();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// return mUnityPlayer.injectEvent(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 onKeyUp(int keyCode, KeyEvent event) {
// return mUnityPlayer.injectEvent(event);
// }
@Override
public boolean onTouchEvent(MotionEvent 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);
}
// public boolean onGenericMotionEvent(MotionEvent event) {
// return mUnityPlayer.injectEvent(event);
// }
// Notify Unity of the focus change.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(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);
// if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
// return mUnityPlayer.injectEvent(event);
return super.dispatchKeyEvent(event);
}

View File

@ -19,8 +19,11 @@ allprojects {
google()
jcenter()
maven { url "https://artifact.bytedance.com/repository/AwemeOpenSDK" }
// flatDir {
// dirs "libs"
// }
flatDir {
dirs 'libs'
dirs "${project(':unityLibrary').projectDir}/libs","libs"
}
}
}

Binary file not shown.

View File

@ -3,3 +3,6 @@ include ':app'
rootProject.name = "HeadlessCocos"
include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File(ext.cfgs.cocos2dxBasePath + '/cocos/platform/android/libcocos2dx')
include ':unityLibrary'
project(':unityLibrary').projectDir = new File(ext.cfgs.unityAndroidProject + '/unityLibrary')