Skip to content

Instantly share code, notes, and snippets.

@oott123
Forked from xloger/Proxy.java
Created March 7, 2017 08:08
Show Gist options
  • Save oott123/413552e43d64babea91a0a3b1eb49d1b to your computer and use it in GitHub Desktop.
Save oott123/413552e43d64babea91a0a3b1eb49d1b to your computer and use it in GitHub Desktop.
package com.xloger.unitylib;
import android.util.Log;
import java.util.LinkedList;
import java.util.Queue;
public class Proxy {
public static class invokeData {
public String method;
public String data;
public static invokeData create(String method, String data) {
invokeData iD = new invokeData();
iD.method = method;
iD.data = data;
return iD;
}
}
private static CivHandler civHandler;
private static Queue<invokeData> queue = new LinkedList<>();
public static void SetHandler(CivHandler source) {
civHandler = source;
pollAllInvoke();
}
public static CivHandler getCivHandler() {
return civHandler;
}
public static void clearInvokeQueue() {
queue.clear();
}
public static void enqueueInvoke(invokeData invokeData) {
queue.offer(invokeData);
if (civHandler != null){
pollAllInvoke();
}
}
private static void pollAllInvoke() {
invokeData d;
while((d = queue.poll()) != null) {
Log.d("UnityInvoke", "执行了"+d.method);
civHandler.invoke(d.method, d.data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment