Monday, October 31, 2016

build android library on command line



android create lib-project --name UnityLibProject --target 1 --path . --package com.ebmajor.unitylib

- create project      : Creates a new Android project.
- create lib-project  : Creates a new Android library project.

UnityLibProject.java:

package com.ebmajor.unitylib;

public class UnityLibProject
{
    public static float GetValue()
    {
        return 1.0f;
    }
}

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="AndroidPlugin" default="help">

    ... default stuff ...

    <target name="jar" depends="debug">
        <jar
            destfile="bin/UnityLib.jar"
            basedir="bin/classes" />
    </target>

</project>

ant jar




android update lib-project
android update project

android update -h

Monday, October 17, 2016

unity calls method in android plugin

for non-static method in android plugin return void

Calls a Java method on an object (non-static).
jo.Call("setToDefaults");

for non-static method in android plugin return int
        AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some string");

        int hash = jo.Call<int>("hashCode");

for static method in android plugin

AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");


AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
jc.CallStatic("UnitySendMessage", "Main Camera", "JavaMessage", "whoowhoo");



AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
pluginClass.CallStatic("initialize", context);
    static public void initialize (Context unityContext){
        try {
            MyApp.initialize(unityContext);
        } catch (NullPointerException e){
            Log.d("UnityPlugin", "Null PTR Exception");
            e.printStackTrace();
        }
    }
 void OnDestroy() {
        int ret;
        AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
        AndroidJavaClass plugIn = new AndroidJavaClass("com.ebmajor.plugin.MyReceiver");
        ret = plugIn.CallStatic<int>("sendExitEvent", context, 10);
        Debug.LogError("android lib: sendExitEvent returned: " + ret);
    }

public static int sendExitEvent(Context context, int val) {
    Intent intent = new Intent();
    intent.setAction("com.ebmajor.ACTION");
    context.sendBroadcast(intent);
    return 1;
}
=========================================================================================

==========================================================================================
android plug-in under Unity
==========================================================================================

package com.le.androidlib;
public class MyActivity extends UnityPlayerActivity {
    static public String getArgs() {
        return uri_arg;
    }
}

==========================================================================================
Unity.cs
==========================================================================================

void Awake()
{
        AndroidJavaObject jo = new AndroidJavaObject("com.le.androidlib.MyActivity");
        string arg = jo.CallStatic<string>("getArgs"); //string return
        Debug.Log("MediaPlayer: arg: " + arg);
        jo.CallStatic<int>("getArgsInt"); //int return
        jo.CallStatic("flushPendingCommands"); //void return
}
==========================================================================================

Unity object script call prodecure

Object 1 - script 1

Android media player - script 2

MainCamera - script 3

----->>>
media player: start()

camera script: start()

object 1 script: start()


----->>> to quit Unity Application,
call "Application.Quit();"

------>>>>

object 1 script:  OnApplicationQuit()

--- no camera scipt is called

media player:  OnApplicationQuit()

--->>> OnDestroy() is called later than OnApplicationQuit()

object 1 script: OnDestroy()

camera script: OnDestroy()

media player: OnDestroy()


==== start and destroy is reverse order ======

Friday, October 14, 2016

androiod background splash screen


https://www.bignerdranch.com/blog/splash-screens-the-right-way/

https://github.com/cstew/Splash/blob/master/app/src

Thursday, October 13, 2016

Linux key event



According to the Linux input documentation, section 5, the /dev/input/eventX devices return data as following:
You can use blocking and nonblocking reads, also select() on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:
struct input_event {
      struct timeval time;
      unsigned short type;
      unsigned short code;
      unsigned int value; };
'time' is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, EV_KEY for a keypress or release. More types are defined in include/linux/input.h.
'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.
'value' is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.

Event: type 4 (Misc), code 4 (ScanCode), value 458783   [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event] 
Event: type 4 (Misc), code 4 (ScanCode), value 458783    [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

In andriod,
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event] 
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

Linux key event



According to the Linux input documentation, section 5, the /dev/input/eventX devices return data as following:
You can use blocking and nonblocking reads, also select() on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:
struct input_event {
      struct timeval time;
      unsigned short type;
      unsigned short code;
      unsigned int value; };
'time' is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, EV_KEY for a keypress or release. More types are defined in include/linux/input.h.
'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.
'value' is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.

Event: type 4 (Misc), code 4 (ScanCode), value 458783   [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event] 
Event: type 4 (Misc), code 4 (ScanCode), value 458783    [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

In andriod,
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event] 
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

Wednesday, October 12, 2016

unity android player classes

unity android player classes version 5.4.1f1

https://1drv.ms/u/s!AvHuXY9pNXdik2V6-dJ1_YeW-O-v

* To add unity class jar to android build script

add jar.libs.dir=your_path_here/lib in ant.properties for SDK >=8
or your_path_here/libs which is the default for SDK 13. See the jar.libs.dir property in $SDK_DIR/tools/ant/build.xml.



C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes