Java is always pass-by-value. Unfortunately, when we deal with objects we are really dealing with object-handles called references which are passed-by-value as well. This terminology and semantics easily confuse many beginners.
It goes like this:
public static void main(String[] args) {
Dog aDog = new Dog("Max");
Dog oldDog = aDog;
// we pass the object to foo
foo(aDog);
// aDog variable is still pointing to the "Max" dog when foo(...) returns
aDog.getName().equals("Max"); // true
aDog.getName().equals("Fifi"); // false
aDog == oldDog; // true
}
public static void foo(Dog d) {
d.getName().equals("Max"); // true
// change d inside of foo() to point to a new Dog instance "Fifi"
d = new Dog("Fifi");
d.getName().equals("Fifi"); // true
}
In the example above aDog.getName()
will still return "Max"
. The value aDog
within main
is not changed in the function foo
with the Dog
"Fifi"
as the object reference is passed by value. If it were passed by reference, then the aDog.getName()
in main
would return "Fifi"
after the call to foo
.
Likewise:
public static void main(String[] args) {
Dog aDog = new Dog("Max");
Dog oldDog = aDog;
foo(aDog);
// when foo(...) returns, the name of the dog has been changed to "Fifi"
aDog.getName().equals("Fifi"); // true
// but it is still the same dog:
aDog == oldDog; // true
}
public static void foo(Dog d) {
d.getName().equals("Max"); // true
// this changes the name of d to be "Fifi"
d.setName("Fifi");
}
In the above example, Fifi
is the dog's name after call to foo(aDog)
because the object's name was set inside of foo(...)
. Any operations that foo
performs on d
are such that, for all practical purposes, they are performed on aDog
, but it is not possible to change the value of the variable aDog
itself.
For more information on pass by reference and pass by value, consult the following SO answer: https://stackoverflow.com/a/430958/6005228. This explains more thoroughly the semantics and history behind the two and also explains why Java and many other modern languages appear to do both in certain cases.
Exporting and running Unity3D project to Android Studio is not really hard. Make sure the you have the latest version of Unity(5.4) and Android Studio(2.1.3). This steps were made with the version mentioned above.
EXPORTING TO Android Studio:
1.Create a root folder that will hold the exported folders and files. Let's call it AndroidTestProject
in this case and the full Directory will be C:/AndroidTestProject
.
2.Exporting to C:/AndroidTestProject
.
A.File->Build Settings...
B.Select Android on the left then tick Google Android Project checkbox.
Image Description:
C.Click the Export Button.
D.Select C:/AndroidTestProject
then click the Select Folder Button.
Image Description:
Unity will build your project.
After Generating the project, a new folder will be created in the C:/AndroidTestProject
directory. That folder will be named whatever your Product Name is in the Player Settings. This what my product name is in the Player Settings:
Image Description:
So in my case, the new Folder name will be called test and will be located at C:/AndroidTestProject/test
.
IMPORTING INTO Android Studio:
1.Create a new Folder called AndroidStudio in the C:/AndroidTestProject/
directory. The full path of that folder should be C:/AndroidTestProject/AndroidStudio
.
A.Open Android Studio. When you open Android Studio, click on Import project (Eclipse ADT,Gradle, etc.)
If Import project (Eclipse ADT,Gradle, etc.) is not displayed, close the current project by going to File->Close Project.
Image Description:
B.Go to the full directory of the exported project C:/AndroidTestProject/test
then select the test folder which is the Product Name of your project then click Ok.
Image Description:
C.A new Window will pop up. Set the Import Destination Directory to be C:/AndroidTestProject/AndroidStudio
which was created in step 1.
Image Description:
D.Click the Next Button.
Tick/Select the follwing check boxes:
- Replace jars with dependencies, when possible.
- Replace library sources with dependencies, when possible.
- Create Gradle-style (CamelCase) module names.
then click the Finish Button.
Image Description:
2.Wait for Android Studio to load your project.
You will get an error that looks like this:
Error:Minimum supported Gradle version is 2.14.1. Current version is
2.10. If using the gradle wrapper, try editing the distributionUrl in C:\AndroidTestProject\AndroidStudio\gradle\wrapper\gradle-wrapper.properties
to gradle-2.14.1-all.zip Fix
Gradle wrapper and re-import project
Gradle settings
A.Simply click on the Fix Gradle wrapper and re-import project Gradle settings message. If you don't see this message, make sure that you are in the Messages Tab. Look at the image below for more information.
Image Description:
B.Wait for Android Studio to finish fixing the Gradle problem.
When finished, go to Build->Make Project.
After project is done building, go to Run->Run 'app'.
C.A new Window will pop up. You can either chose the device to run the app on, create an emulator or chose already existing emulator to run the app. In this example we will use a real device to test.
Under Connected Devices, select your device then click the OK button.
Image Description:
Extra:
A.If you want to be able to debug your App, you have to enable that from Unity. Go back to EXPORTING TO Android Studio step 2B and enable Development Build.Also select Script Debugging then click the Export Button.
B.If you want to see Debug.Log
messages, go to the Android Monitor Tab in the Android Studio.
The circled items in the image below are important to know when Debugging in Android Studio.
Image Description:
This is not really hard. If you do it once, you won't need this instruction again.
Best Answer
How about adding this to your pom.xml