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

View File

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

View File

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

Binary file not shown.

View File

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