Skip to content

Instantly share code, notes, and snippets.

@oott123
Forked from xloger/Proxy.java
Created Mar 7, 2017
Embed
What would you like to do?
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