Last active
March 3, 2021 08:35
-
-
Save shiena/d73554393fbdfe90c055905c3b91e2b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Callback : AndroidJavaProxy, IDisposable | |
{ | |
private Action action; | |
private Disposable disposable; | |
public Callback(Action a) : base("any.java.CallbackInterface") | |
{ | |
action = a; | |
} | |
// implemented method | |
public void invoke() | |
{ | |
disposable = Observable.ReturnUnit() | |
.ObserveOnMainThread() | |
.Subscribe(_ => | |
{ | |
action?.Invoke(); | |
}); | |
} | |
public void Dispose() | |
{ | |
disposable?.Dispose(); | |
} | |
} | |
public class NativePlugin : MonoBehaviour | |
{ | |
private CompositeDisposable compositeDisposable = new CompositeDisposable(); | |
public void Call() | |
{ | |
var callback = new Callback(() => Debug.Log("call")); | |
javaObj.Call("call" callback); | |
compositeDisposable.Add(callback); | |
} | |
void OnDestroy() | |
{ | |
compositeDisposable.Clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment