├── GameScript.cs ├── LICENSE ├── README.md └── TapGame ├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libs └── unity-classes.jar ├── proguard-unity.txt └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── RohansCompany │ └── TapGame │ ├── MainActivity.java │ ├── MiddleActivity.java │ ├── ResultActivity.java │ ├── UnityPlayerActivity.java │ ├── UnityPlayerNativeActivity.java │ └── UnityPlayerProxyActivity.java ├── jniLibs ├── armeabi-v7a │ ├── libmain.so │ ├── libmono.so │ └── libunity.so └── x86 │ ├── libmain.so │ ├── libmono.so │ └── libunity.so └── res ├── drawable-mdpi └── app_icon.png ├── drawable-xhdpi └── app_banner.png ├── layout ├── activity_main.xml ├── activity_middle.xml └── activity_result.xml ├── values-v14 └── styles.xml ├── values-v21 └── styles.xml └── values ├── strings.xml └── styles.xml /GameScript.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | 7 | public class GameScript : MonoBehaviour { 8 | 9 | AndroidJavaClass UnityPlayer; 10 | AndroidJavaObject currentActivity; 11 | 12 | int args; 13 | 14 | int tap_count; 15 | 16 | [SerializeField] 17 | private Text score; 18 | 19 | void Start () { 20 | tap_count = 0; 21 | 22 | UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 23 | currentActivity = UnityPlayer.GetStatic("currentActivity"); 24 | 25 | AndroidJavaObject intent = currentActivity.Call("getIntent"); 26 | bool hasExtra = intent.Call ("hasExtra", "arguments"); 27 | 28 | if (hasExtra) { 29 | AndroidJavaObject extras = intent.Call ("getExtras"); 30 | args = extras.Call ("getInt", "arguments"); 31 | 32 | score.text = "" + args; 33 | tap_count = args; 34 | } 35 | } 36 | 37 | void Update () { 38 | 39 | } 40 | 41 | public void buttonTapped() { 42 | 43 | tap_count += 1; 44 | score.text = "" + tap_count; 45 | } 46 | 47 | public void buttonFinish() { 48 | //Application.Quit (); 49 | currentActivity.Call("onGameFinish", tap_count); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Rohan Gupta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Integrating Unity 3D game engine within an Android App 2 | 3 | This project covers the process of integrating a game made with Unity within a native Android Application. 4 | 5 | 6 | 7 | ## Objective 8 | 9 | Integrate a **Unity Game** within an **Android App**, and establish a way for **Communication** / **Data Transfer** between the two, i.e., 10 | 11 | 1. From the Android App, **Start the game** and **Send** an initial score to Unity. 12 | 2. **Receive** the score in Unity. **Play the game** and increment the score. **Send** the final score back to Android. 13 | 3. Back in Android, **Get** the score from Unity and finally display it. 14 | 15 | ## Getting Started 16 | 17 | ### Unity 18 | 19 | I have made a simple game using Unity, in which the score increments on clicking the **TAP** button. On clicking the **Finish** button, the game ends. Then I exported the project using **Gradle**. 20 | 21 | ### Android Studio 22 | 23 | I then opened this project using **Android Studio** (Import Gradle Project). You can either convert this project into an **Android Archive Library (AAR)** and import it in your own Android Studio project or you can modify this project itself. I chose the latter option for this project. Unity creates the **UnityPlayerActivity**, containing the **UnityPlayer**, in Android. This class is used for all communications with Unity. I added more Activities to the Project, to execute the complete flow. 24 | 25 | 26 | **For more info:** [Detailed Guide to Embed Unity into Android](https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a) 27 | 28 | ## Communication / Data Transfer 29 | 30 | ### 1. Android (Java) -> Unity (C#) 31 | 32 | **In Android**, start the *UnityPlayerActivity* from your Activity with an Intent and add data to this intent using `putExtra` 33 | ``` 34 | Intent intent = new Intent(this, UnityPlayerActivity.class); 35 | intent.putExtra("arguments", 50); 36 | startActivity(intent); 37 | ``` 38 | 39 | **In Unity**, retrieve the data from the Intent as shown below 40 | ``` 41 | int tap_count; 42 | 43 | void Start () { 44 | AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 45 | AndroidJavaObject currentActivity = UnityPlayer.GetStatic ("currentActivity"); 46 | 47 | AndroidJavaObject intent = currentActivity.Call("getIntent"); 48 | bool hasExtra = intent.Call ("hasExtra", "arguments"); 49 | 50 | if (hasExtra) { 51 | AndroidJavaObject extras = intent.Call ("getExtras"); 52 | tap_count = extras.Call ("getInt", "arguments"); 53 | } 54 | } 55 | ``` 56 | 57 | ### 2. Unity (C#) -> Android (Java) 58 | 59 | **In Android**, create a method in *UnityPlayerActivity* to receive data from Unity. This method can be directly called from Unity as shown in the next section 60 | ``` 61 | public void onGameFinish(int score) { 62 | Intent resultIntent = new Intent(this, ResultActivity.class); 63 | resultIntent.putExtra("score", score); 64 | startActivity(resultIntent); 65 | } 66 | ``` 67 | 68 | **In Unity**, call the method defined in the *UnityPlayerActivity* with the arguments 69 | ``` 70 | currentActivity.Call("onGameFinish", tap_count); 71 | ``` 72 | 73 | ## Built With 74 | 75 | - [Unity 5.6.3](https://unity3d.com/) 76 | - [Android Studio 2.3.3](https://developer.android.com/studio/index.html) 77 | 78 | ## License 79 | 80 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details -------------------------------------------------------------------------------- /TapGame/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | # Uncomment the following line if you do not want to check your keystore files in. 45 | #*.jks 46 | 47 | # External native build folder generated in Android Studio 2.2 and later 48 | .externalNativeBuild 49 | 50 | # Google Services (e.g. APIs or Firebase) 51 | google-services.json 52 | 53 | # Freeline 54 | freeline.py 55 | freeline/ 56 | freeline_project_description.json -------------------------------------------------------------------------------- /TapGame/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /TapGame/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /TapGame/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | -------------------------------------------------------------------------------- /TapGame/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TapGame/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /TapGame/build.gradle: -------------------------------------------------------------------------------- 1 | // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | flatDir { 15 | dirs 'libs' 16 | } 17 | } 18 | } 19 | 20 | apply plugin: 'com.android.application' 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:26.+' 25 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 26 | } 27 | 28 | android { 29 | compileSdkVersion 26 30 | buildToolsVersion '26.0.1' 31 | 32 | defaultConfig { 33 | targetSdkVersion 26 34 | applicationId 'com.RohansCompany.TapGame' 35 | } 36 | 37 | lintOptions { 38 | abortOnError false 39 | } 40 | 41 | aaptOptions { 42 | noCompress '.unity3d', '.ress', '.resource', '.obb' 43 | } 44 | 45 | 46 | buildTypes { 47 | debug { 48 | jniDebuggable true 49 | } 50 | release { 51 | // Set minifyEnabled to true if you want to run ProGuard on your project 52 | minifyEnabled false 53 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt' 54 | 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /TapGame/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /TapGame/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 14 14:09:07 IST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip 7 | -------------------------------------------------------------------------------- /TapGame/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /TapGame/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /TapGame/libs/unity-classes.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/libs/unity-classes.jar -------------------------------------------------------------------------------- /TapGame/proguard-unity.txt: -------------------------------------------------------------------------------- 1 | -keep class bitter.jnibridge.* { *; } 2 | -keep class com.unity3d.player.* { *; } 3 | -keep class org.fmod.* { *; } 4 | -------------------------------------------------------------------------------- /TapGame/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 19 | 20 | 21 | 24 | 25 | 26 | 29 | 32 | 33 | 36 | 39 | 42 | 43 | 44 | 45 | 51 | 57 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | 10 | import com.RohansCompany.TapGame.R; 11 | 12 | public class MainActivity extends Activity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | } 19 | 20 | public void onPlayClick(View view) { 21 | Intent intent = new Intent(MainActivity.this, MiddleActivity.class); 22 | startActivity(intent); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/MiddleActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | 8 | public class MiddleActivity extends Activity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_middle); 14 | 15 | Intent intent = new Intent(this, UnityPlayerActivity.class); 16 | intent.putExtra("arguments", 50); 17 | startActivity(intent); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | import com.RohansCompany.TapGame.R; 10 | 11 | public class ResultActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_result); 17 | 18 | int score = getIntent().getIntExtra("score", 0); 19 | 20 | TextView displayScore = (TextView) findViewById(R.id.tvScore); 21 | 22 | displayScore.setText(String.valueOf(score)); 23 | } 24 | 25 | public void onHomeClick(View view) { 26 | 27 | Intent homeIntent = new Intent(this, MainActivity.class); 28 | startActivity(homeIntent); 29 | } 30 | 31 | @Override 32 | public void onBackPressed() { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/UnityPlayerActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import com.unity3d.player.*; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.content.res.Configuration; 7 | import android.graphics.PixelFormat; 8 | import android.os.Bundle; 9 | import android.view.KeyEvent; 10 | import android.view.MotionEvent; 11 | import android.view.Window; 12 | 13 | public class UnityPlayerActivity extends Activity 14 | { 15 | protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code 16 | 17 | // Setup activity layout 18 | @Override protected void onCreate (Bundle savedInstanceState) 19 | { 20 | requestWindowFeature(Window.FEATURE_NO_TITLE); 21 | super.onCreate(savedInstanceState); 22 | 23 | getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy 24 | 25 | mUnityPlayer = new UnityPlayer(this); 26 | setContentView(mUnityPlayer); 27 | mUnityPlayer.requestFocus(); 28 | } 29 | 30 | @Override protected void onNewIntent(Intent intent) 31 | { 32 | // To support deep linking, we need to make sure that the client can get access to 33 | // the last sent intent. The clients access this through a JNI api that allows them 34 | // to get the intent set on launch. To update that after launch we have to manually 35 | // replace the intent with the one caught here. 36 | setIntent(intent); 37 | } 38 | 39 | public void onGameFinish(int score) { 40 | 41 | Intent resultIntent = new Intent(this, ResultActivity.class); 42 | resultIntent.putExtra("score", score); 43 | startActivity(resultIntent); 44 | } 45 | 46 | // Quit Unity 47 | @Override protected void onDestroy () 48 | { 49 | mUnityPlayer.quit(); 50 | super.onDestroy(); 51 | } 52 | 53 | // Pause Unity 54 | @Override protected void onPause() 55 | { 56 | super.onPause(); 57 | mUnityPlayer.pause(); 58 | } 59 | 60 | // Resume Unity 61 | @Override protected void onResume() 62 | { 63 | super.onResume(); 64 | mUnityPlayer.resume(); 65 | } 66 | 67 | // Low Memory Unity 68 | @Override public void onLowMemory() 69 | { 70 | super.onLowMemory(); 71 | mUnityPlayer.lowMemory(); 72 | } 73 | 74 | // Trim Memory Unity 75 | @Override public void onTrimMemory(int level) 76 | { 77 | super.onTrimMemory(level); 78 | if (level == TRIM_MEMORY_RUNNING_CRITICAL) 79 | { 80 | mUnityPlayer.lowMemory(); 81 | } 82 | } 83 | 84 | // This ensures the layout will be correct. 85 | @Override public void onConfigurationChanged(Configuration newConfig) 86 | { 87 | super.onConfigurationChanged(newConfig); 88 | mUnityPlayer.configurationChanged(newConfig); 89 | } 90 | 91 | // Notify Unity of the focus change. 92 | @Override public void onWindowFocusChanged(boolean hasFocus) 93 | { 94 | super.onWindowFocusChanged(hasFocus); 95 | mUnityPlayer.windowFocusChanged(hasFocus); 96 | } 97 | 98 | // For some reason the multiple keyevent type is not supported by the ndk. 99 | // Force event injection by overriding dispatchKeyEvent(). 100 | @Override public boolean dispatchKeyEvent(KeyEvent event) 101 | { 102 | if (event.getAction() == KeyEvent.ACTION_MULTIPLE) 103 | return mUnityPlayer.injectEvent(event); 104 | return super.dispatchKeyEvent(event); 105 | } 106 | 107 | // Pass any events not handled by (unfocused) views straight to UnityPlayer 108 | @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } 109 | @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } 110 | @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } 111 | /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } 112 | } 113 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/UnityPlayerNativeActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | 6 | /** 7 | * @deprecated It's recommended that you base your code directly on UnityPlayerActivity or make your own NativeActitivty implementation. 8 | **/ 9 | public class UnityPlayerNativeActivity extends UnityPlayerActivity 10 | { 11 | @Override protected void onCreate (Bundle savedInstanceState) 12 | { 13 | Log.w("Unity", "UnityPlayerNativeActivity has been deprecated, please update your AndroidManifest to use UnityPlayerActivity instead"); 14 | super.onCreate(savedInstanceState); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TapGame/src/main/java/com/RohansCompany/TapGame/UnityPlayerProxyActivity.java: -------------------------------------------------------------------------------- 1 | package com.RohansCompany.TapGame; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | 8 | /** 9 | * @deprecated Use UnityPlayerActivity instead. 10 | */ 11 | public class UnityPlayerProxyActivity extends Activity 12 | { 13 | @Override protected void onCreate (Bundle savedInstanceState) 14 | { 15 | Log.w("Unity", "UnityPlayerNativeActivity has been deprecated, please update your AndroidManifest to use UnityPlayerActivity instead"); 16 | super.onCreate(savedInstanceState); 17 | 18 | Intent intent = new Intent(this, com.RohansCompany.TapGame.UnityPlayerActivity.class); 19 | intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 20 | Bundle extras = getIntent().getExtras(); 21 | if (extras != null) 22 | intent.putExtras(extras); 23 | startActivity(intent); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/armeabi-v7a/libmain.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/armeabi-v7a/libmain.so -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/armeabi-v7a/libmono.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/armeabi-v7a/libmono.so -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/armeabi-v7a/libunity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/armeabi-v7a/libunity.so -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/x86/libmain.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/x86/libmain.so -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/x86/libmono.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/x86/libmono.so -------------------------------------------------------------------------------- /TapGame/src/main/jniLibs/x86/libunity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/jniLibs/x86/libunity.so -------------------------------------------------------------------------------- /TapGame/src/main/res/drawable-mdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/res/drawable-mdpi/app_icon.png -------------------------------------------------------------------------------- /TapGame/src/main/res/drawable-xhdpi/app_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohangupta/android-unity/65a899caa48e867fde0b4480a4609c8fe1273966/TapGame/src/main/res/drawable-xhdpi/app_banner.png -------------------------------------------------------------------------------- /TapGame/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |