Skip to content

Instantly share code, notes, and snippets.

@arturaz
Last active December 22, 2015 17:59
Show Gist options
  • Save arturaz/6510264 to your computer and use it in GitHub Desktop.
Save arturaz/6510264 to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
class TestCallback {
public static AndroidJavaObject apply<T1, T2>(Action<T1, T2> action) {
var cb = new AndroidJavaObject("TestCallback");
cb.Call("setRunnable", new AndroidJavaRunnable(() => {
var p1 = cb.Call<T1>("getParam1");
var p2 = cb.Call<T2>("getParam2");
action.Invoke(p1, p2);
}));
return cb;
}
}
public class TestCallback<T1, T2> {
private Runnable runnable;
private T1 param1;
private T2 param2;
public void setRunnable(Runnable runnable) {
this.runnable = runnable;
}
public void call(T1 param1, T2 param2) {
this.param1 = param1;
this.param2 = param2;
runnable.run();
}
public T1 getParam1() {
return param1;
}
public T2 getParam2() {
return param2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment