Skip to content

Instantly share code, notes, and snippets.

@xloger
Created March 7, 2017 08:05
Show Gist options
  • Save xloger/fe2702f268f6c030a9c9f8570d6458c7 to your computer and use it in GitHub Desktop.
Save xloger/fe2702f268f6c030a9c9f8570d6458c7 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;
/**
* Created on 2017/3/7 11:10.
* Editor:xloger
* Email:[email protected]
*/
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;
}
public static CivHandler getCivHandler() {
return civHandler;
}
public static void clearInvokeQueue() {
queue.clear();
}
public static void enqueueInvoke(invokeData invokeData) {
if (civHandler==null){
}
queue.offer(invokeData);
}
private static void pollAllInvoke() {
invokeData d;
while((d = queue.poll()) != null) {
Log.d("UnityInvoke", "执行了"+d.method);
civHandler.invoke(d.method, d.data);
}
}
public static void Invoke(String method, String data) {
Log.d("UnityInvoke", method);
Log.d("UnityInvoke", data);
if (method.equals("Initialized")) {
pollAllInvoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment